diff options
author | Håvard Pettersen <havardpe@oath.com> | 2021-01-11 12:38:04 +0000 |
---|---|---|
committer | Håvard Pettersen <havardpe@oath.com> | 2021-01-11 12:38:04 +0000 |
commit | 9c38881ee2f8f61cb51d8f41de5feba36efa422b (patch) | |
tree | 8f726f040328582516736b3ef4d21bd35c194673 | |
parent | 32292572be63bf1725d34e4c071cd6690ecd43e8 (diff) |
fixup after PR comments
-rw-r--r-- | vespalib/src/tests/shared_string_repo/shared_string_repo_test.cpp | 6 | ||||
-rw-r--r-- | vespalib/src/vespa/vespalib/util/shared_string_repo.h | 4 | ||||
-rw-r--r-- | vespalib/src/vespa/vespalib/util/string_id.h | 2 |
3 files changed, 10 insertions, 2 deletions
diff --git a/vespalib/src/tests/shared_string_repo/shared_string_repo_test.cpp b/vespalib/src/tests/shared_string_repo/shared_string_repo_test.cpp index d560513e24d..aaf4a5e3e56 100644 --- a/vespalib/src/tests/shared_string_repo/shared_string_repo_test.cpp +++ b/vespalib/src/tests/shared_string_repo/shared_string_repo_test.cpp @@ -307,6 +307,12 @@ TEST("require that handle/string can be obtained from string_id") { EXPECT_EQUAL(Handle::string_from_id(b.id()), vespalib::string("str")); } +TEST("require that handle can be self-assigned") { + Handle a("foo"); + a = a; + EXPECT_EQUAL(a.as_string(), vespalib::string("foo")); +} + //----------------------------------------------------------------------------- TEST("require that basic multi-handle usage works") { diff --git a/vespalib/src/vespa/vespalib/util/shared_string_repo.h b/vespalib/src/vespa/vespalib/util/shared_string_repo.h index b2a222c82af..7e9f5d41f96 100644 --- a/vespalib/src/vespa/vespalib/util/shared_string_repo.h +++ b/vespalib/src/vespa/vespalib/util/shared_string_repo.h @@ -5,6 +5,7 @@ #include "string_id.h" #include "spin_lock.h" #include <vespa/vespalib/stllike/string.h> +#include <vespa/vespalib/util/stringfmt.h> #include <vespa/vespalib/stllike/identity.h> #include <vespa/vespalib/stllike/hashtable.hpp> #include <xxhash.h> @@ -219,8 +220,9 @@ public: Handle(vespalib::stringref str) : _id(_repo.resolve(str)) {} Handle(const Handle &rhs) : _id(_repo.copy(rhs._id)) {} Handle &operator=(const Handle &rhs) { + string_id copy = _repo.copy(rhs._id); _repo.reclaim(_id); - _id = _repo.copy(rhs._id); + _id = copy; return *this; } Handle(Handle &&rhs) noexcept : _id(rhs._id) { diff --git a/vespalib/src/vespa/vespalib/util/string_id.h b/vespalib/src/vespa/vespalib/util/string_id.h index 92711acdc67..3e608c9d339 100644 --- a/vespalib/src/vespa/vespalib/util/string_id.h +++ b/vespalib/src/vespa/vespalib/util/string_id.h @@ -16,7 +16,7 @@ class SharedStringRepo; * least one SharedStringRepo::Handle or SharedStringRepo::Handles * object. This is similar to how std::enable_shared_from_this works; * the string_id acts like a reference to a mapping from a string to a - * numberical value (without ownership) and Handle/Handles act like + * numerical value (without ownership) and Handle/Handles act like * shared pointers to the same mapping (with shared ownership). **/ class string_id { |