diff options
author | Frédéric Bron <frederic.bron@m4x.org> | 2013-08-23 17:30:34 +0200 |
---|---|---|
committer | David Kastrup <dak@gnu.org> | 2013-09-10 03:15:34 +0200 |
commit | 00216e16c717470ae53dbbfd1d52850d1b102e29 (patch) | |
tree | 09a68e777977b2dd6e9c85a69fd103eb1d076474 /flower | |
parent | c0a691181c981f55ef28e5daa8410b41e37ef808 (diff) |
Issue 3531: replaced function argument 'string' by 'const string&' where it makes sense to avoid unnecessary copying of 'string' objects.
Measurements on x86_64 (i7-2760QM, 2.40GHz) Fedora 19 with g++ 4.8.1, with
configure --enable-optimising --disable-debugging; tests run 10 times, average
elapsed time compared (/usr/bin/time)
* Bach, Concerto in E major or violin and strings, BWV 1042 (Mutopia source),
38 pages:
$ lilypond score.ly -> master: 15.4s, with patch: -0.1%
* lilypond regression tests (1153 .ly files):
$ lilypond *.ly -> master: 276.6s, with patch: -2.5%
Diffstat (limited to 'flower')
-rw-r--r-- | flower/file-name.cc | 4 | ||||
-rw-r--r-- | flower/file-path.cc | 12 | ||||
-rw-r--r-- | flower/include/file-name.hh | 2 | ||||
-rw-r--r-- | flower/include/file-path.hh | 12 | ||||
-rw-r--r-- | flower/include/international.hh | 2 | ||||
-rw-r--r-- | flower/include/std-string.hh | 4 | ||||
-rw-r--r-- | flower/include/std-vector.hh | 2 | ||||
-rw-r--r-- | flower/include/string-convert.hh | 14 | ||||
-rw-r--r-- | flower/include/warn.hh | 20 | ||||
-rw-r--r-- | flower/international.cc | 2 | ||||
-rw-r--r-- | flower/std-string.cc | 6 | ||||
-rw-r--r-- | flower/string-convert.cc | 18 | ||||
-rw-r--r-- | flower/warn.cc | 22 |
13 files changed, 60 insertions, 60 deletions
diff --git a/flower/file-name.cc b/flower/file-name.cc index c24c0731e4..1746c2c28d 100644 --- a/flower/file-name.cc +++ b/flower/file-name.cc @@ -51,7 +51,7 @@ using namespace std; #ifdef __CYGWIN__ static string -dos_to_posix (string file_name) +dos_to_posix (const string &file_name) { char buf[PATH_MAX] = ""; char s[PATH_MAX] = {0}; @@ -78,7 +78,7 @@ slashify (string file_name) } string -dir_name (string const file_name) +dir_name (const string &file_name) { string s = file_name; s = slashify (s); diff --git a/flower/file-path.cc b/flower/file-path.cc index d0dd3a1f99..b19732d15e 100644 --- a/flower/file-path.cc +++ b/flower/file-path.cc @@ -47,13 +47,13 @@ File_path::directories () const #include <algorithm> void -File_path::parse_path (string p) +File_path::parse_path (const string &p) { concat (dirs_, string_split (p, PATHSEP)); } bool -is_file (string file_name) +is_file (const string &file_name) { #if !STAT_MACROS_BROKEN struct stat sbuf; @@ -106,7 +106,7 @@ directory, in this order. The file name if found, or empty string if not found. */ string -File_path::find (string name) const +File_path::find (const string &name) const { if (!name.length () || (name == "-")) return name; @@ -146,7 +146,7 @@ File_path::find (string name) const where EXT is from EXTENSIONS. */ string -File_path::find (string name, char const *extensions[]) +File_path::find (const string &name, char const *extensions[]) { if (name.empty () || name == "-") return name; @@ -195,13 +195,13 @@ File_path::to_string () const } void -File_path::append (string str) +File_path::append (const string &str) { dirs_.push_back (str); } void -File_path::prepend (string str) +File_path::prepend (const string &str) { dirs_.insert (dirs_.begin (), str); } diff --git a/flower/include/file-name.hh b/flower/include/file-name.hh index b30dd9cd5b..4822783fc6 100644 --- a/flower/include/file-name.hh +++ b/flower/include/file-name.hh @@ -23,7 +23,7 @@ #include "std-vector.hh" #include "std-string.hh" -std::string dir_name (std::string file_name); +std::string dir_name (const std::string &file_name); std::string get_working_directory (); class File_name diff --git a/flower/include/file-path.hh b/flower/include/file-path.hh index 29ca17f246..8c8049391d 100644 --- a/flower/include/file-path.hh +++ b/flower/include/file-path.hh @@ -38,16 +38,16 @@ class File_path public: vector<string> directories () const; - string find (string name) const; - string find (string name, char const *extensions[]); + string find (const string &name) const; + string find (const string &name, char const *extensions[]); string to_string () const; bool try_append (string str); - void append (string str); - void parse_path (string); - void prepend (string str); + void append (const string&); + void parse_path (const string&); + void prepend (const string&); }; -bool is_file (string file_name); +bool is_file (const string &file_name); bool is_dir (string file_name); #endif /* FILE_PATH */ diff --git a/flower/include/international.hh b/flower/include/international.hh index 6dd46c28e9..5797a293f7 100644 --- a/flower/include/international.hh +++ b/flower/include/international.hh @@ -43,7 +43,7 @@ string _ (char const *ch); */ string _f (char const *format, ...) __attribute__ ((format (printf, 1, 2))); -string _f (char const *format, string s, string s2 = "", string s3 = ""); +string _f (char const *format, const string &s, const string &s2 = "", const string &s3 = ""); /** va_list version of _f */ diff --git a/flower/include/std-string.hh b/flower/include/std-string.hh index 5b7d2af11d..6b6e8ef972 100644 --- a/flower/include/std-string.hh +++ b/flower/include/std-string.hh @@ -39,7 +39,7 @@ using namespace std; typedef size_t ssize; #define NPOS string::npos -string to_string (string s); +string to_string (const string&); string to_string (char c, int n = 1); string to_string (int i, char const *format = 0); string to_string (double f, char const *format = 0); @@ -53,7 +53,7 @@ __attribute__ ((format (printf, 1, 2))); string &replace_all (string *str, string const &find, string const &replace); string &replace_all (string *str, char find, char replace); -char *string_copy (string s); +char *string_copy (const string &s); int string_compare (string const &, string const &); diff --git a/flower/include/std-vector.hh b/flower/include/std-vector.hh index dd276df186..e7f29a8fcb 100644 --- a/flower/include/std-vector.hh +++ b/flower/include/std-vector.hh @@ -258,7 +258,7 @@ junk_pointers (vector<T> &v) } vector<string> string_split (string str, char c); -string string_join (vector<string> const &strs, string infix); +string string_join (vector<string> const &strs, const string &infix); #define iterof(i,s) typeof((s).begin()) i((s).begin()) diff --git a/flower/include/string-convert.hh b/flower/include/string-convert.hh index 396eee2f91..6b4fba023f 100644 --- a/flower/include/string-convert.hh +++ b/flower/include/string-convert.hh @@ -19,19 +19,19 @@ class String_convert static int hex2nibble (Byte byte); static Byte nibble2hex_byte (Byte byte); public: - static string pad_to (string s, size_t length); + static string pad_to (const string &s, size_t length); static string bool_string (bool b); static string bin2hex (Byte bin_char); - static string bin2hex (string bin_string); - static int bin2int (string bin_string); - static unsigned bin2unsigned (string bin_string); + static string bin2hex (const string &bin_string); + static int bin2int (const string &bin_string); + static unsigned bin2unsigned (const string &bin_string); static string char_string (char c, int n); - static int dec2int (string dec_string); - static double dec2double (string dec_string); + static int dec2int (const string &dec_string); + static double dec2double (const string &dec_string); static string double_string (double f, char const *fmt = 0); static string form_string (char const *format, ...) __attribute__ ((format (printf, 1, 2))); static string vform_string (char const *format, va_list args); - static string hex2bin (string str); + static string hex2bin (const string &str); static string int_string (int i, char const *fmt = 0); static string unsigned_string (unsigned); static string unsigned_long_string (unsigned long); diff --git a/flower/include/warn.hh b/flower/include/warn.hh index 25240113ca..333e95a94e 100644 --- a/flower/include/warn.hh +++ b/flower/include/warn.hh @@ -44,25 +44,25 @@ extern int loglevel; extern bool warning_as_error; /* output messages, in decreasing order of importance */ -void error (string s, string location = ""); // Fatal error, exits lilypond! -void programming_error (string s, string location = ""); -void non_fatal_error (string, string location = ""); -void warning (string s, string location = ""); -void basic_progress (string s, string location = ""); +void error (string s, const string &location = ""); // Fatal error, exits lilypond! +void programming_error (const string &s, const string &location = ""); +void non_fatal_error (const string&, const string &location = ""); +void warning (const string &s, const string &location = ""); +void basic_progress (const string &s, const string &location = ""); /* progress_indication does by default *NOT* start on a new line */ -void progress_indication (string s, bool newline = false, string location = ""); -void message (string s, bool newline = true, string location = ""); -void debug_output (string s, bool newline = true, string location = ""); +void progress_indication (const string &s, bool newline = false, const string &location = ""); +void message (const string &s, bool newline = true, const string &location = ""); +void debug_output (const string &s, bool newline = true, const string &location = ""); /* Helper functions that always print out the message. Callers should ensure that the loglevel is obeyed */ -void print_message (int level, string location, string s, bool newline = true); +void print_message (int level, const string &location, string s, bool newline = true); bool is_loglevel (int level); void set_loglevel (int level); void set_loglevel (string level); -void expect_warning (string msg); +void expect_warning (const string &msg); void check_expected_warnings (); #endif /* WARN_HH */ diff --git a/flower/international.cc b/flower/international.cc index cbdcf58d6e..2e6a09df9f 100644 --- a/flower/international.cc +++ b/flower/international.cc @@ -55,7 +55,7 @@ v_f (char const *format, va_list args) } string -_f (char const *format, string s, string s2, string s3) +_f (char const *format, const string &s, const string &s2, const string &s3) { return String_convert::form_string (gettext (format), s.c_str (), s2.c_str (), s3.c_str ()); diff --git a/flower/std-string.cc b/flower/std-string.cc index d2c2d624d2..7dc9d47311 100644 --- a/flower/std-string.cc +++ b/flower/std-string.cc @@ -21,7 +21,7 @@ #include "string-convert.hh" string -to_string (string s) +to_string (const string &s) { return s; } @@ -106,7 +106,7 @@ replace_all (string *str, char find, char replace) } char * -string_copy (string s) +string_copy (const string &s) { ssize len = s.length (); char *dest = new char[len + 1]; @@ -144,7 +144,7 @@ string_split (string str, char c) } string -string_join (vector<string> const &strs, string infix) +string_join (vector<string> const &strs, const string &infix) { string result; for (vsize i = 0; i < strs.size (); i++) diff --git a/flower/string-convert.cc b/flower/string-convert.cc index 68e6a0c0b8..eebcd92708 100644 --- a/flower/string-convert.cc +++ b/flower/string-convert.cc @@ -43,7 +43,7 @@ String_convert::bin2hex (Byte bin_char) } string -String_convert::bin2hex (string bin_string) +String_convert::bin2hex (const string &bin_string) { string str; Byte const *byte = (Byte const *)bin_string.data (); @@ -56,13 +56,13 @@ String_convert::bin2hex (string bin_string) } int -String_convert::bin2int (string bin_string) +String_convert::bin2int (const string &bin_string) { return bin2unsigned (bin_string); } unsigned -String_convert::bin2unsigned (string bin_string) +String_convert::bin2unsigned (const string &bin_string) { assert (bin_string.length () <= (int)sizeof (unsigned)); @@ -76,7 +76,7 @@ String_convert::bin2unsigned (string bin_string) } int -String_convert::dec2int (string dec_string) +String_convert::dec2int (const string &dec_string) { if (!dec_string.length ()) return 0; @@ -100,7 +100,7 @@ String_convert::i64_string (I64 i64, char const *fmt) } // breendet imp from string double -String_convert::dec2double (string dec_string) +String_convert::dec2double (const string &dec_string) { if (!dec_string.length ()) return 0; @@ -134,7 +134,7 @@ String_convert::hex2bin (string hex_string, string &bin_string_r) } string -String_convert::hex2bin (string hex_string) +String_convert::hex2bin (const string &hex_string) { string str; @@ -352,7 +352,7 @@ String_convert::unsigned_long_string (unsigned long ul) } string -String_convert::pad_to (string s, size_t n) +String_convert::pad_to (const string &s, size_t n) { return s + string (max (int (n - s.length ()), 0), ' '); } @@ -360,13 +360,13 @@ String_convert::pad_to (string s, size_t n) string String_convert::to_upper (string s) { - return strnupr ((char *)s.c_str (), s.length ()); + return strnupr (const_cast<char*>(s.c_str ()), s.length ()); } string String_convert::to_lower (string s) { - return strnlwr ((char *)s.c_str (), s.length ()); + return strnlwr (const_cast<char*>(s.c_str ()), s.length ()); } string diff --git a/flower/warn.cc b/flower/warn.cc index f3f6e1c743..52e2a42508 100644 --- a/flower/warn.cc +++ b/flower/warn.cc @@ -99,7 +99,7 @@ set_loglevel (string level) * expected warnings again. */ vector<string> expected_warnings; -void expect_warning (string msg) +void expect_warning (const string &msg) { expected_warnings.push_back (msg); } @@ -119,7 +119,7 @@ void check_expected_warnings () expected_warnings.clear (); } -bool is_expected (string s) +bool is_expected (const string &s) { bool expected = false; for (vsize i = 0; i < expected_warnings.size (); i++) @@ -151,7 +151,7 @@ static bool message_newline = true; if newline is true, start the message on a new line. */ void -print_message (int level, string location, string s, bool newline) +print_message (int level, const string &location, string s, bool newline) { /* Only print the message if the current loglevel allows it: */ if (!is_loglevel (level)) @@ -178,7 +178,7 @@ print_message (int level, string location, string s, bool newline) /* Display a fatal error message. Also exits lilypond. */ void -error (string s, string location) +error (string s, const string &location) { print_message (LOG_ERROR, location, _f ("fatal error: %s", s) + "\n"); exit (1); @@ -186,7 +186,7 @@ error (string s, string location) /* Display a severe programming error message, but don't exit. */ void -programming_error (string s, string location) +programming_error (const string &s, const string &location) { if (is_expected (s)) print_message (LOG_DEBUG, location, _f ("suppressed programming error: %s", s) + "\n"); @@ -201,7 +201,7 @@ programming_error (string s, string location) /* Display a non-fatal error message, don't exit. */ void -non_fatal_error (string s, string location) +non_fatal_error (const string &s, const string &location) { if (is_expected (s)) print_message (LOG_DEBUG, location, _f ("suppressed error: %s", s) + "\n"); @@ -213,7 +213,7 @@ non_fatal_error (string s, string location) /* Display a warning message. */ void -warning (string s, string location) +warning (const string &s, const string &location) { if (is_expected (s)) print_message (LOG_DEBUG, location, _f ("suppressed warning: %s", s) + "\n"); @@ -225,21 +225,21 @@ warning (string s, string location) /* Display a success message. */ void -basic_progress (string s, string location) +basic_progress (const string &s, const string &location) { print_message (LOG_BASIC, location, s + "\n", true); } /* Display information about the progress. */ void -progress_indication (string s, bool newline, string location) +progress_indication (const string &s, bool newline, const string &location) { print_message (LOG_PROGRESS, location, s, newline); } /* Display a single info message. */ void -message (string s, bool newline, string location) +message (const string &s, bool newline, const string &location) { // Use the progress loglevel for all normal messages (including progress msg) print_message (LOG_INFO, location, s, newline); @@ -247,7 +247,7 @@ message (string s, bool newline, string location) /* Display a debug information, not necessarily on a new line. */ void -debug_output (string s, bool newline, string location) +debug_output (const string &s, bool newline, const string &location) { print_message (LOG_DEBUG, location, s, newline); } |