Pass ArgList by value

This improve bloat test results:
Old stripped size: 67680 (optimized)
New stripped size: 59488 (optimized)
This commit is contained in:
Victor Zverovich 2014-09-21 08:08:52 -07:00
parent 14f2577569
commit 1d4640415d
2 changed files with 22 additions and 23 deletions

View File

@ -319,7 +319,7 @@ inline Arg::StringValue<wchar_t> ignore_incompatible_str(
} // namespace
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;
Writer w;
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(
int error_code, StringRef format_str, const ArgList &args) {
int error_code, StringRef format_str, ArgList args) {
error_code_ = error_code;
Writer w;
internal::format_windows_error(w, error_code, format(format_str, args));
@ -1024,19 +1024,19 @@ void fmt::report_windows_error(
}
#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;
w.write(format_str, args);
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;
w.write(format_str, args);
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";
escape[3] = '0' + static_cast<char>(c);
std::fputs(escape, stdout);
@ -1044,7 +1044,7 @@ void fmt::print_colored(Color c, StringRef format, const ArgList &args) {
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;
printf(w, format, args);
return std::fwrite(w.data(), 1, w.size(), f);

View File

@ -934,14 +934,14 @@ class PrintfFormatter : private FormatterBase {
// A formatter.
template <typename Char>
class BasicFormatter : private internal::FormatterBase {
private:
private:
BasicWriter<Char> &writer_;
const Char *start_;
// Parses argument index and returns corresponding argument.
const internal::Arg &parse_arg_index(const Char *&s);
public:
public:
explicit BasicFormatter(BasicWriter<Char> &w) : writer_(w) {}
BasicWriter<Char> &writer() { return writer_; }
@ -1284,7 +1284,7 @@ for example a file opening error.
*/
class SystemError : public internal::RuntimeError {
private:
void init(int error_code, StringRef format_str, const ArgList &args);
void init(int error_code, StringRef format_str, ArgList args);
protected:
int error_code_;
@ -1490,7 +1490,7 @@ class BasicWriter {
See also `Format String Syntax`_.
\endrst
*/
void write(BasicStringRef<Char> format, const ArgList &args) {
void write(BasicStringRef<Char> format, ArgList args) {
BasicFormatter<Char>(*this).format(format, args);
}
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 {
private:
void init(int error_code, StringRef format_str, const ArgList &args);
void init(int error_code, StringRef format_str, ArgList args);
public:
/**
@ -1958,7 +1958,7 @@ enum Color { BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE };
Example:
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
@ -1969,13 +1969,13 @@ void print_colored(Color c, StringRef format, const ArgList &args);
std::string message = format("The answer is {}", 42);
\endrst
*/
inline std::string format(StringRef format_str, const ArgList &args) {
inline std::string format(StringRef format_str, ArgList args) {
Writer w;
w.write(format_str, args);
return w.str();
}
inline std::wstring format(WStringRef format_str, const ArgList &args) {
inline std::wstring format(WStringRef format_str, ArgList args) {
WWriter w;
w.write(format_str, args);
return w.str();
@ -1990,7 +1990,7 @@ inline std::wstring format(WStringRef format_str, const ArgList &args) {
print(stderr, "Don't {}!", "panic");
\endrst
*/
void print(std::FILE *f, StringRef format_str, const ArgList &args);
void print(std::FILE *f, StringRef format_str, ArgList args);
/**
\rst
@ -2001,7 +2001,7 @@ void print(std::FILE *f, StringRef format_str, const ArgList &args);
print("Elapsed time: {0:.2f} seconds", 1.23);
\endrst
*/
inline void print(StringRef format_str, const ArgList &args) {
inline void print(StringRef format_str, ArgList args) {
print(stdout, format_str, args);
}
@ -2014,11 +2014,10 @@ inline void print(StringRef format_str, const ArgList &args) {
print(cerr, "Don't {}!", "panic");
\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>
void printf(BasicWriter<Char> &w,
BasicStringRef<Char> format, const ArgList &args) {
void printf(BasicWriter<Char> &w, BasicStringRef<Char> format, ArgList 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);
\endrst
*/
inline std::string sprintf(StringRef format, const ArgList &args) {
inline std::string sprintf(StringRef format, ArgList args) {
Writer w;
printf(w, format, args);
return w.str();
@ -2046,7 +2045,7 @@ inline std::string sprintf(StringRef format, const ArgList &args) {
fmt::fprintf(stderr, "Don't %s!", "panic");
\endrst
*/
int fprintf(std::FILE *f, StringRef format, const ArgList &args);
int fprintf(std::FILE *f, StringRef format, ArgList args);
/**
\rst
@ -2057,7 +2056,7 @@ int fprintf(std::FILE *f, StringRef format, const ArgList &args);
fmt::printf("Elapsed time: %.2f seconds", 1.23);
\endrst
*/
inline int printf(StringRef format, const ArgList &args) {
inline int printf(StringRef format, ArgList args) {
return fprintf(stdout, format, args);
}
@ -2244,7 +2243,7 @@ inline void format_decimal(char *&buffer, T value) {
**Example**::
void print_error(const char *file, int line, const char *format,
const fmt::ArgList &args) {
fmt::ArgList args) {
fmt::print("{}: {}: ", file, line);
fmt::print(format, args);
}