From bd8012c7826efe15bfad0ed395bd76d678e76605 Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Wed, 13 Dec 2023 11:32:29 +0000 Subject: - Add some more extern templates to enable code to build with -O0. - Add some more noexcept. --- .../unique_store_dictionary_test.cpp | 10 ++++----- .../src/vespa/vespalib/btree/btreeiterator.cpp | 3 +++ vespalib/src/vespa/vespalib/btree/btreeiterator.h | 14 +++++++++--- .../src/vespa/vespalib/btree/btreeiterator.hpp | 12 ---------- vespalib/src/vespa/vespalib/btree/btreenode.cpp | 2 ++ vespalib/src/vespa/vespalib/btree/btreenode.h | 2 ++ .../vespa/vespalib/btree/btreenodeallocator.cpp | 14 +++++------- .../src/vespa/vespalib/btree/btreenodeallocator.h | 14 +++++------- .../src/vespa/vespalib/btree/btreerootbase.cpp | 14 +++++------- vespalib/src/vespa/vespalib/btree/btreerootbase.h | 14 +++++------- .../vespa/vespalib/datastore/entry_comparator.h | 8 +++---- .../vespalib/datastore/entry_comparator_wrapper.h | 4 ++-- .../src/vespa/vespalib/datastore/unique_store.hpp | 2 +- .../vespalib/datastore/unique_store_comparator.h | 26 +++++++++++----------- .../vespalib/datastore/unique_store_entry_base.h | 10 ++++----- .../datastore/unique_store_string_allocator.h | 10 ++++----- .../datastore/unique_store_string_comparator.h | 14 ++++++------ vespalib/src/vespa/vespalib/text/utf8.h | 2 +- 18 files changed, 81 insertions(+), 94 deletions(-) (limited to 'vespalib') diff --git a/vespalib/src/tests/datastore/unique_store_dictionary/unique_store_dictionary_test.cpp b/vespalib/src/tests/datastore/unique_store_dictionary/unique_store_dictionary_test.cpp index e162d69529f..9dea9848d3a 100644 --- a/vespalib/src/tests/datastore/unique_store_dictionary/unique_store_dictionary_test.cpp +++ b/vespalib/src/tests/datastore/unique_store_dictionary/unique_store_dictionary_test.cpp @@ -16,7 +16,7 @@ class Comparator : public EntryComparator { private: EntryRef _to_find; - EntryRef resolve(EntryRef ref) const { + EntryRef resolve(EntryRef ref) const noexcept { if (ref == EntryRef()) { return _to_find; } @@ -24,16 +24,16 @@ private: } public: - explicit Comparator(uint32_t to_find) + explicit Comparator(uint32_t to_find) noexcept : _to_find(to_find) {} - bool less(const EntryRef lhs, const EntryRef rhs) const override { + bool less(const EntryRef lhs, const EntryRef rhs) const noexcept override { return resolve(lhs).ref() < resolve(rhs).ref(); } - bool equal(const EntryRef lhs, const EntryRef rhs) const override { + bool equal(const EntryRef lhs, const EntryRef rhs) const noexcept override { return resolve(lhs).ref() == resolve(rhs).ref(); } - size_t hash(const EntryRef rhs) const override { + size_t hash(const EntryRef rhs) const noexcept override { return rhs.valid() ? rhs.ref() : _to_find.ref(); } }; diff --git a/vespalib/src/vespa/vespalib/btree/btreeiterator.cpp b/vespalib/src/vespa/vespalib/btree/btreeiterator.cpp index 28c76a317e0..a03d9358069 100644 --- a/vespalib/src/vespa/vespalib/btree/btreeiterator.cpp +++ b/vespalib/src/vespa/vespalib/btree/btreeiterator.cpp @@ -8,9 +8,12 @@ namespace vespalib::btree { template class BTreeIteratorBase; template class BTreeIteratorBase; template class BTreeIteratorBase; +template class BTreeIteratorBase; +template class BTreeIteratorBase; template class BTreeConstIterator; template class BTreeConstIterator; template class BTreeConstIterator; +template class BTreeConstIterator; template class BTreeIterator; template class BTreeIterator; template class BTreeIterator; diff --git a/vespalib/src/vespa/vespalib/btree/btreeiterator.h b/vespalib/src/vespa/vespalib/btree/btreeiterator.h index cd63499a5ed..eae88c6e4be 100644 --- a/vespalib/src/vespa/vespalib/btree/btreeiterator.h +++ b/vespalib/src/vespa/vespalib/btree/btreeiterator.h @@ -5,6 +5,7 @@ #include "btreenode.h" #include "btreenodeallocator.h" #include "btreetraits.h" +#include #include namespace vespalib::btree { @@ -255,7 +256,7 @@ protected: * * @param pathSize New tree height (number of levels of internal nodes) */ - VESPA_DLL_LOCAL void clearPath(uint32_t pathSize); + void clearPath(uint32_t pathSize); /** * Call func with leaf entry key value as argument for all leaf entries in subtree @@ -327,7 +328,7 @@ public: */ const KeyType & getKey() const noexcept { return _leaf.getKey(); } - /** + /**stringatt * Get data at current iterator location. */ const DataType & getData() const noexcept { return _leaf.getData(); } @@ -366,7 +367,11 @@ public: /** * Setup iterator to be empty and not be associated with any tree. */ - VESPA_DLL_LOCAL void setupEmpty(); + void setupEmpty() { + clearPath(0u); + _leaf.invalidate(); + _leafRoot = nullptr; + } /** * Move iterator to beyond last element in the current tree. @@ -845,10 +850,13 @@ private: extern template class BTreeIteratorBase; extern template class BTreeIteratorBase; +extern template class BTreeIteratorBase; +extern template class BTreeIteratorBase; extern template class BTreeIteratorBase; extern template class BTreeConstIterator; extern template class BTreeConstIterator; extern template class BTreeConstIterator; +extern template class BTreeConstIterator; extern template class BTreeIterator; extern template class BTreeIterator; extern template class BTreeIterator; diff --git a/vespalib/src/vespa/vespalib/btree/btreeiterator.hpp b/vespalib/src/vespa/vespalib/btree/btreeiterator.hpp index b9afce54f6b..bdca5e2c4ff 100644 --- a/vespalib/src/vespa/vespalib/btree/btreeiterator.hpp +++ b/vespalib/src/vespa/vespalib/btree/btreeiterator.hpp @@ -91,18 +91,6 @@ setupEnd() } -template -void -BTreeIteratorBase:: -setupEmpty() -{ - clearPath(0u); - _leaf.invalidate(); - _leafRoot = nullptr; -} - - template void diff --git a/vespalib/src/vespa/vespalib/btree/btreenode.cpp b/vespalib/src/vespa/vespalib/btree/btreenode.cpp index 246eba8917b..6f858c40a66 100644 --- a/vespalib/src/vespa/vespalib/btree/btreenode.cpp +++ b/vespalib/src/vespa/vespalib/btree/btreenode.cpp @@ -14,9 +14,11 @@ template class BTreeNodeDataWrap; template class BTreeNodeT; template class BTreeNodeTT; template class BTreeNodeTT; +template class BTreeNodeTT; template class BTreeNodeTT; template class BTreeNodeTT; template class BTreeInternalNode; +template class BTreeInternalNode; template class BTreeInternalNode; template class BTreeLeafNode; template class BTreeLeafNode; diff --git a/vespalib/src/vespa/vespalib/btree/btreenode.h b/vespalib/src/vespa/vespalib/btree/btreenode.h index 7a4fa8030d3..075bae64834 100644 --- a/vespalib/src/vespa/vespalib/btree/btreenode.h +++ b/vespalib/src/vespa/vespalib/btree/btreenode.h @@ -488,9 +488,11 @@ extern template class BTreeNodeDataWrap; extern template class BTreeNodeT; extern template class BTreeNodeTT; extern template class BTreeNodeTT; +extern template class BTreeNodeTT; extern template class BTreeNodeTT; extern template class BTreeNodeTT; extern template class BTreeInternalNode; +extern template class BTreeInternalNode; extern template class BTreeInternalNode; extern template class BTreeLeafNode; extern template class BTreeLeafNode; diff --git a/vespalib/src/vespa/vespalib/btree/btreenodeallocator.cpp b/vespalib/src/vespa/vespalib/btree/btreenodeallocator.cpp index 99faaa6e2e8..fa51a38ab9a 100644 --- a/vespalib/src/vespa/vespalib/btree/btreenodeallocator.cpp +++ b/vespalib/src/vespa/vespalib/btree/btreenodeallocator.cpp @@ -7,14 +7,10 @@ template class vespalib::Array; namespace vespalib::btree { -template class BTreeNodeAllocator; -template class BTreeNodeAllocator; -template class BTreeNodeAllocator; +template class BTreeNodeAllocator; +template class BTreeNodeAllocator; +template class BTreeNodeAllocator; +template class BTreeNodeAllocator; +template class BTreeNodeAllocator; } diff --git a/vespalib/src/vespa/vespalib/btree/btreenodeallocator.h b/vespalib/src/vespa/vespalib/btree/btreenodeallocator.h index 16bd46a5596..e36d1507495 100644 --- a/vespalib/src/vespa/vespalib/btree/btreenodeallocator.h +++ b/vespalib/src/vespa/vespalib/btree/btreenodeallocator.h @@ -178,15 +178,11 @@ public: const NodeStore &getNodeStore() const { return _nodeStore; } }; -extern template class BTreeNodeAllocator; -extern template class BTreeNodeAllocator; -extern template class BTreeNodeAllocator; +extern template class BTreeNodeAllocator; +extern template class BTreeNodeAllocator; +extern template class BTreeNodeAllocator; +extern template class BTreeNodeAllocator; +extern template class BTreeNodeAllocator; } diff --git a/vespalib/src/vespa/vespalib/btree/btreerootbase.cpp b/vespalib/src/vespa/vespalib/btree/btreerootbase.cpp index b6eb589ea4a..48f4754ec4c 100644 --- a/vespalib/src/vespa/vespalib/btree/btreerootbase.cpp +++ b/vespalib/src/vespa/vespalib/btree/btreerootbase.cpp @@ -4,14 +4,10 @@ namespace vespalib::btree { -template class BTreeRootBase; -template class BTreeRootBase; -template class BTreeRootBase; +template class BTreeRootBase; +template class BTreeRootBase; +template class BTreeRootBase; +template class BTreeRootBase; +template class BTreeRootBase; } diff --git a/vespalib/src/vespa/vespalib/btree/btreerootbase.h b/vespalib/src/vespa/vespalib/btree/btreerootbase.h index 108cb2412a1..fa179dc8730 100644 --- a/vespalib/src/vespa/vespalib/btree/btreerootbase.h +++ b/vespalib/src/vespa/vespalib/btree/btreerootbase.h @@ -85,14 +85,10 @@ protected: void recursiveDelete(BTreeNode::Ref node, NodeAllocatorType &allocator); }; -extern template class BTreeRootBase; -extern template class BTreeRootBase; -extern template class BTreeRootBase; +extern template class BTreeRootBase; +extern template class BTreeRootBase; +extern template class BTreeRootBase; +extern template class BTreeRootBase; +extern template class BTreeRootBase; } diff --git a/vespalib/src/vespa/vespalib/datastore/entry_comparator.h b/vespalib/src/vespa/vespalib/datastore/entry_comparator.h index 9de2628b318..205284ee299 100644 --- a/vespalib/src/vespa/vespalib/datastore/entry_comparator.h +++ b/vespalib/src/vespa/vespalib/datastore/entry_comparator.h @@ -14,14 +14,14 @@ namespace vespalib::datastore { */ class EntryComparator { public: - virtual ~EntryComparator() {} + virtual ~EntryComparator() = default; /** * Returns true if the value represented by lhs ref is less than the value represented by rhs ref. */ - virtual bool less(const EntryRef lhs, const EntryRef rhs) const = 0; - virtual bool equal(const EntryRef lhs, const EntryRef rhs) const = 0; - virtual size_t hash(const EntryRef rhs) const = 0; + virtual bool less(const EntryRef lhs, const EntryRef rhs) const noexcept = 0; + virtual bool equal(const EntryRef lhs, const EntryRef rhs) const noexcept = 0; + virtual size_t hash(const EntryRef rhs) const noexcept = 0; }; } diff --git a/vespalib/src/vespa/vespalib/datastore/entry_comparator_wrapper.h b/vespalib/src/vespa/vespalib/datastore/entry_comparator_wrapper.h index e31b639928a..02281ab0435 100644 --- a/vespalib/src/vespa/vespalib/datastore/entry_comparator_wrapper.h +++ b/vespalib/src/vespa/vespalib/datastore/entry_comparator_wrapper.h @@ -12,10 +12,10 @@ namespace vespalib::datastore { class EntryComparatorWrapper { const EntryComparator &_comp; public: - EntryComparatorWrapper(const EntryComparator &comp) + EntryComparatorWrapper(const EntryComparator &comp) noexcept : _comp(comp) { } - bool operator()(const AtomicEntryRef &lhs, const AtomicEntryRef &rhs) const { + bool operator()(const AtomicEntryRef &lhs, const AtomicEntryRef &rhs) const noexcept { return _comp.less(lhs.load_acquire(), rhs.load_acquire()); } }; diff --git a/vespalib/src/vespa/vespalib/datastore/unique_store.hpp b/vespalib/src/vespa/vespalib/datastore/unique_store.hpp index b2c4d4e8d7e..ab2770bc1b0 100644 --- a/vespalib/src/vespa/vespalib/datastore/unique_store.hpp +++ b/vespalib/src/vespa/vespalib/datastore/unique_store.hpp @@ -29,7 +29,7 @@ using DefaultUniqueStoreDictionary = UniqueStoreDictionary; template UniqueStore::UniqueStore(std::shared_ptr memory_allocator) - : UniqueStore(std::move(memory_allocator), [](const auto& data_store) { return ComparatorType(data_store);}) + : UniqueStore(std::move(memory_allocator), [](const auto& data_store) noexcept { return ComparatorType(data_store);}) {} template diff --git a/vespalib/src/vespa/vespalib/datastore/unique_store_comparator.h b/vespalib/src/vespa/vespalib/datastore/unique_store_comparator.h index 267245bc215..68a0a532ed3 100644 --- a/vespalib/src/vespa/vespalib/datastore/unique_store_comparator.h +++ b/vespalib/src/vespa/vespalib/datastore/unique_store_comparator.h @@ -16,13 +16,13 @@ namespace vespalib::datastore { template class UniqueStoreComparatorHelper { public: - static bool less(const EntryT& lhs, const EntryT& rhs) { + static bool less(const EntryT& lhs, const EntryT& rhs) noexcept { return lhs < rhs; } - static bool equal(const EntryT& lhs, const EntryT& rhs) { + static bool equal(const EntryT& lhs, const EntryT& rhs) noexcept { return lhs == rhs; } - static size_t hash(const EntryT& rhs) { + static size_t hash(const EntryT& rhs) noexcept { vespalib::hash hasher; return hasher(rhs); } @@ -36,7 +36,7 @@ template class UniqueStoreFloatingPointComparatorHelper { public: - static bool less(EntryT lhs, const EntryT rhs) { + static bool less(EntryT lhs, const EntryT rhs) noexcept { if (std::isnan(lhs)) { return !std::isnan(rhs); } else if (std::isnan(rhs)) { @@ -45,7 +45,7 @@ public: return (lhs < rhs); } } - static bool equal(EntryT lhs, const EntryT rhs) { + static bool equal(EntryT lhs, const EntryT rhs) noexcept { if (std::isnan(lhs)) { return std::isnan(rhs); } else if (std::isnan(rhs)) { @@ -54,7 +54,7 @@ public: return (lhs == rhs); } } - static size_t hash(EntryT rhs) { + static size_t hash(EntryT rhs) noexcept { if (std::isnan(rhs)) { return 0; } else { @@ -98,7 +98,7 @@ protected: const DataStoreType &_store; const EntryType _lookup_value; - inline const EntryType &get(EntryRef ref) const { + const EntryType &get(EntryRef ref) const noexcept { if (ref.valid()) { RefType iRef(ref); return _store.template getEntry(iRef)->value(); @@ -106,34 +106,34 @@ protected: return _lookup_value; } } - UniqueStoreComparator(const DataStoreType &store, const EntryType &lookup_value) + UniqueStoreComparator(const DataStoreType &store, const EntryType &lookup_value) noexcept : _store(store), _lookup_value(lookup_value) { } public: - UniqueStoreComparator(const DataStoreType &store) + UniqueStoreComparator(const DataStoreType &store) noexcept : _store(store), _lookup_value() { } - bool less(const EntryRef lhs, const EntryRef rhs) const override { + bool less(const EntryRef lhs, const EntryRef rhs) const noexcept override { const EntryType &lhsValue = get(lhs); const EntryType &rhsValue = get(rhs); return UniqueStoreComparatorHelper::less(lhsValue, rhsValue); } - bool equal(const EntryRef lhs, const EntryRef rhs) const override { + bool equal(const EntryRef lhs, const EntryRef rhs) const noexcept override { const EntryType &lhsValue = get(lhs); const EntryType &rhsValue = get(rhs); return UniqueStoreComparatorHelper::equal(lhsValue, rhsValue); } - size_t hash(const EntryRef rhs) const override { + size_t hash(const EntryRef rhs) const noexcept override { const EntryType &rhsValue = get(rhs); return UniqueStoreComparatorHelper::hash(rhsValue); } - UniqueStoreComparator make_for_lookup(const EntryType& lookup_value) const { + UniqueStoreComparator make_for_lookup(const EntryType& lookup_value) const noexcept { return UniqueStoreComparator(_store, lookup_value); } }; diff --git a/vespalib/src/vespa/vespalib/datastore/unique_store_entry_base.h b/vespalib/src/vespa/vespalib/datastore/unique_store_entry_base.h index b8496f40464..a14e32ab2ad 100644 --- a/vespalib/src/vespa/vespalib/datastore/unique_store_entry_base.h +++ b/vespalib/src/vespa/vespalib/datastore/unique_store_entry_base.h @@ -15,18 +15,18 @@ namespace vespalib::datastore { class UniqueStoreEntryBase { mutable uint32_t _ref_count; protected: - constexpr UniqueStoreEntryBase() + constexpr UniqueStoreEntryBase() noexcept : _ref_count(0u) { } public: - uint32_t get_ref_count() const { return _ref_count; } - void set_ref_count(uint32_t ref_count) const { _ref_count = ref_count; } - void inc_ref_count() const { + uint32_t get_ref_count() const noexcept { return _ref_count; } + void set_ref_count(uint32_t ref_count) const noexcept { _ref_count = ref_count; } + void inc_ref_count() const noexcept { assert(_ref_count < std::numeric_limits::max()); ++_ref_count; } - void dec_ref_count() const { + void dec_ref_count() const noexcept { assert(_ref_count > 0u); --_ref_count; } diff --git a/vespalib/src/vespa/vespalib/datastore/unique_store_string_allocator.h b/vespalib/src/vespa/vespalib/datastore/unique_store_string_allocator.h index 1294a936a38..06b51ad301c 100644 --- a/vespalib/src/vespa/vespalib/datastore/unique_store_string_allocator.h +++ b/vespalib/src/vespa/vespalib/datastore/unique_store_string_allocator.h @@ -32,12 +32,12 @@ uint32_t get_type_id(size_t string_len); class UniqueStoreSmallStringEntry : public UniqueStoreEntryBase { char _value[0]; public: - constexpr UniqueStoreSmallStringEntry() + constexpr UniqueStoreSmallStringEntry() noexcept : UniqueStoreEntryBase(), _value() { } - UniqueStoreSmallStringEntry(const char *value, size_t value_len, size_t array_size) + UniqueStoreSmallStringEntry(const char *value, size_t value_len, size_t array_size) noexcept : UniqueStoreEntryBase() { assert(value_offset() + value_len < array_size); @@ -45,12 +45,12 @@ public: memset(&_value[0] + value_len, 0, array_size - value_len - value_offset()); } - void clean_hold(size_t array_size) { + void clean_hold(size_t array_size) noexcept { memset(&_value[0], 0, array_size - value_offset()); } - const char *value() const { return &_value[0]; } - size_t value_offset() const { return &_value[0] - reinterpret_cast(this); } + const char *value() const noexcept { return &_value[0]; } + size_t value_offset() const noexcept { return &_value[0] - reinterpret_cast(this); } }; /* diff --git a/vespalib/src/vespa/vespalib/datastore/unique_store_string_comparator.h b/vespalib/src/vespa/vespalib/datastore/unique_store_string_comparator.h index a0f338ad931..f91f2c1fd9b 100644 --- a/vespalib/src/vespa/vespalib/datastore/unique_store_string_comparator.h +++ b/vespalib/src/vespa/vespalib/datastore/unique_store_string_comparator.h @@ -23,7 +23,7 @@ protected: const DataStoreType &_store; const char *_lookup_value; - const char *get(EntryRef ref) const { + const char *get(EntryRef ref) const noexcept { if (ref.valid()) { RefType iRef(ref); const auto &meta = _store.getBufferMeta(iRef.bufferId()); @@ -37,33 +37,33 @@ protected: return _lookup_value; } } - UniqueStoreStringComparator(const DataStoreType &store, const char *lookup_value) + UniqueStoreStringComparator(const DataStoreType &store, const char *lookup_value) noexcept : _store(store), _lookup_value(lookup_value) { } public: - UniqueStoreStringComparator(const DataStoreType &store) + UniqueStoreStringComparator(const DataStoreType &store) noexcept : _store(store), _lookup_value(nullptr) { } - bool less(const EntryRef lhs, const EntryRef rhs) const override { + bool less(const EntryRef lhs, const EntryRef rhs) const noexcept override { const char *lhs_value = get(lhs); const char *rhs_value = get(rhs); return (strcmp(lhs_value, rhs_value) < 0); } - bool equal(const EntryRef lhs, const EntryRef rhs) const override { + bool equal(const EntryRef lhs, const EntryRef rhs) const noexcept override { const char *lhs_value = get(lhs); const char *rhs_value = get(rhs); return (strcmp(lhs_value, rhs_value) == 0); } - size_t hash(const EntryRef rhs) const override { + size_t hash(const EntryRef rhs) const noexcept override { const char *rhs_value = get(rhs); vespalib::hash hasher; return hasher(rhs_value); } - UniqueStoreStringComparator make_for_lookup(const char* lookup_value) const { + UniqueStoreStringComparator make_for_lookup(const char* lookup_value) const noexcept { return UniqueStoreStringComparator(_store, lookup_value); } }; diff --git a/vespalib/src/vespa/vespalib/text/utf8.h b/vespalib/src/vespa/vespalib/text/utf8.h index b1168c48ccf..26439f16d66 100644 --- a/vespalib/src/vespa/vespalib/text/utf8.h +++ b/vespalib/src/vespa/vespalib/text/utf8.h @@ -304,7 +304,7 @@ public: * * @return a valid UCS-4 codepoint **/ - uint32_t getChar() noexcept{ return getChar(Utf8::REPLACEMENT_CHAR); } + uint32_t getChar() noexcept { return getChar(Utf8::REPLACEMENT_CHAR); } /** * count the number of UCS-4 characters will be returned when -- cgit v1.2.3