From 0d07846664594352564865cd0d28abe5ac4bf3ce Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Tue, 26 Sep 2023 12:30:03 +0000 Subject: Minor code health --- vespalib/src/tests/memorydatastore/memorydatastore.cpp | 2 +- vespalib/src/vespa/vespalib/data/memorydatastore.h | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) (limited to 'vespalib') 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 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(_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(); -- cgit v1.2.3