diff options
Diffstat (limited to 'src/strings/rstring.cpp')
-rw-r--r-- | src/strings/rstring.cpp | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/src/strings/rstring.cpp b/src/strings/rstring.cpp index e74d1d5..aaf0ba0 100644 --- a/src/strings/rstring.cpp +++ b/src/strings/rstring.cpp @@ -36,7 +36,7 @@ namespace tmwa { namespace strings { - RString::RString() + RString::RString() noexcept : u{.begin= ""}, maybe_end(u.begin) { } @@ -58,13 +58,18 @@ namespace strings } RString& RString::operator = (const RString& r) { - // order important for self-assign - if (!r.maybe_end) - r.u.owned->count++; - if (!maybe_end && !u.owned->count--) - ::operator delete(u.owned); - u = r.u; - maybe_end = r.maybe_end; + // this turns out to be a win + // certain callers end up needing to do self-assignment a *lot*, + // leading to pointless ++,--s + if (this->u.owned != r.u.owned) + { + if (!r.maybe_end) + r.u.owned->count++; + if (!maybe_end && !u.owned->count--) + ::operator delete(u.owned); + u = r.u; + maybe_end = r.maybe_end; + } return *this; } RString& RString::operator = (RString&& r) |