diff options
author | Geir Storli <geirst@yahooinc.com> | 2023-09-26 21:17:00 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-26 21:17:00 +0200 |
commit | dc9ad363d6ea4ac017c55b994e16c65be2777f30 (patch) | |
tree | 210e69fdfed045d6d1f36e1a80b6b958aeb5e77c /vespalib | |
parent | 0362fba8f6ee2cdbd6dc26ebe746894135cd98bf (diff) | |
parent | 0d07846664594352564865cd0d28abe5ac4bf3ce (diff) |
Merge pull request #28674 from vespa-engine/balder/minor-code-health
Minor code health
Diffstat (limited to 'vespalib')
-rw-r--r-- | vespalib/src/tests/memorydatastore/memorydatastore.cpp | 2 | ||||
-rw-r--r-- | vespalib/src/vespa/vespalib/data/memorydatastore.h | 7 |
2 files changed, 5 insertions, 4 deletions
diff --git a/vespalib/src/tests/memorydatastore/memorydatastore.cpp b/vespalib/src/tests/memorydatastore/memorydatastore.cpp index 649bd45a541..7eab32601de 100644 --- a/vespalib/src/tests/memorydatastore/memorydatastore.cpp +++ b/vespalib/src/tests/memorydatastore/memorydatastore.cpp @@ -8,7 +8,7 @@ using namespace vespalib; TEST("testMemoryDataStore") { - MemoryDataStore s(alloc::Alloc::alloc(256)); + MemoryDataStore s(alloc::Alloc::alloc(256), nullptr); std::vector<MemoryDataStore::Reference> v; v.push_back(s.push_back("mumbo", 5)); for (size_t i(0); i < 50; i++) { diff --git a/vespalib/src/vespa/vespalib/data/memorydatastore.h b/vespalib/src/vespa/vespalib/data/memorydatastore.h index a0280454a91..6691211cdd0 100644 --- a/vespalib/src/vespa/vespalib/data/memorydatastore.h +++ b/vespalib/src/vespa/vespalib/data/memorydatastore.h @@ -13,18 +13,19 @@ namespace vespalib { * It has the important property that once an object has been allocated it does not move in memory. * It will start of by allocating one backing buffer and items stored will be appended here. * When limit is exceeded a new buffer is allocated with twice the size of the previous and so it goes. + * You can also provide an optional lock to make it thread safe. **/ class MemoryDataStore { public: class Reference { public: - Reference(void * data_) noexcept : _data(data_) { } + explicit Reference(void * data_) noexcept : _data(data_) { } void * data() noexcept { return _data; } const char * c_str() const noexcept { return static_cast<const char *>(_data); } private: void * _data; }; - MemoryDataStore(alloc::Alloc && initialAlloc=alloc::Alloc::alloc(256), std::mutex * lock=nullptr); + MemoryDataStore(alloc::Alloc && initialAlloc, std::mutex * lock); MemoryDataStore(const MemoryDataStore &) = delete; MemoryDataStore & operator = (const MemoryDataStore &) = delete; ~MemoryDataStore(); @@ -33,7 +34,7 @@ public: * for the lifetime of this object. * @return A pointer/reference to the freshly stored object. */ - Reference push_back(const void * data, const size_t sz); + Reference push_back(const void * data, size_t sz); void swap(MemoryDataStore & rhs) { _buffers.swap(rhs._buffers); } void clear() noexcept { _buffers.clear(); |