aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2024-04-26 07:09:29 +0200
committerGitHub <noreply@github.com>2024-04-26 07:09:29 +0200
commit8e0492ef4ff8416d12271768c58be79cf7a53914 (patch)
tree3e4a3d59302f09ccaea51d7bb800408d48eb40ba
parentbec1ec03ae0dbb1a27c408d8484e9a959753b510 (diff)
parent9754bda577ddda8454743e20e4842263875ec6a7 (diff)
Merge pull request #31054 from vespa-engine/balder/add-noexcept
Add noexcept and remove outdated comment
-rw-r--r--searchlib/src/vespa/searchlib/tensor/empty_subspace.cpp1
-rw-r--r--searchlib/src/vespa/searchlib/tensor/hnsw_graph.cpp3
-rw-r--r--vespalib/src/vespa/vespalib/util/rcuvector.h35
-rw-r--r--vespalib/src/vespa/vespalib/util/rcuvector.hpp12
4 files changed, 24 insertions, 27 deletions
diff --git a/searchlib/src/vespa/searchlib/tensor/empty_subspace.cpp b/searchlib/src/vespa/searchlib/tensor/empty_subspace.cpp
index 131dcf05c60..b0fa1a682db 100644
--- a/searchlib/src/vespa/searchlib/tensor/empty_subspace.cpp
+++ b/searchlib/src/vespa/searchlib/tensor/empty_subspace.cpp
@@ -12,7 +12,6 @@ EmptySubspace::EmptySubspace(const SubspaceType& type)
_cells()
{
_empty_space.resize(type.mem_size());
- // Set size to zero to signal empty/invalid subspace
_cells = TypedCells::create_non_existing_attribute_value(_empty_space.data(), type.cell_type(), type.size());
}
diff --git a/searchlib/src/vespa/searchlib/tensor/hnsw_graph.cpp b/searchlib/src/vespa/searchlib/tensor/hnsw_graph.cpp
index 16e2af0ad97..4d57b87d257 100644
--- a/searchlib/src/vespa/searchlib/tensor/hnsw_graph.cpp
+++ b/searchlib/src/vespa/searchlib/tensor/hnsw_graph.cpp
@@ -102,10 +102,9 @@ HnswGraph<type>::histograms() const
for (size_t i = 0; i < num_nodes; ++i) {
auto levels_ref = acquire_levels_ref(i);
if (levels_ref.valid()) {
- uint32_t levels = 0;
uint32_t l0links = 0;
auto level_array = levels_store.get(levels_ref);
- levels = level_array.size();
+ uint32_t levels = level_array.size();
if (levels > 0) {
auto links_ref = level_array[0].load_acquire();
auto link_array = links_store.get(links_ref);
diff --git a/vespalib/src/vespa/vespalib/util/rcuvector.h b/vespalib/src/vespa/vespalib/util/rcuvector.h
index 787fb2d00c6..7dfe57d4dd0 100644
--- a/vespalib/src/vespa/vespalib/util/rcuvector.h
+++ b/vespalib/src/vespa/vespalib/util/rcuvector.h
@@ -17,8 +17,7 @@ class RcuVectorHeld : public GenerationHeldBase
T _data;
public:
- RcuVectorHeld(size_t size, T&& data);
-
+ RcuVectorHeld(size_t size, T&& data) noexcept;
~RcuVectorHeld() override;
};
@@ -49,11 +48,11 @@ private:
GrowStrategy _growStrategy;
GenerationHolderType &_genHolder;
- size_t calcNewSize(size_t baseSize) const;
- size_t calcNewSize() const;
+ size_t calcNewSize(size_t baseSize) const noexcept;
+ size_t calcNewSize() const noexcept;
void expand(size_t newCapacity);
void expandAndInsert(const T & v);
- void update_vector_start();
+ void update_vector_start() noexcept;
protected:
virtual void onReallocation();
@@ -80,12 +79,12 @@ public:
* isFull() should be called from writer only.
* Const type qualifier removed to prevent call from readers.
**/
- bool isFull() { return _data.size() == _data.capacity(); }
+ bool isFull() noexcept { return _data.size() == _data.capacity(); }
/**
* Return the combined memory usage for this instance.
**/
- virtual MemoryUsage getMemoryUsage() const;
+ virtual MemoryUsage getMemoryUsage() const noexcept;
// vector interface
// no swap method, use reset() to forget old capacity and holds
@@ -106,28 +105,28 @@ public:
}
}
- bool empty() const { return _data.empty(); }
+ bool empty() const noexcept { return _data.empty(); }
/*
* size() should be called from writer only.
* Const type qualifier removed to prevent call from readers.
*/
- size_t size() { return _data.size(); }
+ size_t size() noexcept { return _data.size(); }
/*
* get_size() should be called from writer only or with proper lock held.
* Used in predicate attribute by reader (causing data race).
*/
- size_t get_size() const { return _data.size(); }
+ size_t get_size() const noexcept{ return _data.size(); }
/*
* capacity() should be called from writer only.
* Const type qualifier removed to prevent call from readers.
*/
- size_t capacity() { return _data.capacity(); }
+ size_t capacity() noexcept { return _data.capacity(); }
void clear() { _data.clear(); }
/*
* operator[]() should be called from writer only.
* Overload with const type qualifier removed to prevent call from readers.
*/
- T & operator[](size_t i) { return _data[i]; }
+ T & operator[](size_t i) noexcept { return _data[i]; }
/*
* Readers holding a generation guard can call acquire_elem_ref(i)
* to get a const reference to element i. Array bound must be handled
@@ -153,7 +152,7 @@ public:
};
template <typename T>
-class RcuVector : public RcuVectorBase<T>
+class RcuVector final : public RcuVectorBase<T>
{
private:
using generation_t = typename RcuVectorBase<T>::generation_t;
@@ -173,18 +172,18 @@ public:
* New capacity is calculated based on old capacity and grow parameters:
* nc = oc + (oc * growPercent / 100) + growDelta.
**/
- RcuVector(GrowStrategy growStrategy);
- ~RcuVector();
+ explicit RcuVector(GrowStrategy growStrategy);
+ ~RcuVector() override;
- generation_t getGeneration() const { return _generation; }
- void setGeneration(generation_t generation) { _generation = generation; }
+ generation_t getGeneration() const noexcept { return _generation; }
+ void setGeneration(generation_t generation) noexcept { _generation = generation; }
/**
* Remove all old data vectors where generation < firstUsed.
**/
void reclaim_memory(generation_t oldest_used_gen);
- MemoryUsage getMemoryUsage() const override;
+ MemoryUsage getMemoryUsage() const noexcept override;
};
}
diff --git a/vespalib/src/vespa/vespalib/util/rcuvector.hpp b/vespalib/src/vespa/vespalib/util/rcuvector.hpp
index 384c48d2223..07df307e32c 100644
--- a/vespalib/src/vespa/vespalib/util/rcuvector.hpp
+++ b/vespalib/src/vespa/vespalib/util/rcuvector.hpp
@@ -9,7 +9,7 @@
namespace vespalib {
template <typename T>
-RcuVectorHeld<T>::RcuVectorHeld(size_t size, T&& data)
+RcuVectorHeld<T>::RcuVectorHeld(size_t size, T&& data) noexcept
: GenerationHeldBase(size),
_data(std::move(data))
{ }
@@ -18,12 +18,12 @@ template <typename T>
RcuVectorHeld<T>::~RcuVectorHeld() = default;
template <typename T>
-size_t RcuVectorBase<T>::calcNewSize(size_t baseSize) const {
+size_t RcuVectorBase<T>::calcNewSize(size_t baseSize) const noexcept {
return _growStrategy.calc_new_size(baseSize);
}
template <typename T>
-size_t RcuVectorBase<T>::calcNewSize() const {
+size_t RcuVectorBase<T>::calcNewSize() const noexcept {
return calcNewSize(_data.capacity());
}
@@ -135,7 +135,7 @@ RcuVectorBase<T>::RcuVectorBase(GrowStrategy growStrategy,
template <typename T>
MemoryUsage
-RcuVectorBase<T>::getMemoryUsage() const
+RcuVectorBase<T>::getMemoryUsage() const noexcept
{
MemoryUsage retval;
retval.incAllocatedBytes(_data.capacity() * sizeof(T));
@@ -145,7 +145,7 @@ RcuVectorBase<T>::getMemoryUsage() const
template <typename T>
void
-RcuVectorBase<T>::update_vector_start()
+RcuVectorBase<T>::update_vector_start() noexcept
{
_vector_start.store(_data.data(), std::memory_order_release);
}
@@ -193,7 +193,7 @@ RcuVector<T>::reclaim_memory(generation_t oldest_used_gen)
template <typename T>
MemoryUsage
-RcuVector<T>::getMemoryUsage() const
+RcuVector<T>::getMemoryUsage() const noexcept
{
MemoryUsage retval(RcuVectorBase<T>::getMemoryUsage());
retval.mergeGenerationHeldBytes(_genHolderStore.get_held_bytes());