aboutsummaryrefslogtreecommitdiffstats
path: root/storage
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2023-06-08 10:21:28 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2023-06-08 10:21:28 +0000
commit96c08c994dfaf4d605878e3e4f4ac982937b30bc (patch)
tree47619f028956ad5665f48226f198335e0ecb8488 /storage
parent2c7de524f66b86d694f09e673938cb8bf0828764 (diff)
Reorder members to reduce holes, and use std::make_unique.
Diffstat (limited to 'storage')
-rw-r--r--storage/src/tests/bucketdb/lockablemaptest.cpp5
-rw-r--r--storage/src/vespa/storage/bucketdb/abstract_bucket_map.h51
-rw-r--r--storage/src/vespa/storage/bucketdb/storagebucketinfo.h2
3 files changed, 30 insertions, 28 deletions
diff --git a/storage/src/tests/bucketdb/lockablemaptest.cpp b/storage/src/tests/bucketdb/lockablemaptest.cpp
index 3a16ee170fe..ec3567ad795 100644
--- a/storage/src/tests/bucketdb/lockablemaptest.cpp
+++ b/storage/src/tests/bucketdb/lockablemaptest.cpp
@@ -779,4 +779,9 @@ TYPED_TEST(LockableMapTest, entry_changes_not_visible_if_write_not_invoked_on_gu
EXPECT_EQ(*entry, A());
}
+TYPED_TEST(LockableMapTest, track_sizes) {
+ TypeParam map;
+ EXPECT_EQ(40ul, sizeof(typename TypeParam::WrappedEntry));
+}
+
} // storage
diff --git a/storage/src/vespa/storage/bucketdb/abstract_bucket_map.h b/storage/src/vespa/storage/bucketdb/abstract_bucket_map.h
index 983fdbfb93c..7b0ee95210d 100644
--- a/storage/src/vespa/storage/bucketdb/abstract_bucket_map.h
+++ b/storage/src/vespa/storage/bucketdb/abstract_bucket_map.h
@@ -28,47 +28,45 @@ public:
using size_type = size_t;
using BucketId = document::BucketId;
struct WrappedEntry;
-
+private:
// Responsible for releasing lock in map when out of scope.
class LockKeeper {
friend struct WrappedEntry;
AbstractBucketMap& _map;
- key_type _key;
- bool _locked;
-
- LockKeeper(AbstractBucketMap& map, key_type key) noexcept
- : _map(map), _key(key), _locked(true) {}
+ key_type _key;
+ bool _locked;
void unlock() { _map.unlock(_key); _locked = false; }
public:
+ LockKeeper(AbstractBucketMap& map, key_type key) noexcept
+ : _map(map), _key(key), _locked(true) {}
~LockKeeper() { if (_locked) unlock(); }
};
+public:
struct WrappedEntry {
WrappedEntry() noexcept
- : _exists(false),
- _preExisted(false),
- _lockKeeper(),
+ : _lockKeeper(),
_value(),
- _clientId(nullptr)
+ _clientId(nullptr),
+ _exists(false),
+ _preExisted(false)
{}
- WrappedEntry(AbstractBucketMap& map,
- const key_type& key, const mapped_type& val,
+ WrappedEntry(AbstractBucketMap& map, const key_type& key, const mapped_type& val,
const char* clientId, bool preExisted_)
- : _exists(true),
- _preExisted(preExisted_),
- _lockKeeper(new LockKeeper(map, key)),
+ : _lockKeeper(std::make_unique<LockKeeper>(map, key)),
_value(val),
- _clientId(clientId) {}
- WrappedEntry(AbstractBucketMap& map, const key_type& key,
- const char* clientId)
- : _exists(false),
- _preExisted(false),
- _lockKeeper(new LockKeeper(map, key)),
+ _clientId(clientId),
+ _exists(true),
+ _preExisted(preExisted_) {}
+ WrappedEntry(AbstractBucketMap& map, const key_type& key, const char* clientId)
+ : _lockKeeper(std::make_unique<LockKeeper>(map, key)),
_value(),
- _clientId(clientId) {}
+ _clientId(clientId),
+ _exists(false),
+ _preExisted(false) {}
// TODO noexcept on these:
- WrappedEntry(WrappedEntry&&) = default;
- WrappedEntry& operator=(WrappedEntry&&) = default;
+ WrappedEntry(WrappedEntry&&) noexcept = default;
+ WrappedEntry& operator=(WrappedEntry&&) noexcept = default;
~WrappedEntry();
mapped_type* operator->() { return &_value; }
@@ -91,12 +89,11 @@ public:
return BucketId(BucketId::keyToBucketId(getKey()));
}
protected:
- bool _exists;
- bool _preExisted;
std::unique_ptr<LockKeeper> _lockKeeper;
mapped_type _value;
const char* _clientId;
- friend class AbstractLockableMap;
+ bool _exists;
+ bool _preExisted;
};
struct LockId {
diff --git a/storage/src/vespa/storage/bucketdb/storagebucketinfo.h b/storage/src/vespa/storage/bucketdb/storagebucketinfo.h
index abca7e947af..fe9d197f0e9 100644
--- a/storage/src/vespa/storage/bucketdb/storagebucketinfo.h
+++ b/storage/src/vespa/storage/bucketdb/storagebucketinfo.h
@@ -9,7 +9,7 @@ namespace storage::bucketdb {
struct StorageBucketInfo {
api::BucketInfo info;
- StorageBucketInfo() : info() {}
+ StorageBucketInfo() noexcept : info() {}
static bool mayContain(const StorageBucketInfo&) { return true; }
void print(std::ostream&, bool verbose, const std::string& indent) const;
bool valid() const { return info.valid(); }