tstring: String::substr optimization when returning itself as a substring

Use copy ctor to return in a case whole string is being returned.

The intention was to optimize String::stripWhiteSpace for no-strip case
(without any leading or trailing white space removal).

copyFromUTF16 was used in any case previously and allocated duplicate
buffer for the same string - no implicit sharing.

Signed-off-by: Martin Flaska <martin.flaska@legrand.us>
This commit is contained in:
Martin Flaska 2016-11-25 15:32:26 +01:00
parent 6cfb11bb12
commit c9a0754e3b
No known key found for this signature in database
GPG Key ID: 87DC2B71F0B7371F

View File

@ -447,7 +447,10 @@ bool String::startsWith(const String &s) const
String String::substr(unsigned int position, unsigned int n) const
{
return String(d->data.substr(position, n));
if(position == 0 && n == size())
return *this;
else
return String(d->data.substr(position, n));
}
String &String::append(const String &s)