diff options
author | 2017-09-02 09:09:00 -0400 | |
---|---|---|
committer | 2017-09-02 23:09:00 +1000 | |
commit | d217e1fbec6dca0c959e7ae9b8e8cd6a86a9e3fb (patch) | |
tree | ba7ceb706c972016490250642aedad0ab25102f3 | |
parent | e0c2b67676ed577788f7cd8bc418cf668306fd69 (diff) |
Returning a reference from various corestr.cpp calls to avoid unnecessary string copies (#2613)
-rw-r--r-- | src/lib/util/corestr.cpp | 18 | ||||
-rw-r--r-- | src/lib/util/corestr.h | 8 |
2 files changed, 13 insertions, 13 deletions
diff --git a/src/lib/util/corestr.cpp b/src/lib/util/corestr.cpp index c8775f1cec0..b9e56c5cdc5 100644 --- a/src/lib/util/corestr.cpp +++ b/src/lib/util/corestr.cpp @@ -171,7 +171,7 @@ void strreplacechr(std::string& str, char ch, char newch) } } -static std::string internal_strtrimspace(std::string& str, bool right_only) +static std::string &internal_strtrimspace(std::string& str, bool right_only) { // identify the start std::string::iterator start = str.begin(); @@ -196,33 +196,33 @@ static std::string internal_strtrimspace(std::string& str, bool right_only) return str; } -std::string strtrimspace(std::string& str) +std::string &strtrimspace(std::string& str) { return internal_strtrimspace(str, false); } -std::string strtrimrightspace(std::string& str) +std::string &strtrimrightspace(std::string& str) { return internal_strtrimspace(str, true); } -std::string strmakeupper(std::string& str) +std::string &strmakeupper(std::string& str) { std::transform(str.begin(), str.end(), str.begin(), ::toupper); return str; } /** - * @fn std::string strmakelower(std::string& str) + * @fn std::string &strmakelower(std::string& str) * - * @brief Strmakelowers the given string. + * @brief Changes the given string to lower case. * - * @param [in,out] str The string. + * @param [in,out] str The string to make lower case * - * @return A std::string. + * @return A reference to the original std::string having been changed to lower case */ -std::string strmakelower(std::string& str) +std::string &strmakelower(std::string& str) { std::transform(str.begin(), str.end(), str.begin(), ::tolower); return str; diff --git a/src/lib/util/corestr.h b/src/lib/util/corestr.h index d31c1e5f8df..f4d8d7bed09 100644 --- a/src/lib/util/corestr.h +++ b/src/lib/util/corestr.h @@ -66,10 +66,10 @@ int strcatvprintf(std::string &str, const char *format, va_list args); void strdelchr(std::string& str, char chr); void strreplacechr(std::string& str, char ch, char newch); -std::string strtrimspace(std::string& str); -std::string strtrimrightspace(std::string& str); -std::string strmakeupper(std::string& str); -std::string strmakelower(std::string& str); +std::string &strtrimspace(std::string& str); +std::string &strtrimrightspace(std::string& str); +std::string &strmakeupper(std::string& str); +std::string &strmakelower(std::string& str); int strreplace(std::string &str, const std::string& search, const std::string& replace); #endif /* __CORESTR_H__ */ |