diff options
Diffstat (limited to 'src/strings')
-rw-r--r-- | src/strings/astring.py | 2 | ||||
-rw-r--r-- | src/strings/fwd.hpp | 2 | ||||
-rw-r--r-- | src/strings/rstring.cpp | 21 | ||||
-rw-r--r-- | src/strings/rstring.hpp | 2 | ||||
-rw-r--r-- | src/strings/rstring.py | 7 | ||||
-rw-r--r-- | src/strings/strings2_test.cpp | 9 | ||||
-rw-r--r-- | src/strings/vstring.cpp | 29 | ||||
-rw-r--r-- | src/strings/xstring.py | 12 | ||||
-rw-r--r-- | src/strings/zstring.py | 12 |
9 files changed, 44 insertions, 52 deletions
diff --git a/src/strings/astring.py b/src/strings/astring.py index f4cbf66..a3306d9 100644 --- a/src/strings/astring.py +++ b/src/strings/astring.py @@ -25,7 +25,7 @@ class AString(object): test_extra = ''' using tmwa::operator "" _s; - #include "../src/strings/zstring.hpp" + #include "../strings/zstring.hpp" ''' tests = [ diff --git a/src/strings/fwd.hpp b/src/strings/fwd.hpp index b1b8266..29762f9 100644 --- a/src/strings/fwd.hpp +++ b/src/strings/fwd.hpp @@ -23,6 +23,8 @@ #include <cstddef> #include <cstdint> +// strings/fwd.hpp is rank 1 + namespace tmwa { 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) diff --git a/src/strings/rstring.hpp b/src/strings/rstring.hpp index ad44beb..62f74fa 100644 --- a/src/strings/rstring.hpp +++ b/src/strings/rstring.hpp @@ -48,7 +48,7 @@ namespace strings const char *maybe_end; public: - RString(); + RString() noexcept; RString(LString s); RString(const RString&); RString(RString&&); diff --git a/src/strings/rstring.py b/src/strings/rstring.py index 61603d8..75fe2db 100644 --- a/src/strings/rstring.py +++ b/src/strings/rstring.py @@ -1,3 +1,6 @@ +# used by other pretty-printers +rstring_disable_children = False + class RString(object): __slots__ = ('_value') name = 'tmwa::strings::RString' @@ -21,6 +24,8 @@ class RString(object): return b.lazy_string(length=d) def children(self): + if rstring_disable_children: + return v = self._value if v['maybe_end']: pass @@ -31,7 +36,7 @@ class RString(object): test_extra = ''' using tmwa::operator "" _s; - #include "../src/strings/zstring.hpp" + #include "../strings/zstring.hpp" ''' tests = [ diff --git a/src/strings/strings2_test.cpp b/src/strings/strings2_test.cpp index 8ac8482..8b91306 100644 --- a/src/strings/strings2_test.cpp +++ b/src/strings/strings2_test.cpp @@ -228,4 +228,13 @@ TEST(StringTests, rlong) EXPECT_EQ(&*r.begin(), &*r3.begin()); EXPECT_EQ(&*a.begin(), &*a3.begin()); } + +TEST(StringTest, rself) +{ + // force dynamic allocation; valgrind will check for memory errors + RString r = XString("foo bar baz"_s); + RString r2 = r; + r = r; + r = r2; +} } // namespace tmwa diff --git a/src/strings/vstring.cpp b/src/strings/vstring.cpp deleted file mode 100644 index 1cb313a..0000000 --- a/src/strings/vstring.cpp +++ /dev/null @@ -1,29 +0,0 @@ -#include "vstring.hpp" -// strings/vstring.cpp - Functions for vstring.hpp -// -// Copyright © 2013 Ben Longbons <b.r.longbons@gmail.com> -// -// This file is part of The Mana World (Athena server) -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see <http://www.gnu.org/licenses/>. - -#include "../poison.hpp" - - -namespace tmwa -{ -namespace strings -{ -} // namespace strings -} // namespace tmwa diff --git a/src/strings/xstring.py b/src/strings/xstring.py index b2e33bb..ae764df 100644 --- a/src/strings/xstring.py +++ b/src/strings/xstring.py @@ -22,10 +22,10 @@ class XString(object): ''' tests = [ - ('tmwa::XString(""_s)', '"" = {base = 0x0}'), - ('tmwa::XString("Hello"_s)', '"Hello" = {base = 0x0}'), - ('tmwa::XString("' + str256[:-2] + '"_s)', '"' + str256[:-2] + '" = {base = 0x0}'), - ('tmwa::XString("' + str256[:-1] + '"_s)', '"' + str256[:-1] + '" = {base = 0x0}'), - ('tmwa::XString("' + str256 + '"_s)', '"' + str256 + '" = {base = 0x0}'), - ('tmwa::XString("' + str256 + 'x"_s)', '"' + str256 + 'x" = {base = 0x0}'), + ('tmwa::XString(""_s)', '"" = {base = nullptr}'), + ('tmwa::XString("Hello"_s)', '"Hello" = {base = nullptr}'), + ('tmwa::XString("' + str256[:-2] + '"_s)', '"' + str256[:-2] + '" = {base = nullptr}'), + ('tmwa::XString("' + str256[:-1] + '"_s)', '"' + str256[:-1] + '" = {base = nullptr}'), + ('tmwa::XString("' + str256 + '"_s)', '"' + str256 + '" = {base = nullptr}'), + ('tmwa::XString("' + str256 + 'x"_s)', '"' + str256 + 'x" = {base = nullptr}'), ] diff --git a/src/strings/zstring.py b/src/strings/zstring.py index f57252f..570c8f1 100644 --- a/src/strings/zstring.py +++ b/src/strings/zstring.py @@ -22,10 +22,10 @@ class ZString(object): ''' tests = [ - ('tmwa::ZString(""_s)', '"" = {base = 0x0}'), - ('tmwa::ZString("Hello"_s)', '"Hello" = {base = 0x0}'), - ('tmwa::ZString("' + str256[:-2] + '"_s)', '"' + str256[:-2] + '" = {base = 0x0}'), - ('tmwa::ZString("' + str256[:-1] + '"_s)', '"' + str256[:-1] + '" = {base = 0x0}'), - ('tmwa::ZString("' + str256 + '"_s)', '"' + str256 + '" = {base = 0x0}'), - ('tmwa::ZString("' + str256 + 'x"_s)', '"' + str256 + 'x" = {base = 0x0}'), + ('tmwa::ZString(""_s)', '"" = {base = nullptr}'), + ('tmwa::ZString("Hello"_s)', '"Hello" = {base = nullptr}'), + ('tmwa::ZString("' + str256[:-2] + '"_s)', '"' + str256[:-2] + '" = {base = nullptr}'), + ('tmwa::ZString("' + str256[:-1] + '"_s)', '"' + str256[:-1] + '" = {base = nullptr}'), + ('tmwa::ZString("' + str256 + '"_s)', '"' + str256 + '" = {base = nullptr}'), + ('tmwa::ZString("' + str256 + 'x"_s)', '"' + str256 + 'x" = {base = nullptr}'), ] |