Pass ArgList by value
This improve bloat test results: Old stripped size: 67680 (optimized) New stripped size: 59488 (optimized)
This commit is contained in:
parent
14f2577569
commit
1d4640415d
12
format.cc
12
format.cc
@ -319,7 +319,7 @@ inline Arg::StringValue<wchar_t> ignore_incompatible_str(
|
|||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
void fmt::SystemError::init(
|
void fmt::SystemError::init(
|
||||||
int error_code, StringRef format_str, const ArgList &args) {
|
int error_code, StringRef format_str, ArgList args) {
|
||||||
error_code_ = error_code;
|
error_code_ = error_code;
|
||||||
Writer w;
|
Writer w;
|
||||||
internal::format_system_error(w, error_code, format(format_str, args));
|
internal::format_system_error(w, error_code, format(format_str, args));
|
||||||
@ -428,7 +428,7 @@ int fmt::internal::UTF16ToUTF8::convert(fmt::WStringRef s) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void fmt::WindowsError::init(
|
void fmt::WindowsError::init(
|
||||||
int error_code, StringRef format_str, const ArgList &args) {
|
int error_code, StringRef format_str, ArgList args) {
|
||||||
error_code_ = error_code;
|
error_code_ = error_code;
|
||||||
Writer w;
|
Writer w;
|
||||||
internal::format_windows_error(w, error_code, format(format_str, args));
|
internal::format_windows_error(w, error_code, format(format_str, args));
|
||||||
@ -1024,19 +1024,19 @@ void fmt::report_windows_error(
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void fmt::print(std::FILE *f, StringRef format_str, const ArgList &args) {
|
void fmt::print(std::FILE *f, StringRef format_str, ArgList args) {
|
||||||
Writer w;
|
Writer w;
|
||||||
w.write(format_str, args);
|
w.write(format_str, args);
|
||||||
std::fwrite(w.data(), 1, w.size(), f);
|
std::fwrite(w.data(), 1, w.size(), f);
|
||||||
}
|
}
|
||||||
|
|
||||||
void fmt::print(std::ostream &os, StringRef format_str, const ArgList &args) {
|
void fmt::print(std::ostream &os, StringRef format_str, ArgList args) {
|
||||||
Writer w;
|
Writer w;
|
||||||
w.write(format_str, args);
|
w.write(format_str, args);
|
||||||
os.write(w.data(), w.size());
|
os.write(w.data(), w.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
void fmt::print_colored(Color c, StringRef format, const ArgList &args) {
|
void fmt::print_colored(Color c, StringRef format, ArgList args) {
|
||||||
char escape[] = "\x1b[30m";
|
char escape[] = "\x1b[30m";
|
||||||
escape[3] = '0' + static_cast<char>(c);
|
escape[3] = '0' + static_cast<char>(c);
|
||||||
std::fputs(escape, stdout);
|
std::fputs(escape, stdout);
|
||||||
@ -1044,7 +1044,7 @@ void fmt::print_colored(Color c, StringRef format, const ArgList &args) {
|
|||||||
std::fputs(RESET_COLOR, stdout);
|
std::fputs(RESET_COLOR, stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
int fmt::fprintf(std::FILE *f, StringRef format, const ArgList &args) {
|
int fmt::fprintf(std::FILE *f, StringRef format, ArgList args) {
|
||||||
Writer w;
|
Writer w;
|
||||||
printf(w, format, args);
|
printf(w, format, args);
|
||||||
return std::fwrite(w.data(), 1, w.size(), f);
|
return std::fwrite(w.data(), 1, w.size(), f);
|
||||||
|
33
format.h
33
format.h
@ -934,14 +934,14 @@ class PrintfFormatter : private FormatterBase {
|
|||||||
// A formatter.
|
// A formatter.
|
||||||
template <typename Char>
|
template <typename Char>
|
||||||
class BasicFormatter : private internal::FormatterBase {
|
class BasicFormatter : private internal::FormatterBase {
|
||||||
private:
|
private:
|
||||||
BasicWriter<Char> &writer_;
|
BasicWriter<Char> &writer_;
|
||||||
const Char *start_;
|
const Char *start_;
|
||||||
|
|
||||||
// Parses argument index and returns corresponding argument.
|
// Parses argument index and returns corresponding argument.
|
||||||
const internal::Arg &parse_arg_index(const Char *&s);
|
const internal::Arg &parse_arg_index(const Char *&s);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit BasicFormatter(BasicWriter<Char> &w) : writer_(w) {}
|
explicit BasicFormatter(BasicWriter<Char> &w) : writer_(w) {}
|
||||||
|
|
||||||
BasicWriter<Char> &writer() { return writer_; }
|
BasicWriter<Char> &writer() { return writer_; }
|
||||||
@ -1284,7 +1284,7 @@ for example a file opening error.
|
|||||||
*/
|
*/
|
||||||
class SystemError : public internal::RuntimeError {
|
class SystemError : public internal::RuntimeError {
|
||||||
private:
|
private:
|
||||||
void init(int error_code, StringRef format_str, const ArgList &args);
|
void init(int error_code, StringRef format_str, ArgList args);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
int error_code_;
|
int error_code_;
|
||||||
@ -1490,7 +1490,7 @@ class BasicWriter {
|
|||||||
See also `Format String Syntax`_.
|
See also `Format String Syntax`_.
|
||||||
\endrst
|
\endrst
|
||||||
*/
|
*/
|
||||||
void write(BasicStringRef<Char> format, const ArgList &args) {
|
void write(BasicStringRef<Char> format, ArgList args) {
|
||||||
BasicFormatter<Char>(*this).format(format, args);
|
BasicFormatter<Char>(*this).format(format, args);
|
||||||
}
|
}
|
||||||
FMT_VARIADIC_VOID(write, BasicStringRef<Char>)
|
FMT_VARIADIC_VOID(write, BasicStringRef<Char>)
|
||||||
@ -1926,7 +1926,7 @@ void report_system_error(int error_code, StringRef message) FMT_NOEXCEPT(true);
|
|||||||
*/
|
*/
|
||||||
class WindowsError : public SystemError {
|
class WindowsError : public SystemError {
|
||||||
private:
|
private:
|
||||||
void init(int error_code, StringRef format_str, const ArgList &args);
|
void init(int error_code, StringRef format_str, ArgList args);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
@ -1958,7 +1958,7 @@ enum Color { BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE };
|
|||||||
Example:
|
Example:
|
||||||
PrintColored(fmt::RED, "Elapsed time: {0:.2f} seconds") << 1.23;
|
PrintColored(fmt::RED, "Elapsed time: {0:.2f} seconds") << 1.23;
|
||||||
*/
|
*/
|
||||||
void print_colored(Color c, StringRef format, const ArgList &args);
|
void print_colored(Color c, StringRef format, ArgList args);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\rst
|
\rst
|
||||||
@ -1969,13 +1969,13 @@ void print_colored(Color c, StringRef format, const ArgList &args);
|
|||||||
std::string message = format("The answer is {}", 42);
|
std::string message = format("The answer is {}", 42);
|
||||||
\endrst
|
\endrst
|
||||||
*/
|
*/
|
||||||
inline std::string format(StringRef format_str, const ArgList &args) {
|
inline std::string format(StringRef format_str, ArgList args) {
|
||||||
Writer w;
|
Writer w;
|
||||||
w.write(format_str, args);
|
w.write(format_str, args);
|
||||||
return w.str();
|
return w.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::wstring format(WStringRef format_str, const ArgList &args) {
|
inline std::wstring format(WStringRef format_str, ArgList args) {
|
||||||
WWriter w;
|
WWriter w;
|
||||||
w.write(format_str, args);
|
w.write(format_str, args);
|
||||||
return w.str();
|
return w.str();
|
||||||
@ -1990,7 +1990,7 @@ inline std::wstring format(WStringRef format_str, const ArgList &args) {
|
|||||||
print(stderr, "Don't {}!", "panic");
|
print(stderr, "Don't {}!", "panic");
|
||||||
\endrst
|
\endrst
|
||||||
*/
|
*/
|
||||||
void print(std::FILE *f, StringRef format_str, const ArgList &args);
|
void print(std::FILE *f, StringRef format_str, ArgList args);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\rst
|
\rst
|
||||||
@ -2001,7 +2001,7 @@ void print(std::FILE *f, StringRef format_str, const ArgList &args);
|
|||||||
print("Elapsed time: {0:.2f} seconds", 1.23);
|
print("Elapsed time: {0:.2f} seconds", 1.23);
|
||||||
\endrst
|
\endrst
|
||||||
*/
|
*/
|
||||||
inline void print(StringRef format_str, const ArgList &args) {
|
inline void print(StringRef format_str, ArgList args) {
|
||||||
print(stdout, format_str, args);
|
print(stdout, format_str, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2014,11 +2014,10 @@ inline void print(StringRef format_str, const ArgList &args) {
|
|||||||
print(cerr, "Don't {}!", "panic");
|
print(cerr, "Don't {}!", "panic");
|
||||||
\endrst
|
\endrst
|
||||||
*/
|
*/
|
||||||
void print(std::ostream &os, StringRef format_str, const ArgList &args);
|
void print(std::ostream &os, StringRef format_str, ArgList args);
|
||||||
|
|
||||||
template <typename Char>
|
template <typename Char>
|
||||||
void printf(BasicWriter<Char> &w,
|
void printf(BasicWriter<Char> &w, BasicStringRef<Char> format, ArgList args) {
|
||||||
BasicStringRef<Char> format, const ArgList &args) {
|
|
||||||
internal::PrintfFormatter<Char>().format(w, format, args);
|
internal::PrintfFormatter<Char>().format(w, format, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2031,7 +2030,7 @@ void printf(BasicWriter<Char> &w,
|
|||||||
std::string message = fmt::sprintf("The answer is %d", 42);
|
std::string message = fmt::sprintf("The answer is %d", 42);
|
||||||
\endrst
|
\endrst
|
||||||
*/
|
*/
|
||||||
inline std::string sprintf(StringRef format, const ArgList &args) {
|
inline std::string sprintf(StringRef format, ArgList args) {
|
||||||
Writer w;
|
Writer w;
|
||||||
printf(w, format, args);
|
printf(w, format, args);
|
||||||
return w.str();
|
return w.str();
|
||||||
@ -2046,7 +2045,7 @@ inline std::string sprintf(StringRef format, const ArgList &args) {
|
|||||||
fmt::fprintf(stderr, "Don't %s!", "panic");
|
fmt::fprintf(stderr, "Don't %s!", "panic");
|
||||||
\endrst
|
\endrst
|
||||||
*/
|
*/
|
||||||
int fprintf(std::FILE *f, StringRef format, const ArgList &args);
|
int fprintf(std::FILE *f, StringRef format, ArgList args);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\rst
|
\rst
|
||||||
@ -2057,7 +2056,7 @@ int fprintf(std::FILE *f, StringRef format, const ArgList &args);
|
|||||||
fmt::printf("Elapsed time: %.2f seconds", 1.23);
|
fmt::printf("Elapsed time: %.2f seconds", 1.23);
|
||||||
\endrst
|
\endrst
|
||||||
*/
|
*/
|
||||||
inline int printf(StringRef format, const ArgList &args) {
|
inline int printf(StringRef format, ArgList args) {
|
||||||
return fprintf(stdout, format, args);
|
return fprintf(stdout, format, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2244,7 +2243,7 @@ inline void format_decimal(char *&buffer, T value) {
|
|||||||
**Example**::
|
**Example**::
|
||||||
|
|
||||||
void print_error(const char *file, int line, const char *format,
|
void print_error(const char *file, int line, const char *format,
|
||||||
const fmt::ArgList &args) {
|
fmt::ArgList args) {
|
||||||
fmt::print("{}: {}: ", file, line);
|
fmt::print("{}: {}: ", file, line);
|
||||||
fmt::print(format, args);
|
fmt::print(format, args);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user