From 2e8a79cab1fbb534f06ba23db6686810c3ecaf91 Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Thu, 25 Apr 2024 11:04:57 +0000 Subject: Add noexcept --- vespalib/src/vespa/vespalib/btree/btreeiterator.h | 115 ++++++++------- .../src/vespa/vespalib/btree/btreeiterator.hpp | 164 ++++++++------------- 2 files changed, 116 insertions(+), 163 deletions(-) (limited to 'vespalib') diff --git a/vespalib/src/vespa/vespalib/btree/btreeiterator.h b/vespalib/src/vespa/vespalib/btree/btreeiterator.h index a0d189ef03c..505ad4c5c3b 100644 --- a/vespalib/src/vespa/vespalib/btree/btreeiterator.h +++ b/vespalib/src/vespa/vespalib/btree/btreeiterator.h @@ -39,7 +39,7 @@ class NodeElement using DataType = typename NodeType::DataType; uint64_t _nodeAndIdx; - NodeType * getWNode() const { return const_cast(getNode()); } + NodeType * getWNode() const noexcept { return const_cast(getNode()); } static constexpr uint8_t NODE_BITS = 57; static constexpr uint8_t IDX_BITS = 64 - NODE_BITS; static constexpr uint64_t NODE_MASK = (1ul << NODE_BITS) - 1ul; @@ -162,12 +162,12 @@ private: /* * Find the next leaf node, called by operator++() as needed. */ - void findNextLeafNode(); + void findNextLeafNode() noexcept; /* * Find the previous leaf node, called by operator--() as needed. */ - void findPrevLeafNode(); + void findPrevLeafNode() noexcept; protected: /* @@ -175,7 +175,7 @@ protected: * * @param pidx Number of levels above leaf nodes to take into account. */ - size_t position(uint32_t pidx) const; + size_t position(uint32_t pidx) const noexcept; /** * Create iterator pointing to first element in the tree referenced @@ -184,7 +184,7 @@ protected: * @param root Reference to root of tree * @param allocator B-tree node allocator helper class. */ - BTreeIteratorBase(BTreeNode::Ref root, const NodeAllocatorType &allocator); + BTreeIteratorBase(BTreeNode::Ref root, const NodeAllocatorType &allocator) noexcept; /** * Compability constructor, creating a temporary tree with only a @@ -204,7 +204,7 @@ protected: /** * Step iterator forwards. If at end then leave it at end. */ - BTreeIteratorBase & operator++() { + BTreeIteratorBase & operator++() noexcept { if (_leaf.getNode() == nullptr) { return *this; } @@ -220,7 +220,7 @@ protected: * Step iterator backwards. If at end then place it at last valid * position in tree (cf. rbegin()) */ - BTreeIteratorBase & operator--() { + BTreeIteratorBase & operator--() noexcept { if (_leaf.getNode() == nullptr) { rbegin(); return *this; @@ -233,17 +233,17 @@ protected: return *this; } - void set_subtree_position(const InternalNodeType* node, uint32_t level, uint32_t idx, size_t position); + void set_subtree_position(const InternalNodeType* node, uint32_t level, uint32_t idx, size_t position) noexcept; /* * Step iterator forwards the given number of steps. */ - void step_forward(size_t steps); + void step_forward(size_t steps) noexcept; /* * Step iterator backwards the given number of steps. */ - void step_backward(size_t steps); + void step_backward(size_t steps) noexcept; ~BTreeIteratorBase(); BTreeIteratorBase(const BTreeIteratorBase &other); @@ -256,7 +256,7 @@ protected: * * @param pathSize New tree height (number of levels of internal nodes) */ - void clearPath(uint32_t pathSize); + void clearPath(uint32_t pathSize) noexcept; /** * Call func with leaf entry key value as argument for all leaf entries in subtree @@ -347,12 +347,12 @@ public: /** * Return the current position in the tree. */ - size_t position() const { return position(_pathSize); } + size_t position() const noexcept { return position(_pathSize); } /** * Return the distance between two positions in the tree. */ - ssize_t operator-(const BTreeIteratorBase &rhs) const; + ssize_t operator-(const BTreeIteratorBase &rhs) const noexcept; /** * Return if the tree has data or not (e.g. keys and data or only keys). @@ -362,12 +362,14 @@ public: /** * Move the iterator directly to end. Used by findHelper method in BTree. */ - void setupEnd(); + void setupEnd() noexcept { + _leaf.invalidate(); + } /** * Setup iterator to be empty and not be associated with any tree. */ - void setupEmpty() { + void setupEmpty() noexcept { clearPath(0u); _leaf.invalidate(); _leafRoot = nullptr; @@ -376,44 +378,43 @@ public: /** * Move iterator to beyond last element in the current tree. */ - void end() __attribute__((noinline)); + void end() noexcept __attribute__((noinline)); /** * Move iterator to beyond last element in the given tree. * * @param rootRef Reference to root of tree. */ - void end(BTreeNode::Ref rootRef); + void end(BTreeNode::Ref rootRef) noexcept; /** * Move iterator to first element in the current tree. */ - void begin(); + void begin() noexcept; /** * Move iterator to first element in the given tree. * * @param rootRef Reference to root of tree. */ - void begin(BTreeNode::Ref rootRef); + void begin(BTreeNode::Ref rootRef) noexcept; /** * Move iterator to last element in the current tree. */ - void rbegin(); + void rbegin() noexcept; /* * Get aggregated values for the current tree. */ - const AggrT & getAggregated() const; + const AggrT & getAggregated() const noexcept; - bool identical(const BTreeIteratorBase &rhs) const; + bool identical(const BTreeIteratorBase &rhs) const noexcept; template - void foreach_key(FunctionType func) const { + void foreach_key(FunctionType func) const noexcept { if (_pathSize > 0) { - _path[_pathSize - 1].getNode()-> - foreach_key(_allocator->getNodeStore(), func); + _path[_pathSize - 1].getNode()->foreach_key(_allocator->getNodeStore(), func); } else if (_leafRoot != nullptr) { _leafRoot->foreach_key(func); } @@ -425,7 +426,7 @@ public: * range [this iterator, end_itr)). */ template - void foreach_key_range(const BTreeIteratorBase &end_itr, FunctionType func) const { + void foreach_key_range(const BTreeIteratorBase &end_itr, FunctionType func) const noexcept { if (!valid()) { return; } @@ -536,7 +537,7 @@ public: * @param root Reference to root of tree * @param allocator B-tree node allocator helper class. */ - BTreeConstIterator(BTreeNode::Ref root, const NodeAllocatorType &allocator) + BTreeConstIterator(BTreeNode::Ref root, const NodeAllocatorType &allocator) noexcept : ParentType(root, allocator) { } @@ -562,7 +563,7 @@ public: /** * Step iterator forwards. If at end then leave it at end. */ - BTreeConstIterator & operator++() { + BTreeConstIterator & operator++() noexcept { ParentType::operator++(); return *this; } @@ -571,7 +572,7 @@ public: * Step iterator backwards. If at end then place it at last valid * position in tree (cf. rbegin()) */ - BTreeConstIterator & operator--() { + BTreeConstIterator & operator--() noexcept { ParentType::operator--(); return *this; } @@ -579,7 +580,7 @@ public: /* * Step iterator forwards the given number of steps. */ - BTreeConstIterator & operator+=(size_t steps) { + BTreeConstIterator & operator+=(size_t steps) noexcept { step_forward(steps); return *this; } @@ -587,7 +588,7 @@ public: /* * Step iterator backward the given number of steps. */ - BTreeConstIterator & operator-=(size_t steps) { + BTreeConstIterator & operator-=(size_t steps) noexcept { step_backward(steps); return *this; } @@ -599,7 +600,7 @@ public: * @param key Key to search for * @param comp Comparator for the tree ordering. */ - void lower_bound(const KeyType & key, CompareT comp = CompareT()); + void lower_bound(const KeyType & key, CompareT comp = CompareT()) noexcept; /** * Position iterator at first position with a key that is greater @@ -608,7 +609,7 @@ public: * @param key Key to search for * @param comp Comparator for the tree ordering. */ - void lower_bound(BTreeNode::Ref rootRef, const KeyType & key, CompareT comp = CompareT()); + void lower_bound(BTreeNode::Ref rootRef, const KeyType & key, CompareT comp = CompareT()) noexcept; /** * Step iterator forwards until it is at a position with a key @@ -621,7 +622,7 @@ public: * @param key Key to search for * @param comp Comparator for the tree ordering. */ - void seek(const KeyType &key, CompareT comp = CompareT()); + void seek(const KeyType &key, CompareT comp = CompareT()) noexcept; /** * Step iterator forwards until it is at a position with a key @@ -633,7 +634,7 @@ public: * @param key Key to search for * @param comp Comparator for the tree ordering. */ - void binarySeek(const KeyType &key, CompareT comp = CompareT()); + void binarySeek(const KeyType &key, CompareT comp = CompareT()) noexcept; /** * Step iterator forwards until it is at a position with a key @@ -645,7 +646,7 @@ public: * @param key Key to search for * @param comp Comparator for the tree ordering. */ - void linearSeek(const KeyType &key, CompareT comp = CompareT()); + void linearSeek(const KeyType &key, CompareT comp = CompareT()) noexcept; /** * Step iterator forwards until it is at a position with a key @@ -658,7 +659,7 @@ public: * @param key Key to search for * @param comp Comparator for the tree ordering. */ - void seekPast(const KeyType &key, CompareT comp = CompareT()); + void seekPast(const KeyType &key, CompareT comp = CompareT()) noexcept; /** * Step iterator forwards until it is at a position with a key @@ -670,7 +671,7 @@ public: * @param key Key to search for * @param comp Comparator for the tree ordering. */ - void binarySeekPast(const KeyType &key, CompareT comp = CompareT()); + void binarySeekPast(const KeyType &key, CompareT comp = CompareT()) noexcept; /** * Step iterator forwards until it is at a position with a key @@ -682,7 +683,7 @@ public: * @param key Key to search for * @param comp Comparator for the tree ordering. */ - void linearSeekPast(const KeyType &key, CompareT comp = CompareT()); + void linearSeekPast(const KeyType &key, CompareT comp = CompareT()) noexcept; /** * Validate the iterator as a valid iterator or positioned at @@ -692,7 +693,7 @@ public: * @param rootRef Reference to root of tree to operate on * @param comp Comparator for the tree ordering. */ - void validate(BTreeNode::Ref rootRef, CompareT comp = CompareT()); + void validate(BTreeNode::Ref rootRef, CompareT comp = CompareT()) noexcept; }; @@ -737,7 +738,7 @@ public: using ParentType::step_forward; using EntryRef = datastore::EntryRef; - BTreeIterator(BTreeNode::Ref root, const NodeAllocatorType &allocator) + BTreeIterator(BTreeNode::Ref root, const NodeAllocatorType &allocator) noexcept : ParentType(root, allocator) { } @@ -751,29 +752,29 @@ public: { } - BTreeIterator() : ParentType() { } + BTreeIterator() noexcept : ParentType() { } - BTreeIterator & operator++() { + BTreeIterator & operator++() noexcept { ParentType::operator++(); return *this; } - BTreeIterator & operator--() { + BTreeIterator & operator--() noexcept { ParentType::operator--(); return *this; } - BTreeIterator & operator+=(size_t steps) { + BTreeIterator & operator+=(size_t steps) noexcept { step_forward(steps); return *this; } - BTreeIterator & operator-=(size_t steps) { + BTreeIterator & operator-=(size_t steps) noexcept { step_backward(steps); return *this; } - NodeAllocatorType & getAllocator() const { + NodeAllocatorType & getAllocator() const noexcept { return const_cast(*_allocator); } @@ -781,19 +782,19 @@ public: void moveNextLeafNode(); - void writeData(const DataType &data) { + void writeData(const DataType &data) noexcept { _leaf.getWNode()->writeData(_leaf.getIdx(), data); } // Only use during compaction when changing reference to moved value - DataType &getWData() { return _leaf.getWData(); } + DataType &getWData() noexcept { return _leaf.getWData(); } /** * Set a new key for the current iterator position. * The new key must have the same semantic meaning as the old key. * Typically used when compacting data store containing keys. */ - void writeKey(const KeyType &key); + void writeKey(const KeyType &key) noexcept; /** * Updata data at the current iterator position. The tree should @@ -803,7 +804,7 @@ public: * @param aggrCalc Calculator for updating aggregated information. */ template - void updateData(const DataType &data, const AggrCalcT &aggrCalc); + void updateData(const DataType &data, const AggrCalcT &aggrCalc) noexcept; /** * Thaw a path from the root node down the the current leaf node in @@ -816,12 +817,12 @@ private: /* Insert into empty tree */ template BTreeNode::Ref insertFirst(const KeyType &key, const DataType &data, const AggrCalcT &aggrCalc); - LeafNodeType * getLeafNode() const { return _leaf.getWNode(); } - bool setLeafNodeIdx(uint32_t idx, const LeafNodeType *splitLeafNode); - void setLeafNodeIdx(uint32_t idx) { _leaf.setIdx(idx); } - uint32_t getLeafNodeIdx() const { return _leaf.getIdx(); } - uint32_t getPathSize() const { return _pathSize; } - PathElement & getPath(uint32_t pidx) { return _path[pidx]; } + LeafNodeType * getLeafNode() const noexcept { return _leaf.getWNode(); } + bool setLeafNodeIdx(uint32_t idx, const LeafNodeType *splitLeafNode) noexcept; + void setLeafNodeIdx(uint32_t idx) noexcept { _leaf.setIdx(idx); } + uint32_t getLeafNodeIdx() const noexcept { return _leaf.getIdx(); } + uint32_t getPathSize() const noexcept { return _pathSize; } + PathElement & getPath(uint32_t pidx) noexcept { return _path[pidx]; } template BTreeNode::Ref addLevel(BTreeNode::Ref rootRef, BTreeNode::Ref splitNodeRef, bool inRightSplit, const AggrCalcT &aggrCalc); diff --git a/vespalib/src/vespa/vespalib/btree/btreeiterator.hpp b/vespalib/src/vespa/vespalib/btree/btreeiterator.hpp index bdca5e2c4ff..e1196d7c6db 100644 --- a/vespalib/src/vespa/vespalib/btree/btreeiterator.hpp +++ b/vespalib/src/vespa/vespalib/btree/btreeiterator.hpp @@ -52,7 +52,7 @@ template void BTreeIteratorBase:: -clearPath(uint32_t pathSize) +clearPath(uint32_t pathSize) noexcept { uint32_t level = _pathSize; while (level > pathSize) { @@ -84,18 +84,7 @@ BTreeIteratorBase::~B template void -BTreeIteratorBase:: -setupEnd() -{ - _leaf.invalidate(); -} - - -template -void -BTreeIteratorBase:: -end() +BTreeIteratorBase::end() noexcept { if (_pathSize == 0) { if (_leafRoot == nullptr) @@ -126,8 +115,7 @@ end() template void -BTreeIteratorBase:: -end(BTreeNode::Ref rootRef) +BTreeIteratorBase::end(BTreeNode::Ref rootRef) noexcept { if (!rootRef.valid()) { setupEmpty(); @@ -167,7 +155,7 @@ template void BTreeIteratorBase:: -findNextLeafNode() +findNextLeafNode() noexcept { uint32_t pidx; for (pidx = 0; pidx < _pathSize; ++pidx) { @@ -195,7 +183,7 @@ template void BTreeIteratorBase:: -findPrevLeafNode() +findPrevLeafNode() noexcept { uint32_t pidx; for (pidx = 0; pidx < _pathSize; ++pidx) { @@ -225,8 +213,7 @@ findPrevLeafNode() template void -BTreeIteratorBase:: -begin() +BTreeIteratorBase::begin() noexcept { uint32_t pidx = _pathSize; if (pidx > 0u) { @@ -251,8 +238,7 @@ begin() template void -BTreeIteratorBase:: -begin(BTreeNode::Ref rootRef) +BTreeIteratorBase::begin(BTreeNode::Ref rootRef) noexcept { if (!rootRef.valid()) { setupEmpty(); @@ -288,8 +274,7 @@ begin(BTreeNode::Ref rootRef) template void -BTreeIteratorBase:: -rbegin() +BTreeIteratorBase::rbegin() noexcept { uint32_t pidx = _pathSize; if (pidx > 0u) { @@ -310,10 +295,7 @@ rbegin() const LeafNodeType *lnode(_allocator->mapLeafRef(node)); _leaf.setNodeAndIdx(lnode, lnode->validSlots() - 1); } else { - _leaf.setNodeAndIdx(_leafRoot, - (_leafRoot != nullptr) ? - _leafRoot->validSlots() - 1 : - 0u); + _leaf.setNodeAndIdx(_leafRoot, (_leafRoot != nullptr) ? _leafRoot->validSlots() - 1 : 0u); } } @@ -322,7 +304,7 @@ template const AggrT & BTreeIteratorBase:: -getAggregated() const +getAggregated() const noexcept { // XXX: Undefined behavior if tree is empty. uint32_t pidx = _pathSize; @@ -340,7 +322,7 @@ template size_t BTreeIteratorBase:: -position(uint32_t levels) const +position(uint32_t levels) const noexcept { assert(_pathSize >= levels); if (_leaf.getNode() == nullptr) @@ -393,8 +375,7 @@ position(uint32_t levels) const template BTreeIteratorBase:: -BTreeIteratorBase(BTreeNode::Ref root, - const NodeAllocatorType &allocator) +BTreeIteratorBase(BTreeNode::Ref root, const NodeAllocatorType &allocator) noexcept : _leaf(nullptr, 0u), _path(), _pathSize(0), @@ -467,7 +448,7 @@ template ssize_t BTreeIteratorBase:: -operator-(const BTreeIteratorBase &rhs) const +operator-(const BTreeIteratorBase &rhs) const noexcept { if (_leaf.getNode() == nullptr) { if (rhs._leaf.getNode() == nullptr) @@ -497,7 +478,7 @@ template bool BTreeIteratorBase:: -identical(const BTreeIteratorBase &rhs) const +identical(const BTreeIteratorBase &rhs) const noexcept { if (_pathSize != rhs._pathSize || _leaf != rhs._leaf) { HDR_ABORT("should not be reached"); @@ -518,7 +499,7 @@ template void BTreeIteratorBase:: -set_subtree_position(const InternalNodeType* node, uint32_t level, uint32_t idx, size_t position) +set_subtree_position(const InternalNodeType* node, uint32_t level, uint32_t idx, size_t position) noexcept { /* * Walk down subtree adjusting iterator for new partial position. @@ -550,7 +531,7 @@ template void BTreeIteratorBase:: -step_forward(size_t steps) +step_forward(size_t steps) noexcept { auto lnode = _leaf.getNode(); if (lnode == nullptr) { @@ -600,8 +581,7 @@ step_forward(size_t steps) template void -BTreeIteratorBase:: -step_backward(size_t steps) +BTreeIteratorBase::step_backward(size_t steps) noexcept { int64_t remaining_steps = steps; if (remaining_steps == 0) { @@ -651,11 +631,10 @@ step_backward(size_t steps) set_subtree_position(node, level, idx, -remaining_steps); } -template +template void BTreeConstIterator:: -lower_bound(const KeyType & key, CompareT comp) +lower_bound(const KeyType & key, CompareT comp) noexcept { if (_pathSize == 0) { if (_leafRoot == nullptr) @@ -696,11 +675,10 @@ lower_bound(const KeyType & key, CompareT comp) } -template +template void BTreeConstIterator:: -lower_bound(BTreeNode::Ref rootRef, const KeyType & key, CompareT comp) +lower_bound(BTreeNode::Ref rootRef, const KeyType & key, CompareT comp) noexcept { if (!rootRef.valid()) { setupEmpty(); @@ -748,11 +726,10 @@ lower_bound(BTreeNode::Ref rootRef, const KeyType & key, CompareT comp) } -template +template void BTreeConstIterator:: -seek(const KeyType & key, CompareT comp) +seek(const KeyType & key, CompareT comp) noexcept { if (TraitsT::BINARY_SEEK) { binarySeek(key, comp); @@ -761,11 +738,10 @@ seek(const KeyType & key, CompareT comp) } } -template +template void BTreeConstIterator:: -binarySeek(const KeyType & key, CompareT comp) +binarySeek(const KeyType & key, CompareT comp) noexcept { const LeafNodeType *lnode = _leaf.getNode(); uint32_t lidx = _leaf.getIdx() + 1; @@ -806,11 +782,10 @@ binarySeek(const KeyType & key, CompareT comp) _leaf.setIdx(lidx); } -template +template void BTreeConstIterator:: -linearSeek(const KeyType & key, CompareT comp) +linearSeek(const KeyType & key, CompareT comp) noexcept { const LeafNodeType *lnode = _leaf.getNode(); uint32_t lidx = _leaf.getIdx() + 1; @@ -858,11 +833,10 @@ linearSeek(const KeyType & key, CompareT comp) _leaf.setIdx(lidx); } -template +template void BTreeConstIterator:: -seekPast(const KeyType & key, CompareT comp) +seekPast(const KeyType & key, CompareT comp) noexcept { if (TraitsT::BINARY_SEEK) { binarySeekPast(key, comp); @@ -871,11 +845,10 @@ seekPast(const KeyType & key, CompareT comp) } } -template +template void BTreeConstIterator:: -binarySeekPast(const KeyType & key, CompareT comp) +binarySeekPast(const KeyType & key, CompareT comp) noexcept { const LeafNodeType *lnode = _leaf.getNode(); uint32_t lidx = _leaf.getIdx() + 1; @@ -916,11 +889,10 @@ binarySeekPast(const KeyType & key, CompareT comp) _leaf.setIdx(lidx); } -template +template void BTreeConstIterator:: -linearSeekPast(const KeyType & key, CompareT comp) +linearSeekPast(const KeyType & key, CompareT comp) noexcept { const LeafNodeType *lnode = _leaf.getNode(); uint32_t lidx = _leaf.getIdx() + 1; @@ -970,11 +942,10 @@ linearSeekPast(const KeyType & key, CompareT comp) } -template +template void BTreeConstIterator:: -validate(BTreeNode::Ref rootRef, CompareT comp) +validate(BTreeNode::Ref rootRef, CompareT comp) noexcept { bool frozen = false; if (!rootRef.valid()) { @@ -1036,8 +1007,7 @@ validate(BTreeNode::Ref rootRef, CompareT comp) } -template +template BTreeNode::Ref BTreeIterator:: moveFirstLeafNode(BTreeNode::Ref rootRef) @@ -1100,11 +1070,9 @@ moveFirstLeafNode(BTreeNode::Ref rootRef) } -template +template void -BTreeIterator:: -moveNextLeafNode() +BTreeIterator::moveNextLeafNode() { uint32_t level = 0; uint32_t levels = _pathSize; @@ -1146,11 +1114,9 @@ moveNextLeafNode() } -template +template void -BTreeIterator:: -writeKey(const KeyType & key) +BTreeIterator::writeKey(const KeyType & key) noexcept { LeafNodeType * lnode = getLeafNode(); lnode->writeKey(_leaf.getIdx(), key); @@ -1170,12 +1136,11 @@ writeKey(const KeyType & key) } -template +template template void BTreeIterator:: -updateData(const DataType & data, [[maybe_unused]] const AggrCalcT &aggrCalc) +updateData(const DataType & data, [[maybe_unused]] const AggrCalcT &aggrCalc) noexcept { LeafNodeType * lnode = getLeafNode(); if constexpr (AggrCalcT::hasAggregated() && AggrCalcT::aggregate_over_values()) { @@ -1198,8 +1163,7 @@ updateData(const DataType & data, [[maybe_unused]] const AggrCalcT &aggrCalc) const PathElement & pe = _path[i]; InternalNodeType * inode = pe.getWNode(); AggrT oldpa(inode->getAggregated()); - if (aggrCalc.update(inode->getAggregated(), - oldca, ca)) { + if (aggrCalc.update(inode->getAggregated(), oldca, ca)) { Aggregator::recalc(*inode, *_allocator, aggrCalc); } AggrT pa(inode->getAggregated()); @@ -1212,11 +1176,9 @@ updateData(const DataType & data, [[maybe_unused]] const AggrCalcT &aggrCalc) } -template +template BTreeNode::Ref -BTreeIterator:: -thaw(BTreeNode::Ref rootRef) +BTreeIterator::thaw(BTreeNode::Ref rootRef) { assert(_leaf.getNode() != nullptr && _compatLeafNode.get() == nullptr); if (!_leaf.getNode()->getFrozen()) @@ -1226,20 +1188,17 @@ thaw(BTreeNode::Ref rootRef) LeafNodeType *leafNode = allocator.mapLeafRef(rootRef); assert(leafNode == _leaf.getNode()); assert(leafNode == _leafRoot); - LeafNodeTypeRefPair thawedLeaf = allocator.thawNode(rootRef, - leafNode); + LeafNodeTypeRefPair thawedLeaf = allocator.thawNode(rootRef, leafNode); _leaf.setNode(thawedLeaf.data); _leafRoot = thawedLeaf.data; return thawedLeaf.ref; } assert(_leafRoot == nullptr); - assert(_path[_pathSize - 1].getNode() == - allocator.mapInternalRef(rootRef)); + assert(_path[_pathSize - 1].getNode() == allocator.mapInternalRef(rootRef)); BTreeNode::Ref childRef(_path[0].getNode()->getChild(_path[0].getIdx())); LeafNodeType *leafNode = allocator.mapLeafRef(childRef); assert(leafNode == _leaf.getNode()); - LeafNodeTypeRefPair thawedLeaf = allocator.thawNode(childRef, - leafNode); + LeafNodeTypeRefPair thawedLeaf = allocator.thawNode(childRef, leafNode); _leaf.setNode(thawedLeaf.data); childRef = thawedLeaf.ref; uint32_t level = 0; @@ -1247,10 +1206,9 @@ thaw(BTreeNode::Ref rootRef) while (level < levels) { PathElement &pe = _path[level]; InternalNodeType *node(pe.getWNode()); - BTreeNode::Ref nodeRef = level + 1 < levels ? - _path[level + 1].getNode()-> - getChild(_path[level + 1].getIdx()) : - rootRef; + BTreeNode::Ref nodeRef = (level + 1 < levels) + ? _path[level + 1].getNode()->getChild(_path[level + 1].getIdx()) + : rootRef; assert(node == allocator.mapInternalRef(nodeRef)); if (!node->getFrozen()) { node->set_child_relaxed(pe.getIdx(), childRef); @@ -1267,8 +1225,7 @@ thaw(BTreeNode::Ref rootRef) } -template +template template BTreeNode::Ref BTreeIterator:: @@ -1295,16 +1252,14 @@ insertFirst(const KeyType &key, const DataType &data, } -template +template bool BTreeIterator:: -setLeafNodeIdx(uint32_t idx, const LeafNodeType *splitLeafNode) +setLeafNodeIdx(uint32_t idx, const LeafNodeType *splitLeafNode) noexcept { uint32_t leafSlots = _leaf.getNode()->validSlots(); if (idx >= leafSlots) { - _leaf.setNodeAndIdx(splitLeafNode, - idx - leafSlots); + _leaf.setNodeAndIdx(splitLeafNode, idx - leafSlots); if (_pathSize == 0) { _leafRoot = splitLeafNode; } @@ -1316,8 +1271,7 @@ setLeafNodeIdx(uint32_t idx, const LeafNodeType *splitLeafNode) } -template +template template BTreeNode::Ref BTreeIterator:: @@ -1349,8 +1303,7 @@ addLevel(BTreeNode::Ref rootRef, BTreeNode::Ref splitNodeRef, } -template +template BTreeNode::Ref BTreeIterator:: removeLevel(BTreeNode::Ref rootRef, InternalNodeType *rootNode) @@ -1367,8 +1320,7 @@ removeLevel(BTreeNode::Ref rootRef, InternalNodeType *rootNode) } -template +template void BTreeIterator:: removeLast(BTreeNode::Ref rootRef) -- cgit v1.2.3 From 1205b1e49be43416e4bf27df141db1983075a7ed Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Thu, 25 Apr 2024 14:44:04 +0000 Subject: Use std::vector --- searchlib/src/vespa/searchlib/grouping/collect.cpp | 11 ++++------- searchlib/src/vespa/searchlib/grouping/collect.h | 18 +++++++++--------- vespalib/src/vespa/vespalib/data/memorydatastore.h | 1 - vespalib/src/vespa/vespalib/objects/nbostream.h | 8 ++------ vespalib/src/vespa/vespalib/util/rcuvector.h | 2 +- 5 files changed, 16 insertions(+), 24 deletions(-) (limited to 'vespalib') diff --git a/searchlib/src/vespa/searchlib/grouping/collect.cpp b/searchlib/src/vespa/searchlib/grouping/collect.cpp index d0a9a38bf7d..464362602f2 100644 --- a/searchlib/src/vespa/searchlib/grouping/collect.cpp +++ b/searchlib/src/vespa/searchlib/grouping/collect.cpp @@ -1,7 +1,6 @@ // Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "collect.h" -#include #include using namespace search::expression; @@ -48,8 +47,7 @@ Collect::~Collect() assert((_aggrBacking.size() % _aggregatorSize) == 0); for (size_t i(0), m(_aggrBacking.size()/_aggregatorSize); i < m; i++) { uint8_t * base(&_aggrBacking[ i * _aggregatorSize]); - for (size_t j(0), k(_aggregator.size()); j < k; j++) { - ResultAccessor & r = _aggregator[j]; + for (auto & r : _aggregator) { r.destroy(base); } } @@ -74,8 +72,8 @@ void Collect::collect(GroupRef gr, uint32_t docId, double rank) { uint8_t * base(&_aggrBacking[getAggrBase(gr)]); - for (size_t i(0), m(_aggregator.size()); i < m; i++) { - _aggregator[i].aggregate(base, docId, rank); + for (auto & i : _aggregator) { + i.aggregate(base, docId, rank); } } @@ -86,8 +84,7 @@ Collect::createCollectors(GroupRef gr) if (offset == _aggrBacking.size()) { _aggrBacking.resize(getAggrBase(GroupRef(gr.getRef() + 1))); uint8_t * base(&_aggrBacking[offset]); - for (size_t i(0), m(_aggregator.size()); i < m; i++) { - ResultAccessor & r = _aggregator[i]; + for (auto & r : _aggregator) { r.create(base); } } diff --git a/searchlib/src/vespa/searchlib/grouping/collect.h b/searchlib/src/vespa/searchlib/grouping/collect.h index 3566d21f821..932cf559156 100644 --- a/searchlib/src/vespa/searchlib/grouping/collect.h +++ b/searchlib/src/vespa/searchlib/grouping/collect.h @@ -13,7 +13,7 @@ public: Collect(const Collect &) = delete; Collect & operator = (const Collect &) = delete; protected: - Collect(const aggregation::Group & protoType); + explicit Collect(const aggregation::Group & protoType); ~Collect(); void preFill(GroupRef gr, const aggregation::Group & r); void createCollectors(GroupRef gr); @@ -55,9 +55,9 @@ private: */ class ResultAccessor { public: - ResultAccessor() : _bluePrint(NULL), _aggregator(NULL), _offset(0) { } + ResultAccessor() noexcept : _bluePrint(nullptr), _aggregator(nullptr), _offset(0) { } ResultAccessor(const aggregation::AggregationResult & aggregator, size_t offset); - void setResult(const expression::ResultNode & result, uint8_t * base) { + void setResult(const expression::ResultNode & result, uint8_t * base) const { result.encode(base+_offset); } const expression::ResultNode & getResult(expression::ResultNode & result, const uint8_t * base) const { @@ -86,8 +86,8 @@ private: mutable vespalib::IdentifiablePtr _aggregator; uint32_t _offset; }; - using AggregatorBacking = vespalib::Array; - using ResultAccessorList = vespalib::Array; + using AggregatorBacking = std::vector; + using ResultAccessorList = std::vector; class SortInfo { public: SortInfo() noexcept : _index(0), _sign(1) { } @@ -98,10 +98,10 @@ private: uint8_t _index; // Which index in the aggragators should be used for sorting this level. int8_t _sign; // And which way. positive number -> ascending, negative number descending. }; - size_t _aggregatorSize; // This is the bytesize required to store the aggrgate values per bucket. - ResultAccessorList _aggregator; // These are the accessors to use when accessing the results. - AggregatorBacking _aggrBacking; // This is the storage for the accessors. - std::vector _sortInfo; // Generated cheap sortInfo, to avoid accessing more complicated data. + size_t _aggregatorSize; // This is the bytesize required to store the aggrgate values per bucket. + ResultAccessorList _aggregator; // These are the accessors to use when accessing the results. + AggregatorBacking _aggrBacking; // This is the storage for the accessors. + std::vector _sortInfo; // Generated cheap sortInfo, to avoid accessing more complicated data. }; } diff --git a/vespalib/src/vespa/vespalib/data/memorydatastore.h b/vespalib/src/vespa/vespalib/data/memorydatastore.h index 0bf2becf7c3..3682e3629e3 100644 --- a/vespalib/src/vespa/vespalib/data/memorydatastore.h +++ b/vespalib/src/vespa/vespalib/data/memorydatastore.h @@ -2,7 +2,6 @@ #pragma once #include -#include #include #include diff --git a/vespalib/src/vespa/vespalib/objects/nbostream.h b/vespalib/src/vespa/vespalib/objects/nbostream.h index ab02e7c1f05..f66c261ae91 100644 --- a/vespalib/src/vespa/vespalib/objects/nbostream.h +++ b/vespalib/src/vespa/vespalib/objects/nbostream.h @@ -107,17 +107,13 @@ public: } template - nbostream & - operator<<(const std::pair &val) - { + nbostream & operator<<(const std::pair &val) { *this << val.first << val.second; return *this; } template - nbostream & - operator>>(std::pair &val) - { + nbostream & operator>>(std::pair &val) { *this >> val.first >> val.second; return *this; } diff --git a/vespalib/src/vespa/vespalib/util/rcuvector.h b/vespalib/src/vespa/vespalib/util/rcuvector.h index dcd3fcd8052..787fb2d00c6 100644 --- a/vespalib/src/vespa/vespalib/util/rcuvector.h +++ b/vespalib/src/vespa/vespalib/util/rcuvector.h @@ -19,7 +19,7 @@ class RcuVectorHeld : public GenerationHeldBase public: RcuVectorHeld(size_t size, T&& data); - ~RcuVectorHeld(); + ~RcuVectorHeld() override; }; -- cgit v1.2.3