summaryrefslogtreecommitdiffstats
path: root/vespalib
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2023-09-26 12:30:03 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2023-09-26 12:30:03 +0000
commit0d07846664594352564865cd0d28abe5ac4bf3ce (patch)
treefc87ee4eb1b85eb0c5aa16ec83a401b5842f3953 /vespalib
parentfcd0868ab10343bef4d3925f21c59cb8f577d51c (diff)
Minor code health
Diffstat (limited to 'vespalib')
-rw-r--r--vespalib/src/tests/memorydatastore/memorydatastore.cpp2
-rw-r--r--vespalib/src/vespa/vespalib/data/memorydatastore.h7
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();