From 6ce3285c77f6fce9dd2729b6b53035cebd560833 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Fri, 30 Oct 2015 11:41:16 -0400 Subject: [PATCH] Lexer: Modified ::trim to make one less copy --- src/Lexer.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/Lexer.cpp b/src/Lexer.cpp index 2e0f32b80..bc68eb0e1 100644 --- a/src/Lexer.cpp +++ b/src/Lexer.cpp @@ -509,22 +509,27 @@ std::string Lexer::ucFirst (const std::string& input) //////////////////////////////////////////////////////////////////////////////// std::string Lexer::trimLeft (const std::string& in, const std::string& t /*= " "*/) { - std::string out = in; - return out.erase (0, in.find_first_not_of (t)); + std::string::size_type ws = in.find_first_not_of (t); + if (ws > 0) + { + std::string out {in}; + return out.erase (0, ws); + } + + return in; } //////////////////////////////////////////////////////////////////////////////// std::string Lexer::trimRight (const std::string& in, const std::string& t /*= " "*/) { - std::string out = in; - return out.erase (out.find_last_not_of (t) + 1); + std::string out {in}; + return out.erase (in.find_last_not_of (t) + 1); } //////////////////////////////////////////////////////////////////////////////// std::string Lexer::trim (const std::string& in, const std::string& t /*= " "*/) { - std::string out = in; - return trimLeft (trimRight (out, t), t); + return trimLeft (trimRight (in, t), t); } ////////////////////////////////////////////////////////////////////////////////