aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2023-06-29 16:44:07 +0200
committerGitHub <noreply@github.com>2023-06-29 16:44:07 +0200
commit107defdd8b78829c65076d5fcceeaa964659cbbd (patch)
treeaf93a147ff51a450a76ee6efcfa3584bd8fa08c2
parent826edc1dc433eb54b15ba414f16dff20f8d0586d (diff)
parentb7aa8ac1a051bb3c3ac3e40f8750fea3568f9788 (diff)
Merge pull request #27587 from vespa-engine/balder/add-noexcept
Add noexcept
-rw-r--r--vespalib/src/vespa/vespalib/data/memorydatastore.cpp16
-rw-r--r--vespalib/src/vespa/vespalib/data/memorydatastore.h64
-rw-r--r--vespalib/src/vespa/vespalib/test/memory_allocator_observer.cpp2
-rw-r--r--vespalib/src/vespa/vespalib/test/memory_allocator_observer.h2
-rw-r--r--vespalib/src/vespa/vespalib/util/alloc.cpp24
-rw-r--r--vespalib/src/vespa/vespalib/util/alloc.h17
-rw-r--r--vespalib/src/vespa/vespalib/util/memory_allocator.h8
-rw-r--r--vespalib/src/vespa/vespalib/util/mmap_file_allocator.cpp2
-rw-r--r--vespalib/src/vespa/vespalib/util/mmap_file_allocator.h2
9 files changed, 67 insertions, 70 deletions
diff --git a/vespalib/src/vespa/vespalib/data/memorydatastore.cpp b/vespalib/src/vespa/vespalib/data/memorydatastore.cpp
index f7fa627ea7e..354787690c2 100644
--- a/vespalib/src/vespa/vespalib/data/memorydatastore.cpp
+++ b/vespalib/src/vespa/vespalib/data/memorydatastore.cpp
@@ -7,10 +7,10 @@ namespace vespalib {
using alloc::Alloc;
using LockGuard = std::lock_guard<std::mutex>;
-MemoryDataStore::MemoryDataStore(Alloc && initialAlloc, std::mutex * lock) :
- _buffers(),
- _writePos(0),
- _lock(lock)
+MemoryDataStore::MemoryDataStore(Alloc && initialAlloc, std::mutex * lock)
+ : _buffers(),
+ _writePos(0),
+ _lock(lock)
{
_buffers.reserve(24);
_buffers.emplace_back(std::move(initialAlloc));
@@ -23,7 +23,7 @@ MemoryDataStore::push_back(const void * data, const size_t sz)
{
std::unique_ptr<LockGuard> guard;
if (_lock != nullptr) {
- guard.reset(new LockGuard(*_lock));
+ guard = std::make_unique<LockGuard>(*_lock);
}
const Alloc & b = _buffers.back();
if ((sz + _writePos) > b.size()) {
@@ -41,9 +41,9 @@ MemoryDataStore::push_back(const void * data, const size_t sz)
return ref;
}
-VariableSizeVector::VariableSizeVector(size_t initialCount, size_t initialBufferSize) :
- _vector(),
- _store(Alloc::alloc(initialBufferSize))
+VariableSizeVector::VariableSizeVector(size_t initialCount, size_t initialBufferSize)
+ : _vector(),
+ _store(Alloc::alloc(initialBufferSize))
{
_vector.reserve(initialCount);
}
diff --git a/vespalib/src/vespa/vespalib/data/memorydatastore.h b/vespalib/src/vespa/vespalib/data/memorydatastore.h
index 58057a34376..7022eb88051 100644
--- a/vespalib/src/vespa/vespalib/data/memorydatastore.h
+++ b/vespalib/src/vespa/vespalib/data/memorydatastore.h
@@ -18,9 +18,9 @@ class MemoryDataStore {
public:
class Reference {
public:
- Reference(void * data_) : _data(data_) { }
- void * data() { return _data; }
- const char * c_str() const { return static_cast<const char *>(_data); }
+ 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;
};
@@ -35,13 +35,13 @@ public:
*/
Reference push_back(const void * data, const size_t sz);
void swap(MemoryDataStore & rhs) { _buffers.swap(rhs._buffers); }
- void clear() {
+ void clear() noexcept {
_buffers.clear();
}
private:
std::vector<alloc::Alloc> _buffers;
- size_t _writePos;
- std::mutex * _lock;
+ size_t _writePos;
+ std::mutex * _lock;
};
class VariableSizeVector
@@ -49,50 +49,50 @@ class VariableSizeVector
public:
class Reference {
public:
- Reference(void * data_, size_t sz) : _data(data_), _sz(sz) { }
- void * data() { return _data; }
- const char * c_str() const { return static_cast<const char *>(_data); }
- size_t size() const { return _sz; }
+ Reference(void * data_, size_t sz) noexcept : _data(data_), _sz(sz) { }
+ void * data() noexcept { return _data; }
+ const char * c_str() const noexcept { return static_cast<const char *>(_data); }
+ size_t size() const noexcept { return _sz; }
private:
void * _data;
size_t _sz;
};
class iterator {
public:
- iterator(vespalib::Array<Reference> & v, size_t index) : _vector(&v), _index(index) {}
- Reference & operator * () const { return (*_vector)[_index]; }
- Reference * operator -> () const { return &(*_vector)[_index]; }
- iterator & operator ++ () {
+ iterator(vespalib::Array<Reference> & v, size_t index) noexcept : _vector(&v), _index(index) {}
+ Reference & operator * () const noexcept { return (*_vector)[_index]; }
+ Reference * operator -> () const noexcept { return &(*_vector)[_index]; }
+ iterator & operator ++ () noexcept {
_index++;
return *this;
}
- iterator operator ++ (int) {
+ iterator operator ++ (int) noexcept {
iterator prev = *this;
++(*this);
return prev;
}
- bool operator==(const iterator& rhs) const { return (_index == rhs._index); }
- bool operator!=(const iterator& rhs) const { return (_index != rhs._index); }
+ bool operator==(const iterator& rhs) const noexcept { return (_index == rhs._index); }
+ bool operator!=(const iterator& rhs) const noexcept { return (_index != rhs._index); }
private:
vespalib::Array<Reference> * _vector;
size_t _index;
};
class const_iterator {
public:
- const_iterator(const vespalib::Array<Reference> & v, size_t index) : _vector(&v), _index(index) {}
- const Reference & operator * () const { return (*_vector)[_index]; }
- const Reference * operator -> () const { return &(*_vector)[_index]; }
- const_iterator & operator ++ () {
+ const_iterator(const vespalib::Array<Reference> & v, size_t index) noexcept : _vector(&v), _index(index) {}
+ const Reference & operator * () const noexcept { return (*_vector)[_index]; }
+ const Reference * operator -> () const noexcept { return &(*_vector)[_index]; }
+ const_iterator & operator ++ () noexcept {
_index++;
return *this;
}
- const_iterator operator ++ (int) {
+ const_iterator operator ++ (int) noexcept {
const_iterator prev = *this;
++(*this);
return prev;
}
- bool operator==(const const_iterator& rhs) const { return (_index == rhs._index); }
- bool operator!=(const const_iterator& rhs) const { return (_index != rhs._index); }
+ bool operator==(const const_iterator& rhs) const noexcept { return (_index == rhs._index); }
+ bool operator!=(const const_iterator& rhs) const noexcept { return (_index != rhs._index); }
private:
const vespalib::Array<Reference> * _vector;
size_t _index;
@@ -101,15 +101,15 @@ public:
VariableSizeVector & operator = (const VariableSizeVector &) = delete;
VariableSizeVector(size_t initialCount, size_t initialBufferSize);
~VariableSizeVector();
- iterator begin() { return iterator(_vector, 0); }
- iterator end() { return iterator(_vector, size()); }
- const_iterator begin() const { return const_iterator(_vector, 0); }
- const_iterator end() const { return const_iterator(_vector, size()); }
+ iterator begin() noexcept { return iterator(_vector, 0); }
+ iterator end() noexcept { return iterator(_vector, size()); }
+ const_iterator begin() const noexcept { return const_iterator(_vector, 0); }
+ const_iterator end() const noexcept { return const_iterator(_vector, size()); }
Reference push_back(const void * data, const size_t sz);
- Reference operator [] (uint32_t index) const { return _vector[index]; }
- size_t size() const { return _vector.size(); }
- bool empty() const { return _vector.empty(); }
- void swap(VariableSizeVector & rhs) {
+ Reference operator [] (uint32_t index) const noexcept { return _vector[index]; }
+ size_t size() const noexcept { return _vector.size(); }
+ bool empty() const noexcept { return _vector.empty(); }
+ void swap(VariableSizeVector & rhs) noexcept {
_vector.swap(rhs._vector);
_store.swap(rhs._store);
}
diff --git a/vespalib/src/vespa/vespalib/test/memory_allocator_observer.cpp b/vespalib/src/vespa/vespalib/test/memory_allocator_observer.cpp
index 43817e63948..ff12cc745a1 100644
--- a/vespalib/src/vespa/vespalib/test/memory_allocator_observer.cpp
+++ b/vespalib/src/vespa/vespalib/test/memory_allocator_observer.cpp
@@ -29,7 +29,7 @@ MemoryAllocatorObserver::alloc(size_t sz) const
void
-MemoryAllocatorObserver::free(PtrAndSize alloc) const
+MemoryAllocatorObserver::free(PtrAndSize alloc) const noexcept
{
++_stats.free_cnt;
_backing_allocator->free(alloc);
diff --git a/vespalib/src/vespa/vespalib/test/memory_allocator_observer.h b/vespalib/src/vespa/vespalib/test/memory_allocator_observer.h
index 0ad07535f62..05afe30680c 100644
--- a/vespalib/src/vespa/vespalib/test/memory_allocator_observer.h
+++ b/vespalib/src/vespa/vespalib/test/memory_allocator_observer.h
@@ -37,7 +37,7 @@ public:
MemoryAllocatorObserver(Stats &stats);
~MemoryAllocatorObserver() override;
PtrAndSize alloc(size_t sz) const override;
- void free(PtrAndSize alloc) const override;
+ void free(PtrAndSize alloc) const noexcept override;
size_t resize_inplace(PtrAndSize current, size_t newSize) const override;
};
diff --git a/vespalib/src/vespa/vespalib/util/alloc.cpp b/vespalib/src/vespa/vespalib/util/alloc.cpp
index 4e04dd20d91..204d80340aa 100644
--- a/vespalib/src/vespa/vespalib/util/alloc.cpp
+++ b/vespalib/src/vespa/vespalib/util/alloc.cpp
@@ -125,10 +125,10 @@ namespace {
class HeapAllocator : public MemoryAllocator {
public:
PtrAndSize alloc(size_t sz) const override;
- void free(PtrAndSize alloc) const override;
+ void free(PtrAndSize alloc) const noexcept override;
size_t resize_inplace(PtrAndSize, size_t) const override { return 0; }
static PtrAndSize salloc(size_t sz);
- static void sfree(PtrAndSize alloc);
+ static void sfree(PtrAndSize alloc) noexcept;
static MemoryAllocator & getDefault();
};
@@ -146,11 +146,11 @@ private:
class MMapAllocator : public MemoryAllocator {
public:
PtrAndSize alloc(size_t sz) const override;
- void free(PtrAndSize alloc) const override;
+ void free(PtrAndSize alloc) const noexcept override;
size_t resize_inplace(PtrAndSize current, size_t newSize) const override;
static size_t sresize_inplace(PtrAndSize current, size_t newSize);
static PtrAndSize salloc(size_t sz, void * wantedAddress);
- static void sfree(PtrAndSize alloc);
+ static void sfree(PtrAndSize alloc) noexcept;
static MemoryAllocator & getDefault();
private:
static size_t extend_inplace(PtrAndSize current, size_t newSize);
@@ -161,8 +161,8 @@ class AutoAllocator : public MemoryAllocator {
public:
AutoAllocator(size_t mmapLimit, size_t alignment) : _mmapLimit(mmapLimit), _alignment(alignment) { }
PtrAndSize alloc(size_t sz) const override;
- void free(PtrAndSize alloc) const override;
- void free(void * ptr, size_t sz) const override;
+ void free(PtrAndSize alloc) const noexcept override;
+ void free(void * ptr, size_t sz) const noexcept override;
size_t resize_inplace(PtrAndSize current, size_t newSize) const override;
static MemoryAllocator & getDefault();
static MemoryAllocator & getAllocator(size_t mmapLimit, size_t alignment);
@@ -301,11 +301,11 @@ HeapAllocator::salloc(size_t sz) {
return PtrAndSize(ptr, sz);
}
-void HeapAllocator::free(PtrAndSize alloc) const {
+void HeapAllocator::free(PtrAndSize alloc) const noexcept {
sfree(alloc);
}
-void HeapAllocator::sfree(PtrAndSize alloc) {
+void HeapAllocator::sfree(PtrAndSize alloc) noexcept {
if (alloc.get()) { ::free(alloc.get()); }
}
@@ -419,11 +419,11 @@ MMapAllocator::shrink_inplace(PtrAndSize current, size_t newSize) {
return newSize;
}
-void MMapAllocator::free(PtrAndSize alloc) const {
+void MMapAllocator::free(PtrAndSize alloc) const noexcept {
sfree(alloc);
}
-void MMapAllocator::sfree(PtrAndSize alloc)
+void MMapAllocator::sfree(PtrAndSize alloc) noexcept
{
if (alloc.get() != nullptr) {
int madvise_retval = madvise(alloc.get(), alloc.size(), MADV_DONTNEED);
@@ -477,7 +477,7 @@ AutoAllocator::alloc(size_t sz) const {
}
void
-AutoAllocator::free(PtrAndSize alloc) const {
+AutoAllocator::free(PtrAndSize alloc) const noexcept {
if ( ! isMMapped(alloc.size())) {
return HeapAllocator::sfree(alloc);
} else {
@@ -486,7 +486,7 @@ AutoAllocator::free(PtrAndSize alloc) const {
}
void
-AutoAllocator::free(void * ptr, size_t sz) const {
+AutoAllocator::free(void * ptr, size_t sz) const noexcept {
if ( ! useMMap(sz)) {
return HeapAllocator::sfree(PtrAndSize(ptr, sz));
} else {
diff --git a/vespalib/src/vespa/vespalib/util/alloc.h b/vespalib/src/vespa/vespalib/util/alloc.h
index b78c10dd381..794d3fd6f6e 100644
--- a/vespalib/src/vespa/vespalib/util/alloc.h
+++ b/vespalib/src/vespa/vespalib/util/alloc.h
@@ -32,9 +32,9 @@ public:
bool resize_inplace(size_t newSize);
Alloc(const Alloc &) = delete;
Alloc & operator = (const Alloc &) = delete;
- Alloc(Alloc && rhs) noexcept :
- _alloc(rhs._alloc),
- _allocator(rhs._allocator)
+ Alloc(Alloc && rhs) noexcept
+ : _alloc(rhs._alloc),
+ _allocator(rhs._allocator)
{
rhs.clear();
}
@@ -50,17 +50,14 @@ public:
return *this;
}
Alloc() noexcept : _alloc(nullptr, 0), _allocator(nullptr) { }
- ~Alloc() {
- if (_alloc.get() != nullptr) {
- _allocator->free(_alloc);
- _alloc = PtrAndSize();
- }
+ ~Alloc() noexcept {
+ reset();
}
void swap(Alloc & rhs) noexcept {
std::swap(_alloc, rhs._alloc);
std::swap(_allocator, rhs._allocator);
}
- void reset() {
+ void reset() noexcept {
if (_alloc.get() != nullptr) {
_allocator->free(_alloc);
_alloc = PtrAndSize();
@@ -92,7 +89,7 @@ private:
: _alloc(nullptr, 0),
_allocator(allocator)
{ }
- void clear() {
+ void clear() noexcept {
_alloc = PtrAndSize();
_allocator = nullptr;
}
diff --git a/vespalib/src/vespa/vespalib/util/memory_allocator.h b/vespalib/src/vespa/vespalib/util/memory_allocator.h
index e9a494f3e6f..0bc66926b04 100644
--- a/vespalib/src/vespa/vespalib/util/memory_allocator.h
+++ b/vespalib/src/vespa/vespalib/util/memory_allocator.h
@@ -28,12 +28,12 @@ public:
static constexpr size_t HUGEPAGE_SIZE = 2_Mi;
MemoryAllocator(const MemoryAllocator &) = delete;
MemoryAllocator & operator = (const MemoryAllocator &) = delete;
- MemoryAllocator() = default;
+ MemoryAllocator() noexcept = default;
virtual ~MemoryAllocator() = default;
virtual PtrAndSize alloc(size_t sz) const = 0;
- virtual void free(PtrAndSize alloc) const = 0;
+ virtual void free(PtrAndSize alloc) const noexcept = 0;
// Allow for freeing memory there size is the size requested, and not the size allocated.
- virtual void free(void * ptr, size_t sz) const {
+ virtual void free(void * ptr, size_t sz) const noexcept {
free(PtrAndSize(ptr, sz));
}
/*
@@ -46,7 +46,7 @@ public:
* @return true if successful.
*/
virtual size_t resize_inplace(PtrAndSize current, size_t newSize) const = 0;
- static size_t roundUpToHugePages(size_t sz) {
+ static size_t roundUpToHugePages(size_t sz) noexcept {
return (sz+(HUGEPAGE_SIZE-1)) & ~(HUGEPAGE_SIZE-1);
}
static const MemoryAllocator * select_allocator();
diff --git a/vespalib/src/vespa/vespalib/util/mmap_file_allocator.cpp b/vespalib/src/vespa/vespalib/util/mmap_file_allocator.cpp
index 929b926c03e..9ed4806385d 100644
--- a/vespalib/src/vespa/vespalib/util/mmap_file_allocator.cpp
+++ b/vespalib/src/vespa/vespalib/util/mmap_file_allocator.cpp
@@ -70,7 +70,7 @@ MmapFileAllocator::alloc(size_t sz) const
}
void
-MmapFileAllocator::free(PtrAndSize alloc) const
+MmapFileAllocator::free(PtrAndSize alloc) const noexcept
{
if (alloc.size() == 0) {
assert(alloc.get() == nullptr);
diff --git a/vespalib/src/vespa/vespalib/util/mmap_file_allocator.h b/vespalib/src/vespa/vespalib/util/mmap_file_allocator.h
index 9d6eb096162..883c7e49848 100644
--- a/vespalib/src/vespa/vespalib/util/mmap_file_allocator.h
+++ b/vespalib/src/vespa/vespalib/util/mmap_file_allocator.h
@@ -40,7 +40,7 @@ public:
MmapFileAllocator(const vespalib::string& dir_name);
~MmapFileAllocator();
PtrAndSize alloc(size_t sz) const override;
- void free(PtrAndSize alloc) const override;
+ void free(PtrAndSize alloc) const noexcept override;
size_t resize_inplace(PtrAndSize, size_t) const override;
// For unit test