From 006f5d16fd9e5a4010c0b1068a7b96fa35136a8c Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Wed, 26 Jul 2023 03:33:15 +0000 Subject: - Pack data closer to let config fit in 2 cache lines instead of 4. - Avoid plt indirection and allow more inlining of frequently called code. - Reapplication of #27646 --- eval/src/vespa/eval/eval/value_type.h | 20 ++--- .../compaction/attribute_compaction_test.cpp | 2 +- .../docstore/logdatastore/logdatastore_test.cpp | 2 +- .../src/vespa/searchcommon/attribute/basictype.h | 38 ++++----- .../vespa/searchcommon/attribute/collectiontype.h | 54 ++++++------ .../src/vespa/searchcommon/attribute/config.cpp | 6 +- .../src/vespa/searchcommon/attribute/config.h | 42 +++++----- .../vespa/searchcommon/attribute/distance_metric.h | 4 +- .../attribute/persistent_predicate_params.h | 25 +++--- .../searchcommon/attribute/predicate_params.h | 13 ++- .../vespa/searchcommon/common/dictionary_config.h | 9 +- .../src/vespa/searchcommon/common/growstrategy.h | 8 +- .../vespa/searchlib/attribute/attributevector.cpp | 2 + .../vespa/searchlib/attribute/attributevector.h | 4 +- .../searchlib/attribute/string_search_helper.cpp | 2 +- .../searchlib/attribute/string_search_helper.h | 2 +- searchlib/src/vespa/searchlib/fef/properties.cpp | 22 ++--- searchlib/src/vespa/searchlib/fef/properties.h | 42 +++++----- .../src/vespa/searchlib/queryeval/blueprint.cpp | 26 ++---- .../src/vespa/searchlib/queryeval/blueprint.h | 96 ++++++++++++---------- .../src/vespa/searchlib/queryeval/field_spec.cpp | 6 +- .../src/vespa/searchlib/queryeval/field_spec.h | 38 ++++----- .../vespalib/datastore/compaction_strategy.cpp | 8 +- .../vespa/vespalib/datastore/compaction_strategy.h | 53 ++++++------ vespalib/src/vespa/vespalib/text/lowercase.h | 4 +- vespalib/src/vespa/vespalib/text/utf8.cpp | 39 ++++----- vespalib/src/vespa/vespalib/text/utf8.h | 47 ++++++----- vespalib/src/vespa/vespalib/util/alloc.cpp | 4 +- vespalib/src/vespa/vespalib/util/alloc.h | 7 +- vespalib/src/vespa/vespalib/util/growstrategy.h | 9 +- .../vespa/vespalib/util/mmap_file_allocator.cpp | 2 +- vespalib/src/vespa/vespalib/util/small_vector.h | 2 +- 32 files changed, 308 insertions(+), 330 deletions(-) diff --git a/eval/src/vespa/eval/eval/value_type.h b/eval/src/vespa/eval/eval/value_type.h index 49f88edb2f9..5c0d9e3317d 100644 --- a/eval/src/vespa/eval/eval/value_type.h +++ b/eval/src/vespa/eval/eval/value_type.h @@ -25,13 +25,13 @@ public: : name(name_in), size(npos) {} Dimension(const vespalib::string &name_in, size_type size_in) noexcept : name(name_in), size(size_in) {} - bool operator==(const Dimension &rhs) const { + bool operator==(const Dimension &rhs) const noexcept { return ((name == rhs.name) && (size == rhs.size)); } - bool operator!=(const Dimension &rhs) const { return !(*this == rhs); } - bool is_mapped() const { return (size == npos); } - bool is_indexed() const { return (size != npos); } - bool is_trivial() const { return (size == 1); } + bool operator!=(const Dimension &rhs) const noexcept { return !(*this == rhs); } + bool is_mapped() const noexcept { return (size == npos); } + bool is_indexed() const noexcept { return (size != npos); } + bool is_trivial() const noexcept { return (size == 1); } }; private: @@ -39,10 +39,10 @@ private: CellType _cell_type; std::vector _dimensions; - ValueType() + ValueType() noexcept : _error(true), _cell_type(CellType::DOUBLE), _dimensions() {} - ValueType(CellType cell_type_in, std::vector &&dimensions_in) + ValueType(CellType cell_type_in, std::vector &&dimensions_in) noexcept : _error(false), _cell_type(cell_type_in), _dimensions(std::move(dimensions_in)) {} static ValueType error_if(bool has_error, ValueType else_type); @@ -57,7 +57,7 @@ public: CellMeta cell_meta() const { return {_cell_type, is_double()}; } bool is_error() const { return _error; } bool is_double() const; - bool has_dimensions() const { return !_dimensions.empty(); } + bool has_dimensions() const noexcept { return !_dimensions.empty(); } bool is_sparse() const; bool is_dense() const; bool is_mixed() const; @@ -70,12 +70,12 @@ public: std::vector mapped_dimensions() const; size_t dimension_index(const vespalib::string &name) const; std::vector dimension_names() const; - bool operator==(const ValueType &rhs) const { + bool operator==(const ValueType &rhs) const noexcept { return ((_error == rhs._error) && (_cell_type == rhs._cell_type) && (_dimensions == rhs._dimensions)); } - bool operator!=(const ValueType &rhs) const { return !(*this == rhs); } + bool operator!=(const ValueType &rhs) const noexcept { return !(*this == rhs); } ValueType map() const; ValueType reduce(const std::vector &dimensions_in) const; diff --git a/searchlib/src/tests/attribute/compaction/attribute_compaction_test.cpp b/searchlib/src/tests/attribute/compaction/attribute_compaction_test.cpp index c5d70109015..79ef6e42bb2 100644 --- a/searchlib/src/tests/attribute/compaction/attribute_compaction_test.cpp +++ b/searchlib/src/tests/attribute/compaction/attribute_compaction_test.cpp @@ -123,7 +123,7 @@ void hammerAttribute(AttributePtr &v, DocIdRange range, uint32_t count) Config compactAddressSpaceAttributeConfig(bool enableAddressSpaceCompact) { Config cfg(BasicType::INT8, CollectionType::ARRAY); - cfg.setCompactionStrategy({ 1.0, (enableAddressSpaceCompact ? 0.2 : 1.0) }); + cfg.setCompactionStrategy({ 1.0f, (enableAddressSpaceCompact ? 0.2f : 1.0f) }); return cfg; } diff --git a/searchlib/src/tests/docstore/logdatastore/logdatastore_test.cpp b/searchlib/src/tests/docstore/logdatastore/logdatastore_test.cpp index 3b023ed3bc8..c76f73e7477 100644 --- a/searchlib/src/tests/docstore/logdatastore/logdatastore_test.cpp +++ b/searchlib/src/tests/docstore/logdatastore/logdatastore_test.cpp @@ -1005,7 +1005,7 @@ TEST_F("require that lid space can be increased after being compacted and then s TEST_F("require that there is control of static memory usage", Fixture) { vespalib::MemoryUsage usage = f.store.getMemoryUsage(); - EXPECT_EQUAL(536u + sizeof(LogDataStore::NameIdSet) + sizeof(std::mutex), sizeof(LogDataStore)); + EXPECT_EQUAL(520u + sizeof(LogDataStore::NameIdSet) + sizeof(std::mutex), sizeof(LogDataStore)); EXPECT_EQUAL(74108u, usage.allocatedBytes()); EXPECT_EQUAL(384u, usage.usedBytes()); } diff --git a/searchlib/src/vespa/searchcommon/attribute/basictype.h b/searchlib/src/vespa/searchcommon/attribute/basictype.h index 46387dd2738..407348fea92 100644 --- a/searchlib/src/vespa/searchcommon/attribute/basictype.h +++ b/searchlib/src/vespa/searchcommon/attribute/basictype.h @@ -9,7 +9,7 @@ namespace search::attribute { class BasicType { public: - enum Type { + enum Type : uint8_t { NONE = 0, STRING = 1, BOOL = 2, @@ -28,33 +28,33 @@ class BasicType MAX_TYPE }; - explicit BasicType(int t) : _type(Type(t)) { } - explicit BasicType(unsigned int t) : _type(Type(t)) { } - BasicType(Type t) : _type(t) { } + explicit BasicType(int t) noexcept : _type(Type(t)) { } + explicit BasicType(unsigned int t) noexcept : _type(Type(t)) { } + BasicType(Type t) noexcept : _type(t) { } explicit BasicType(const vespalib::string & t) : _type(asType(t)) { } - Type type() const { return _type; } - const char * asString() const { return asString(_type); } - size_t fixedSize() const { return fixedSize(_type); } - static BasicType fromType(bool) { return BOOL; } - static BasicType fromType(int8_t) { return INT8; } - static BasicType fromType(int16_t) { return INT16; } - static BasicType fromType(int32_t) { return INT32; } - static BasicType fromType(int64_t) { return INT64; } - static BasicType fromType(float) { return FLOAT; } - static BasicType fromType(double) { return DOUBLE; } - bool operator==(const BasicType &b) const { return _type == b._type; } - bool operator!=(const BasicType &b) const { return _type != b._type; } + Type type() const noexcept { return _type; } + const char * asString() const noexcept { return asString(_type); } + size_t fixedSize() const noexcept { return fixedSize(_type); } + static BasicType fromType(bool) noexcept { return BOOL; } + static BasicType fromType(int8_t) noexcept { return INT8; } + static BasicType fromType(int16_t) noexcept { return INT16; } + static BasicType fromType(int32_t) noexcept { return INT32; } + static BasicType fromType(int64_t) noexcept { return INT64; } + static BasicType fromType(float) noexcept { return FLOAT; } + static BasicType fromType(double) noexcept { return DOUBLE; } + bool operator==(const BasicType &b) const noexcept { return _type == b._type; } + bool operator!=(const BasicType &b) const noexcept { return _type != b._type; } private: - static const char * asString(Type t) { return _typeTable[t]._name; } - static size_t fixedSize(Type t) { return _typeTable[t]._fixedSize; } + static const char * asString(Type t) noexcept { return _typeTable[t]._name; } + static size_t fixedSize(Type t) noexcept { return _typeTable[t]._fixedSize; } static Type asType(const vespalib::string & t); Type _type; struct TypeInfo { - Type _type; + Type _type; unsigned int _fixedSize; const char * _name; }; diff --git a/searchlib/src/vespa/searchcommon/attribute/collectiontype.h b/searchlib/src/vespa/searchcommon/attribute/collectiontype.h index 35cb7612ed0..05fad8cbc64 100644 --- a/searchlib/src/vespa/searchcommon/attribute/collectiontype.h +++ b/searchlib/src/vespa/searchcommon/attribute/collectiontype.h @@ -9,7 +9,7 @@ namespace search::attribute { class CollectionType { public: - enum Type { + enum Type : uint8_t { /** * Single value type with one value stored for each document. **/ @@ -26,32 +26,30 @@ class CollectionType MAX_TYPE }; - CollectionType(Type t = SINGLE, bool remove = false, bool create = false) : - _type(t), - _removeIfZero(remove), - _createIfNonExistant(create) - { - } + CollectionType(Type t = SINGLE, bool remove = false, bool create = false) noexcept + : _type(t), + _removeIfZero(remove), + _createIfNonExistant(create) + { } explicit - CollectionType(const vespalib::string & t, bool remove = false, bool create = false) : - _type(asType(t)), - _removeIfZero(remove), - _createIfNonExistant(create) - { - } + CollectionType(const vespalib::string & t, bool remove = false, bool create = false) + : _type(asType(t)), + _removeIfZero(remove), + _createIfNonExistant(create) + { } - Type type() const { return _type; } - bool isMultiValue() const { return _type != SINGLE; } - bool isWeightedSet() const { return _type == WSET; } - bool isArray() const { return _type == ARRAY; } - bool removeIfZero() const { return _removeIfZero; } - bool createIfNonExistant() const { return _createIfNonExistant; } - const char * asString() const { return asString(_type); } - void removeIfZero(bool newValue) { _removeIfZero = newValue; } - void createIfNonExistant(bool newValue) { _createIfNonExistant = newValue; } - bool operator!=(const CollectionType &b) const { return !(operator==(b)); } - bool operator==(const CollectionType &b) const { + Type type() const noexcept { return _type; } + bool isMultiValue() const noexcept { return _type != SINGLE; } + bool isWeightedSet() const noexcept { return _type == WSET; } + bool isArray() const noexcept { return _type == ARRAY; } + bool removeIfZero() const noexcept { return _removeIfZero; } + bool createIfNonExistant() const noexcept { return _createIfNonExistant; } + const char * asString() const noexcept { return asString(_type); } + void removeIfZero(bool newValue) noexcept { _removeIfZero = newValue; } + void createIfNonExistant(bool newValue) noexcept { _createIfNonExistant = newValue; } + bool operator!=(const CollectionType &b) const noexcept { return !(operator==(b)); } + bool operator==(const CollectionType &b) const noexcept { return _type == b._type && _removeIfZero == b._removeIfZero && _createIfNonExistant == b._createIfNonExistant; @@ -63,12 +61,12 @@ class CollectionType const char * _name; }; - static const char * asString(Type t) { return _typeTable[t]._name; } + static const char * asString(Type t) noexcept { return _typeTable[t]._name; } static Type asType(const vespalib::string &t); - Type _type; - bool _removeIfZero; - bool _createIfNonExistant; + Type _type : 4; + bool _removeIfZero : 1; + bool _createIfNonExistant : 1; static const TypeInfo _typeTable[MAX_TYPE]; }; diff --git a/searchlib/src/vespa/searchcommon/attribute/config.cpp b/searchlib/src/vespa/searchcommon/attribute/config.cpp index af29bd64ad6..7c302a10731 100644 --- a/searchlib/src/vespa/searchcommon/attribute/config.cpp +++ b/searchlib/src/vespa/searchcommon/attribute/config.cpp @@ -23,14 +23,14 @@ Config::Config(BasicType bt, CollectionType ct, bool fastSearch_) noexcept _fastAccess(false), _mutable(false), _paged(false), - _maxUnCommittedMemory(MAX_UNCOMMITTED_MEMORY), + _distance_metric(DistanceMetric::Euclidean), _match(Match::UNCASED), _dictionary(), + _maxUnCommittedMemory(MAX_UNCOMMITTED_MEMORY), _growStrategy(), _compactionStrategy(), _predicateParams(), _tensorType(vespalib::eval::ValueType::error_type()), - _distance_metric(DistanceMetric::Euclidean), _hnsw_index_params() { } @@ -42,7 +42,7 @@ Config & Config::operator = (Config &&) noexcept = default; Config::~Config() = default; bool -Config::operator==(const Config &b) const +Config::operator==(const Config &b) const noexcept { return _basicType == b._basicType && _type == b._type && diff --git a/searchlib/src/vespa/searchcommon/attribute/config.h b/searchlib/src/vespa/searchcommon/attribute/config.h index b368885240c..17c762267cc 100644 --- a/searchlib/src/vespa/searchcommon/attribute/config.h +++ b/searchlib/src/vespa/searchcommon/attribute/config.h @@ -21,7 +21,7 @@ namespace search::attribute { */ class Config { public: - enum class Match { CASED, UNCASED }; + enum class Match : uint8_t { CASED, UNCASED }; using CompactionStrategy = vespalib::datastore::CompactionStrategy; Config() noexcept; Config(BasicType bt) noexcept : Config(bt, CollectionType::SINGLE) { } @@ -33,27 +33,27 @@ public: Config & operator = (Config &&) noexcept; ~Config(); - BasicType basicType() const { return _basicType; } - CollectionType collectionType() const { return _type; } - bool fastSearch() const { return _fastSearch; } - bool paged() const { return _paged; } - const PredicateParams &predicateParams() const { return _predicateParams; } - const vespalib::eval::ValueType & tensorType() const { return _tensorType; } - DistanceMetric distance_metric() const { return _distance_metric; } + BasicType basicType() const noexcept { return _basicType; } + CollectionType collectionType() const noexcept { return _type; } + bool fastSearch() const noexcept { return _fastSearch; } + bool paged() const noexcept { return _paged; } + const PredicateParams &predicateParams() const noexcept { return _predicateParams; } + const vespalib::eval::ValueType & tensorType() const noexcept { return _tensorType; } + DistanceMetric distance_metric() const noexcept { return _distance_metric; } const std::optional& hnsw_index_params() const { return _hnsw_index_params; } /** * Check if attribute posting list can consist of only a bitvector with * no corresponding btree. */ - bool getIsFilter() const { return _isFilter; } - bool isMutable() const { return _mutable; } + bool getIsFilter() const noexcept { return _isFilter; } + bool isMutable() const noexcept { return _mutable; } /** * Check if this attribute should be fast accessible at all times. * If so, attribute is kept in memory also for non-searchable documents. */ - bool fastAccess() const { return _fastAccess; } + bool fastAccess() const noexcept { return _fastAccess; } const GrowStrategy & getGrowStrategy() const { return _growStrategy; } const CompactionStrategy &getCompactionStrategy() const { return _compactionStrategy; } @@ -92,28 +92,28 @@ public: } Config & set_dictionary_config(const DictionaryConfig & cfg) { _dictionary = cfg; return *this; } Config & set_match(Match match) { _match = match; return *this; } - bool operator!=(const Config &b) const { return !(operator==(b)); } - bool operator==(const Config &b) const; + bool operator!=(const Config &b) const noexcept { return !(operator==(b)); } + bool operator==(const Config &b) const noexcept ; - uint64_t getMaxUnCommittedMemory() const { return _maxUnCommittedMemory; } + uint64_t getMaxUnCommittedMemory() const noexcept { return _maxUnCommittedMemory; } Config & setMaxUnCommittedMemory(uint64_t value) { _maxUnCommittedMemory = value; return *this; } private: BasicType _basicType; CollectionType _type; - bool _fastSearch; - bool _isFilter; - bool _fastAccess; - bool _mutable; - bool _paged; - uint64_t _maxUnCommittedMemory; + bool _fastSearch : 1; + bool _isFilter : 1; + bool _fastAccess : 1; + bool _mutable : 1; + bool _paged : 1; + DistanceMetric _distance_metric; Match _match; DictionaryConfig _dictionary; + uint64_t _maxUnCommittedMemory; GrowStrategy _growStrategy; CompactionStrategy _compactionStrategy; PredicateParams _predicateParams; vespalib::eval::ValueType _tensorType; - DistanceMetric _distance_metric; std::optional _hnsw_index_params; }; diff --git a/searchlib/src/vespa/searchcommon/attribute/distance_metric.h b/searchlib/src/vespa/searchcommon/attribute/distance_metric.h index 9f9f45810b9..35f5fb4fe6b 100644 --- a/searchlib/src/vespa/searchcommon/attribute/distance_metric.h +++ b/searchlib/src/vespa/searchcommon/attribute/distance_metric.h @@ -2,8 +2,10 @@ #pragma once +#include + namespace search::attribute { -enum class DistanceMetric { Euclidean, Angular, GeoDegrees, InnerProduct, Hamming, PrenormalizedAngular, Dotproduct }; +enum DistanceMetric : uint8_t { Euclidean, Angular, GeoDegrees, InnerProduct, Hamming, PrenormalizedAngular, Dotproduct }; } diff --git a/searchlib/src/vespa/searchcommon/attribute/persistent_predicate_params.h b/searchlib/src/vespa/searchcommon/attribute/persistent_predicate_params.h index d81eb9c5d3c..205a75c188f 100644 --- a/searchlib/src/vespa/searchcommon/attribute/persistent_predicate_params.h +++ b/searchlib/src/vespa/searchcommon/attribute/persistent_predicate_params.h @@ -10,24 +10,23 @@ namespace search::attribute { * Persistent parameters for predicate attributes. */ class PersistentPredicateParams { - uint32_t _arity; int64_t _lower_bound; int64_t _upper_bound; + uint32_t _arity; public: - PersistentPredicateParams() - : _arity(8), - _lower_bound(std::numeric_limits::min()), - _upper_bound(std::numeric_limits::max()) - { - } - uint32_t arity() const { return _arity; } - int64_t lower_bound() const { return _lower_bound; } - int64_t upper_bound() const { return _upper_bound; } - void setArity(uint32_t v) { _arity = v; } - void setBounds(int64_t lower, int64_t upper) { _lower_bound = lower; _upper_bound = upper; } + PersistentPredicateParams() noexcept + : _lower_bound(std::numeric_limits::min()), + _upper_bound(std::numeric_limits::max()), + _arity(8) + { } + uint32_t arity() const noexcept { return _arity; } + int64_t lower_bound() const noexcept { return _lower_bound; } + int64_t upper_bound() const noexcept { return _upper_bound; } + void setArity(uint32_t v) noexcept { _arity = v; } + void setBounds(int64_t lower, int64_t upper) noexcept { _lower_bound = lower; _upper_bound = upper; } - bool operator==(const PersistentPredicateParams &rhs) const { + bool operator==(const PersistentPredicateParams &rhs) const noexcept { return ((_arity == rhs._arity) && (_lower_bound == rhs._lower_bound) && (_upper_bound == rhs._upper_bound)); diff --git a/searchlib/src/vespa/searchcommon/attribute/predicate_params.h b/searchlib/src/vespa/searchcommon/attribute/predicate_params.h index 133b7331689..7e9258ab5db 100644 --- a/searchlib/src/vespa/searchcommon/attribute/predicate_params.h +++ b/searchlib/src/vespa/searchcommon/attribute/predicate_params.h @@ -11,17 +11,16 @@ namespace search::attribute { */ class PredicateParams : public PersistentPredicateParams { - double _dense_posting_list_threshold; + float _dense_posting_list_threshold; public: - PredicateParams() + PredicateParams() noexcept : PersistentPredicateParams(), _dense_posting_list_threshold(0.4) - { - } + { } - double dense_posting_list_threshold() const { return _dense_posting_list_threshold; } - void setDensePostingListThreshold(double v) { _dense_posting_list_threshold = v; } - bool operator==(const PredicateParams &rhs) const { + float dense_posting_list_threshold() const noexcept { return _dense_posting_list_threshold; } + void setDensePostingListThreshold(float v) noexcept { _dense_posting_list_threshold = v; } + bool operator==(const PredicateParams &rhs) const noexcept { return (PersistentPredicateParams::operator==(rhs) && (_dense_posting_list_threshold == rhs._dense_posting_list_threshold)); } diff --git a/searchlib/src/vespa/searchcommon/common/dictionary_config.h b/searchlib/src/vespa/searchcommon/common/dictionary_config.h index f51341ad799..f504439c5a3 100644 --- a/searchlib/src/vespa/searchcommon/common/dictionary_config.h +++ b/searchlib/src/vespa/searchcommon/common/dictionary_config.h @@ -3,6 +3,7 @@ #pragma once #include +#include namespace search { @@ -11,8 +12,8 @@ namespace search { */ class DictionaryConfig { public: - enum class Type { BTREE, HASH, BTREE_AND_HASH }; - enum class Match { CASED, UNCASED }; + enum class Type : uint8_t { BTREE, HASH, BTREE_AND_HASH }; + enum class Match : uint8_t { CASED, UNCASED }; DictionaryConfig() noexcept : _type(Type::BTREE), _match(Match::UNCASED) {} DictionaryConfig(Type type) noexcept : _type(type), _match(Match::UNCASED) {} DictionaryConfig(Type type, Match match) noexcept : _type(type), _match(match) {} @@ -20,8 +21,8 @@ public: Match getMatch() const { return _match; } bool operator == (const DictionaryConfig & b) const { return (_type == b._type) && (_match == b._match); } private: - Type _type; - Match _match; + Type _type : 4; + Match _match : 4; }; std::ostream& operator<<(std::ostream& os, const DictionaryConfig & cfg); diff --git a/searchlib/src/vespa/searchcommon/common/growstrategy.h b/searchlib/src/vespa/searchcommon/common/growstrategy.h index 8766989ded0..86750eafbfc 100644 --- a/searchlib/src/vespa/searchcommon/common/growstrategy.h +++ b/searchlib/src/vespa/searchcommon/common/growstrategy.h @@ -23,17 +23,17 @@ public: { } - static GrowStrategy make(uint32_t docsInitialCapacity, float docsGrowFactor, uint32_t docsGrowDelta) { + static GrowStrategy make(uint32_t docsInitialCapacity, float docsGrowFactor, uint32_t docsGrowDelta) noexcept { return {docsInitialCapacity, docsGrowFactor, docsGrowDelta, 0, 0.2}; } - float getMultiValueAllocGrowFactor() const { return _multiValueAllocGrowFactor; } + float getMultiValueAllocGrowFactor() const noexcept { return _multiValueAllocGrowFactor; } - bool operator==(const GrowStrategy & rhs) const { + bool operator==(const GrowStrategy & rhs) const noexcept { return vespalib::GrowStrategy::operator==(rhs) && (_multiValueAllocGrowFactor == rhs._multiValueAllocGrowFactor); } - bool operator!=(const GrowStrategy & rhs) const { + bool operator!=(const GrowStrategy & rhs) const noexcept { return !(operator==(rhs)); } }; diff --git a/searchlib/src/vespa/searchlib/attribute/attributevector.cpp b/searchlib/src/vespa/searchlib/attribute/attributevector.cpp index 859c607e9cb..3d5f2ec09fd 100644 --- a/searchlib/src/vespa/searchlib/attribute/attributevector.cpp +++ b/searchlib/src/vespa/searchlib/attribute/attributevector.cpp @@ -128,6 +128,8 @@ bool AttributeVector::hasArrayType() const { return _config->collectionType().is bool AttributeVector::getIsFilter() const { return _config->getIsFilter(); } bool AttributeVector::getIsFastSearch() const { return _config->fastSearch(); } bool AttributeVector::isMutable() const { return _config->isMutable(); } +attribute::BasicType::Type AttributeVector::getBasicType() const { return _config->basicType().type(); } +attribute::CollectionType::Type AttributeVector::getCollectionType() const { return _config->collectionType().type(); } bool AttributeVector::isEnumerated(const vespalib::GenericHeader &header) diff --git a/searchlib/src/vespa/searchlib/attribute/attributevector.h b/searchlib/src/vespa/searchlib/attribute/attributevector.h index 5fd6cb915fa..68dfe52643f 100644 --- a/searchlib/src/vespa/searchlib/attribute/attributevector.h +++ b/searchlib/src/vespa/searchlib/attribute/attributevector.h @@ -319,8 +319,8 @@ public: AddressSpaceUsage getAddressSpaceUsage() const; - BasicType::Type getBasicType() const override final { return getInternalBasicType().type(); } - CollectionType::Type getCollectionType() const override final { return getInternalCollectionType().type(); } + BasicType::Type getBasicType() const override final; + CollectionType::Type getCollectionType() const override final; uint32_t getCommittedDocIdLimit() const override final { return _committedDocIdLimit.load(std::memory_order_acquire); } bool isImported() const override; diff --git a/searchlib/src/vespa/searchlib/attribute/string_search_helper.cpp b/searchlib/src/vespa/searchlib/attribute/string_search_helper.cpp index 17a0e6256d4..6e56f5477c2 100644 --- a/searchlib/src/vespa/searchlib/attribute/string_search_helper.cpp +++ b/searchlib/src/vespa/searchlib/attribute/string_search_helper.cpp @@ -41,7 +41,7 @@ StringSearchHelper::StringSearchHelper(StringSearchHelper&&) noexcept = default; StringSearchHelper::~StringSearchHelper() = default; bool -StringSearchHelper::isMatch(const char *src) const { +StringSearchHelper::isMatch(const char *src) const noexcept { if (__builtin_expect(isRegex(), false)) { return getRegex().valid() && getRegex().partial_match(std::string_view(src)); } diff --git a/searchlib/src/vespa/searchlib/attribute/string_search_helper.h b/searchlib/src/vespa/searchlib/attribute/string_search_helper.h index ee68053122f..b0ce5dff2e0 100644 --- a/searchlib/src/vespa/searchlib/attribute/string_search_helper.h +++ b/searchlib/src/vespa/searchlib/attribute/string_search_helper.h @@ -21,7 +21,7 @@ public: StringSearchHelper(const StringSearchHelper &) = delete; StringSearchHelper & operator =(const StringSearchHelper &) = delete; ~StringSearchHelper(); - bool isMatch(const char *src) const; + bool isMatch(const char *src) const noexcept; bool isPrefix() const noexcept { return _isPrefix; } bool isRegex() const noexcept { return _isRegex; } bool isCased() const noexcept { return _isCased; } diff --git a/searchlib/src/vespa/searchlib/fef/properties.cpp b/searchlib/src/vespa/searchlib/fef/properties.cpp index 6f334630dc5..2cc4e50b593 100644 --- a/searchlib/src/vespa/searchlib/fef/properties.cpp +++ b/searchlib/src/vespa/searchlib/fef/properties.cpp @@ -11,7 +11,7 @@ const Property::Value Property::_emptyValue; const Property::Values Property::_emptyValues; const Property::Value & -Property::getAt(uint32_t idx) const +Property::getAt(uint32_t idx) const noexcept { if (idx < (*_values).size()) { return (*_values)[idx]; @@ -22,7 +22,7 @@ Property::getAt(uint32_t idx) const //----------------------------------------------------------------------------- uint32_t -Properties::rawHash(const void *buf, uint32_t len) +Properties::rawHash(const void *buf, uint32_t len) noexcept { uint32_t res = 0; unsigned const char *pt = (unsigned const char *) buf; @@ -33,7 +33,7 @@ Properties::rawHash(const void *buf, uint32_t len) return res; } -Properties::Properties() +Properties::Properties() noexcept : _numValues(0), _data() { @@ -59,7 +59,7 @@ Properties::add(vespalib::stringref key, vespalib::stringref value) } uint32_t -Properties::count(vespalib::stringref key) const +Properties::count(vespalib::stringref key) const noexcept { if (!key.empty()) { auto node = _data.find(key); @@ -112,14 +112,14 @@ Properties::clear() } bool -Properties::operator==(const Properties &rhs) const +Properties::operator==(const Properties &rhs) const noexcept { return (_numValues == rhs._numValues && _data == rhs._data); } uint32_t -Properties::hashCode() const +Properties::hashCode() const noexcept { uint32_t hash = numKeys() + numValues(); for (const auto& elem : _data) { @@ -159,7 +159,7 @@ Properties::visitNamespace(vespalib::stringref ns, } Property -Properties::lookup(vespalib::stringref key) const +Properties::lookup(vespalib::stringref key) const noexcept { if (key.empty()) { return Property(); @@ -172,7 +172,7 @@ Properties::lookup(vespalib::stringref key) const } Property Properties::lookup(vespalib::stringref namespace1, - vespalib::stringref key) const + vespalib::stringref key) const noexcept { if (namespace1.empty() || key.empty()) { return Property(); @@ -184,7 +184,7 @@ Property Properties::lookup(vespalib::stringref namespace1, Property Properties::lookup(vespalib::stringref namespace1, vespalib::stringref namespace2, - vespalib::stringref key) const + vespalib::stringref key) const noexcept { if (namespace1.empty() || namespace2.empty() || key.empty()) { return Property(); @@ -197,7 +197,7 @@ Property Properties::lookup(vespalib::stringref namespace1, Property Properties::lookup(vespalib::stringref namespace1, vespalib::stringref namespace2, vespalib::stringref namespace3, - vespalib::stringref key) const + vespalib::stringref key) const noexcept { if (namespace1.empty() || namespace2.empty() || namespace3.empty() || key.empty()) { return Property(); @@ -207,7 +207,7 @@ Property Properties::lookup(vespalib::stringref namespace1, return lookup(fullKey); } -void Properties::swap(Properties & rhs) +void Properties::swap(Properties & rhs) noexcept { _data.swap(rhs._data); std::swap(_numValues, rhs._numValues); diff --git a/searchlib/src/vespa/searchlib/fef/properties.h b/searchlib/src/vespa/searchlib/fef/properties.h index a6ae83b0339..80e8c70939c 100644 --- a/searchlib/src/vespa/searchlib/fef/properties.h +++ b/searchlib/src/vespa/searchlib/fef/properties.h @@ -37,7 +37,7 @@ private: * * @param values the values for this property **/ - Property(const Values &values) : _values(&values) { } + Property(const Values &values) noexcept : _values(&values) { } public: /** @@ -46,14 +46,14 @@ public: * object on the stack in the application, and will also be used * by the @ref Properties class when a lookup gives no results. **/ - Property() : _values(&_emptyValues) { } + Property() noexcept : _values(&_emptyValues) { } /** * Check if we found what we were looking for or not. * * @return true if the key we looked up had at least one value **/ - bool found() const { + bool found() const noexcept { return !(*_values).empty(); } @@ -63,7 +63,7 @@ public: * * @return first value for the looked up key, or "" **/ - const Value &get() const { + const Value &get() const noexcept { if ((*_values).empty()) { return _emptyValue; } @@ -78,7 +78,7 @@ public: * @return first value for the looked up key, or fallBack * @param fallBack value to return if no values were found **/ - const Value & get(const Value &fallBack) const { + const Value & get(const Value &fallBack) const noexcept { if ((*_values).empty()) { return fallBack; } @@ -90,7 +90,7 @@ public: * * @return number of values for this property **/ - uint32_t size() const { return (*_values).size(); } + uint32_t size() const noexcept { return (*_values).size(); } /** * Obtain a specific value for the looked up key. @@ -98,7 +98,7 @@ public: * @return the requested value, or "" if idx was out of bounds * @param idx the index of the value we want to access **/ - const Value &getAt(uint32_t idx) const; + const Value &getAt(uint32_t idx) const noexcept; }; //----------------------------------------------------------------------------- @@ -127,7 +127,7 @@ public: /** * Virtual destructor to allow safe subclassing. **/ - virtual ~IPropertiesVisitor() {} + virtual ~IPropertiesVisitor() = default; }; //----------------------------------------------------------------------------- @@ -156,7 +156,7 @@ private: * @param buf data pointer * @param len data length **/ - static uint32_t rawHash(const void *buf, uint32_t len); + static uint32_t rawHash(const void *buf, uint32_t len) noexcept; public: using UP = std::unique_ptr; @@ -164,7 +164,7 @@ public: /** * Create an empty properties object. **/ - Properties(); + Properties() noexcept; Properties(Properties &&) noexcept = default; Properties & operator=(Properties &&) noexcept = default; Properties(const Properties &); @@ -192,7 +192,7 @@ public: * @return number of values for the given key * @param key the key **/ - uint32_t count(vespalib::stringref key) const; + uint32_t count(vespalib::stringref key) const noexcept; /** * Remove all values for the given key. @@ -226,14 +226,14 @@ public: * * @return number of keys **/ - uint32_t numKeys() const { return _data.size(); } + uint32_t numKeys() const noexcept { return _data.size(); } /** * Obtain the total number of values stored in this object. * * @return number of values **/ - uint32_t numValues() const { return _numValues; } + uint32_t numValues() const noexcept { return _numValues; } /** * Check if rhs contains the same key/value pairs as this @@ -242,14 +242,14 @@ public: * * @return true if we are equal to rhs **/ - bool operator==(const Properties &rhs) const; + bool operator==(const Properties &rhs) const noexcept; /** * Calculate a hash code for this object * * @return hash code for this object **/ - uint32_t hashCode() const; + uint32_t hashCode() const noexcept; /** * Visit all key/value pairs @@ -275,7 +275,7 @@ public: * @return object encapsulating lookup result * @param key the key to look up **/ - Property lookup(vespalib::stringref key) const; + Property lookup(vespalib::stringref key) const noexcept; /** * Look up a key inside a namespace using the proposed namespace @@ -289,7 +289,7 @@ public: * @param key the key to look up **/ Property lookup(vespalib::stringref namespace1, - vespalib::stringref key) const; + vespalib::stringref key) const noexcept; /** * Look up a key inside a namespace using the proposed namespace @@ -305,7 +305,7 @@ public: **/ Property lookup(vespalib::stringref namespace1, vespalib::stringref namespace2, - vespalib::stringref key) const; + vespalib::stringref key) const noexcept; /** * Look up a key inside a namespace using the proposed namespace @@ -323,13 +323,13 @@ public: Property lookup(vespalib::stringref namespace1, vespalib::stringref namespace2, vespalib::stringref namespace3, - vespalib::stringref key) const; + vespalib::stringref key) const noexcept; - void swap(Properties & rhs); + void swap(Properties & rhs) noexcept ; }; inline void -swap(Properties & a, Properties & b) +swap(Properties & a, Properties & b) noexcept { a.swap(b); } diff --git a/searchlib/src/vespa/searchlib/queryeval/blueprint.cpp b/searchlib/src/vespa/searchlib/queryeval/blueprint.cpp index 488c58e3119..3f6085ef7ff 100644 --- a/searchlib/src/vespa/searchlib/queryeval/blueprint.cpp +++ b/searchlib/src/vespa/searchlib/queryeval/blueprint.cpp @@ -87,7 +87,7 @@ Blueprint::sat_sum(const std::vector &data, uint32_t docid_limit) return { uint32_t(std::min(sum, uint64_t(limit))), empty }; } -Blueprint::State::State() +Blueprint::State::State() noexcept : _fields(), _estimateHits(0), _tree_size(1), @@ -97,13 +97,13 @@ Blueprint::State::State() _cost_tier(COST_TIER_NORMAL) {} -Blueprint::State::State(FieldSpecBase field) +Blueprint::State::State(FieldSpecBase field) noexcept : State() { _fields.add(field); } -Blueprint::State::State(FieldSpecBaseList fields_in) +Blueprint::State::State(FieldSpecBaseList fields_in) noexcept : _fields(std::move(fields_in)), _estimateHits(0), _tree_size(1), @@ -116,7 +116,7 @@ Blueprint::State::State(FieldSpecBaseList fields_in) Blueprint::State::~State() = default; -Blueprint::Blueprint() +Blueprint::Blueprint() noexcept : _parent(0), _sourceId(0xffffffff), _docid_limit(0), @@ -383,7 +383,7 @@ StateCache::notifyChange() { IntermediateBlueprint::~IntermediateBlueprint() = default; void -IntermediateBlueprint::setDocIdLimit(uint32_t limit) +IntermediateBlueprint::setDocIdLimit(uint32_t limit) noexcept { Blueprint::setDocIdLimit(limit); for (Blueprint::UP &child : _children) { @@ -576,7 +576,7 @@ IntermediateBlueprint::createSearch(fef::MatchData &md, bool strict) const return createIntermediateSearch(std::move(subSearches), strict, md); } -IntermediateBlueprint::IntermediateBlueprint() = default; +IntermediateBlueprint::IntermediateBlueprint() noexcept = default; IntermediateBlueprint & IntermediateBlueprint::addChild(Blueprint::UP child) @@ -736,13 +736,6 @@ LeafBlueprint::optimize(Blueprint* &self) maybe_eliminate_self(self, get_replacement()); } -void -LeafBlueprint::setEstimate(HitEstimate est) -{ - _state.estimate(est); - notifyChange(); -} - void LeafBlueprint::set_cost_tier(uint32_t value) { @@ -751,13 +744,6 @@ LeafBlueprint::set_cost_tier(uint32_t value) notifyChange(); } -void -LeafBlueprint::set_allow_termwise_eval(bool value) -{ - _state.allow_termwise_eval(value); - notifyChange(); -} - void LeafBlueprint::set_want_global_filter(bool value) { diff --git a/searchlib/src/vespa/searchlib/queryeval/blueprint.h b/searchlib/src/vespa/searchlib/queryeval/blueprint.h index dc7a0992d82..8d230b6ec01 100644 --- a/searchlib/src/vespa/searchlib/queryeval/blueprint.h +++ b/searchlib/src/vespa/searchlib/queryeval/blueprint.h @@ -48,11 +48,11 @@ public: uint32_t estHits; bool empty; - HitEstimate() : estHits(0), empty(true) {} - HitEstimate(uint32_t estHits_, bool empty_) + HitEstimate() noexcept : estHits(0), empty(true) {} + HitEstimate(uint32_t estHits_, bool empty_) noexcept : estHits(estHits_), empty(empty_) {} - bool operator < (const HitEstimate &other) const { + bool operator < (const HitEstimate &other) const noexcept { if (empty == other.empty) { return (estHits < other.estHits); } else { @@ -77,21 +77,21 @@ public: static constexpr uint8_t COST_TIER_EXPENSIVE = 2; static constexpr uint8_t COST_TIER_MAX = 255; - State(); - State(FieldSpecBase field); - State(FieldSpecBaseList fields_in); + State() noexcept; + State(FieldSpecBase field) noexcept; + State(FieldSpecBaseList fields_in) noexcept; State(const State &rhs) = delete; State(State &&rhs) noexcept = default; State &operator=(const State &rhs) = delete; State &operator=(State &&rhs) noexcept = default; ~State(); - bool isTermLike() const { return !_fields.empty(); } - const FieldSpecBaseList &fields() const { return _fields; } + bool isTermLike() const noexcept { return !_fields.empty(); } + const FieldSpecBaseList &fields() const noexcept { return _fields; } - size_t numFields() const { return _fields.size(); } - const FieldSpecBase &field(size_t idx) const { return _fields[idx]; } - const FieldSpecBase *lookupField(uint32_t fieldId) const { + size_t numFields() const noexcept { return _fields.size(); } + const FieldSpecBase &field(size_t idx) const noexcept { return _fields[idx]; } + const FieldSpecBase *lookupField(uint32_t fieldId) const noexcept { for (const FieldSpecBase & field : _fields) { if (field.getFieldId() == fieldId) { return &field; @@ -100,27 +100,27 @@ public: return nullptr; } - void estimate(HitEstimate est) { + void estimate(HitEstimate est) noexcept { _estimateHits = est.estHits; _estimateEmpty = est.empty; } - HitEstimate estimate() const { return HitEstimate(_estimateHits, _estimateEmpty); } - double hit_ratio(uint32_t docid_limit) const { + HitEstimate estimate() const noexcept { return HitEstimate(_estimateHits, _estimateEmpty); } + double hit_ratio(uint32_t docid_limit) const noexcept { uint32_t total_hits = _estimateHits; uint32_t total_docs = std::max(total_hits, docid_limit); return (total_docs == 0) ? 0.0 : double(total_hits) / double(total_docs); } - void tree_size(uint32_t value) { + void tree_size(uint32_t value) noexcept { assert(value < 0x100000); _tree_size = value; } - uint32_t tree_size() const { return _tree_size; } - void allow_termwise_eval(bool value) { _allow_termwise_eval = value; } - bool allow_termwise_eval() const { return _allow_termwise_eval; } - void want_global_filter(bool value) { _want_global_filter = value; } - bool want_global_filter() const { return _want_global_filter; } - void cost_tier(uint8_t value) { _cost_tier = value; } - uint8_t cost_tier() const { return _cost_tier; } + uint32_t tree_size() const noexcept { return _tree_size; } + void allow_termwise_eval(bool value) noexcept { _allow_termwise_eval = value; } + bool allow_termwise_eval() const noexcept { return _allow_termwise_eval; } + void want_global_filter(bool value) noexcept { _want_global_filter = value; } + bool want_global_filter() const noexcept { return _want_global_filter; } + void cost_tier(uint8_t value) noexcept { _cost_tier = value; } + uint8_t cost_tier() const noexcept { return _cost_tier; } }; // utility that just takes maximum estimate @@ -137,7 +137,7 @@ public: // utility to get the greater estimate to sort first, higher tiers last struct TieredGreaterEstimate { - bool operator () (const auto &a, const auto &b) const { + bool operator () (const auto &a, const auto &b) const noexcept { const auto &lhs = a->getState(); const auto &rhs = b->getState(); if (lhs.cost_tier() != rhs.cost_tier()) { @@ -149,7 +149,7 @@ public: // utility to get the lesser estimate to sort first, higher tiers last struct TieredLessEstimate { - bool operator () (const auto &a, const auto &b) const { + bool operator () (const auto &a, const auto &b) const noexcept { const auto &lhs = a->getState(); const auto &rhs = b->getState(); if (lhs.cost_tier() != rhs.cost_tier()) { @@ -189,20 +189,20 @@ public: // hit that isn't certain to be a match). enum class FilterConstraint { UPPER_BOUND, LOWER_BOUND }; - Blueprint(); + Blueprint() noexcept; Blueprint(const Blueprint &) = delete; Blueprint &operator=(const Blueprint &) = delete; virtual ~Blueprint(); - void setParent(Blueprint *parent) { _parent = parent; } - Blueprint *getParent() const { return _parent; } + void setParent(Blueprint *parent) noexcept { _parent = parent; } + Blueprint *getParent() const noexcept { return _parent; } bool has_parent() const { return (_parent != nullptr); } - Blueprint &setSourceId(uint32_t sourceId) { _sourceId = sourceId; return *this; } - uint32_t getSourceId() const { return _sourceId; } + Blueprint &setSourceId(uint32_t sourceId) noexcept { _sourceId = sourceId; return *this; } + uint32_t getSourceId() const noexcept { return _sourceId; } - virtual void setDocIdLimit(uint32_t limit) { _docid_limit = limit; } - uint32_t get_docid_limit() const { return _docid_limit; } + virtual void setDocIdLimit(uint32_t limit) noexcept { _docid_limit = limit; } + uint32_t get_docid_limit() const noexcept { return _docid_limit; } static Blueprint::UP optimize(Blueprint::UP bp); virtual void optimize(Blueprint* &self) = 0; @@ -227,7 +227,7 @@ public: virtual const State &getState() const = 0; const Blueprint &root() const; - double hit_ratio() const { return getState().hit_ratio(_docid_limit); } + double hit_ratio() const noexcept { return getState().hit_ratio(_docid_limit); } virtual void fetchPostings(const ExecuteInfo &execInfo) = 0; virtual void freeze() = 0; @@ -319,10 +319,10 @@ protected: public: using IndexList = std::vector; - IntermediateBlueprint(); + IntermediateBlueprint() noexcept; ~IntermediateBlueprint() override; - void setDocIdLimit(uint32_t limit) final; + void setDocIdLimit(uint32_t limit) noexcept final; void optimize(Blueprint* &self) final; void set_global_filter(const GlobalFilter &global_filter, double estimated_hit_ratio) override; @@ -360,24 +360,30 @@ private: State _state; protected: void optimize(Blueprint* &self) final; - void setEstimate(HitEstimate est); + void setEstimate(HitEstimate est) { + _state.estimate(est); + notifyChange(); + } void set_cost_tier(uint32_t value); - void set_allow_termwise_eval(bool value); + void set_allow_termwise_eval(bool value) { + _state.allow_termwise_eval(value); + notifyChange(); + } void set_want_global_filter(bool value); void set_tree_size(uint32_t value); - LeafBlueprint(bool allow_termwise_eval) + LeafBlueprint(bool allow_termwise_eval) noexcept : _state() { _state.allow_termwise_eval(allow_termwise_eval); } - LeafBlueprint(FieldSpecBase field, bool allow_termwise_eval) + LeafBlueprint(FieldSpecBase field, bool allow_termwise_eval) noexcept : _state(field) { _state.allow_termwise_eval(allow_termwise_eval); } - LeafBlueprint(FieldSpecBaseList fields, bool allow_termwise_eval) + LeafBlueprint(FieldSpecBaseList fields, bool allow_termwise_eval) noexcept : _state(std::move(fields)) { _state.allow_termwise_eval(allow_termwise_eval); @@ -386,7 +392,7 @@ protected: public: ~LeafBlueprint() override = default; const State &getState() const final { return _state; } - void setDocIdLimit(uint32_t limit) final { Blueprint::setDocIdLimit(limit); } + void setDocIdLimit(uint32_t limit) noexcept final { Blueprint::setDocIdLimit(limit); } void fetchPostings(const ExecuteInfo &execInfo) override; void freeze() final; SearchIteratorUP createSearch(fef::MatchData &md, bool strict) const override; @@ -397,15 +403,15 @@ public: // for leaf nodes representing a single term struct SimpleLeafBlueprint : LeafBlueprint { - explicit SimpleLeafBlueprint() : LeafBlueprint(true) {} - explicit SimpleLeafBlueprint(FieldSpecBase field) : LeafBlueprint(field, true) {} - explicit SimpleLeafBlueprint(FieldSpecBaseList fields) : LeafBlueprint(std::move(fields), true) {} + explicit SimpleLeafBlueprint() noexcept : LeafBlueprint(true) {} + explicit SimpleLeafBlueprint(FieldSpecBase field) noexcept : LeafBlueprint(field, true) {} + explicit SimpleLeafBlueprint(FieldSpecBaseList fields) noexcept: LeafBlueprint(std::move(fields), true) {} }; // for leaf nodes representing more complex structures like wand/phrase struct ComplexLeafBlueprint : LeafBlueprint { - explicit ComplexLeafBlueprint(FieldSpecBase field) : LeafBlueprint(field, false) {} - explicit ComplexLeafBlueprint(FieldSpecBaseList fields) : LeafBlueprint(std::move(fields), false) {} + explicit ComplexLeafBlueprint(FieldSpecBase field) noexcept : LeafBlueprint(field, false) {} + explicit ComplexLeafBlueprint(FieldSpecBaseList fields) noexcept : LeafBlueprint(std::move(fields), false) {} }; //----------------------------------------------------------------------------- diff --git a/searchlib/src/vespa/searchlib/queryeval/field_spec.cpp b/searchlib/src/vespa/searchlib/queryeval/field_spec.cpp index 121591723e2..cd1ddd5b92e 100644 --- a/searchlib/src/vespa/searchlib/queryeval/field_spec.cpp +++ b/searchlib/src/vespa/searchlib/queryeval/field_spec.cpp @@ -5,9 +5,9 @@ namespace search::queryeval { -FieldSpecBase::FieldSpecBase(uint32_t fieldId, fef::TermFieldHandle handle, bool isFilter_) : - _fieldId(fieldId | (isFilter_ ? 0x1000000u : 0)), - _handle(handle) +FieldSpecBase::FieldSpecBase(uint32_t fieldId, fef::TermFieldHandle handle, bool isFilter_) noexcept + : _fieldId(fieldId | (isFilter_ ? 0x1000000u : 0)), + _handle(handle) { assert(fieldId < 0x1000000); // Can be represented by 24 bits } diff --git a/searchlib/src/vespa/searchlib/queryeval/field_spec.h b/searchlib/src/vespa/searchlib/queryeval/field_spec.h index 3fe43597602..960afb95281 100644 --- a/searchlib/src/vespa/searchlib/queryeval/field_spec.h +++ b/searchlib/src/vespa/searchlib/queryeval/field_spec.h @@ -19,15 +19,15 @@ namespace search::queryeval { class FieldSpecBase { public: - FieldSpecBase(uint32_t fieldId, fef::TermFieldHandle handle, bool isFilter_ = false); + FieldSpecBase(uint32_t fieldId, fef::TermFieldHandle handle, bool isFilter_ = false) noexcept; // resolve where to put match information for this term/field combination fef::TermFieldMatchData *resolve(fef::MatchData &md) const; const fef::TermFieldMatchData *resolve(const fef::MatchData &md) const; - uint32_t getFieldId() const { return _fieldId & 0xffffff; } - fef::TermFieldHandle getHandle() const { return _handle; } + uint32_t getFieldId() const noexcept { return _fieldId & 0xffffff; } + fef::TermFieldHandle getHandle() const noexcept { return _handle; } /// a filter produces less detailed match data - bool isFilter() const { return _fieldId & 0x1000000; } + bool isFilter() const noexcept { return _fieldId & 0x1000000; } private: uint32_t _fieldId; // field id in ranking framework fef::TermFieldHandle _handle; // handle used when exposing match data to ranking framework @@ -40,18 +40,18 @@ class FieldSpec : public FieldSpecBase { public: FieldSpec(const vespalib::string & name, uint32_t fieldId, - fef::TermFieldHandle handle, bool isFilter_ = false) + fef::TermFieldHandle handle, bool isFilter_ = false) noexcept : FieldSpecBase(fieldId, handle, isFilter_), _name(name) {} - FieldSpec(const vespalib::string & name, FieldSpecBase base) + FieldSpec(const vespalib::string & name, FieldSpecBase base) noexcept : FieldSpecBase(base), _name(name) {} ~FieldSpec(); - void setBase(FieldSpecBase base) { - static_cast(*this) = base; + void setBase(FieldSpecBase base) noexcept { + FieldSpecBase::operator =(base); } const vespalib::string & getName() const noexcept { return _name; } private: @@ -68,7 +68,7 @@ private: List _list; public: - FieldSpecBaseList() = default; + FieldSpecBaseList() noexcept = default; FieldSpecBaseList(FieldSpecBaseList &&) noexcept = default; FieldSpecBaseList & operator=(FieldSpecBaseList &&) noexcept = default; FieldSpecBaseList(const FieldSpecBaseList &) = default; @@ -76,15 +76,15 @@ public: ~FieldSpecBaseList(); void reserve(size_t sz) { _list.reserve(sz); } using const_iterator = const FieldSpecBase *; - FieldSpecBaseList &add(const FieldSpecBase &spec) { + FieldSpecBaseList &add(const FieldSpecBase &spec) noexcept { _list.push_back(spec); return *this; } - bool empty() const { return _list.empty(); } - size_t size() const { return _list.size(); } - const_iterator begin() const { return _list.begin(); } - const_iterator end() const { return _list.end(); } - const FieldSpecBase &operator[](size_t i) const { return _list[i]; } + bool empty() const noexcept { return _list.empty(); } + size_t size() const noexcept { return _list.size(); } + const_iterator begin() const noexcept { return _list.begin(); } + const_iterator end() const noexcept { return _list.end(); } + const FieldSpecBase &operator[](size_t i) const noexcept { return _list[i]; } }; /** @@ -96,7 +96,7 @@ private: vespalib::SmallVector _list; public: - FieldSpecList() = default; + FieldSpecList() noexcept = default; FieldSpecList(FieldSpecList &&) noexcept = delete; FieldSpecList & operator=(FieldSpecList &&) noexcept = delete; FieldSpecList(const FieldSpecList &) noexcept = delete; @@ -106,9 +106,9 @@ public: _list.push_back(spec); return *this; } - bool empty() const { return _list.empty(); } - size_t size() const { return _list.size(); } - const FieldSpec &operator[](size_t i) const { return _list[i]; } + bool empty() const noexcept { return _list.empty(); } + size_t size() const noexcept { return _list.size(); } + const FieldSpec &operator[](size_t i) const noexcept { return _list[i]; } void clear() { _list.clear(); } }; diff --git a/vespalib/src/vespa/vespalib/datastore/compaction_strategy.cpp b/vespalib/src/vespa/vespalib/datastore/compaction_strategy.cpp index 4eb4ff16864..eea49e80135 100644 --- a/vespalib/src/vespa/vespalib/datastore/compaction_strategy.cpp +++ b/vespalib/src/vespa/vespalib/datastore/compaction_strategy.cpp @@ -10,19 +10,19 @@ namespace vespalib::datastore { bool -CompactionStrategy::should_compact_memory(const MemoryUsage& memory_usage) const +CompactionStrategy::should_compact_memory(const MemoryUsage& memory_usage) const noexcept { return should_compact_memory(memory_usage.usedBytes(), memory_usage.deadBytes()); } bool -CompactionStrategy::should_compact_address_space(const AddressSpace& address_space) const +CompactionStrategy::should_compact_address_space(const AddressSpace& address_space) const noexcept { return should_compact_address_space(address_space.used(), address_space.dead()); } CompactionSpec -CompactionStrategy::should_compact(const MemoryUsage& memory_usage, const AddressSpace& address_space) const +CompactionStrategy::should_compact(const MemoryUsage& memory_usage, const AddressSpace& address_space) const noexcept { return CompactionSpec(should_compact_memory(memory_usage), should_compact_address_space(address_space)); } @@ -36,7 +36,7 @@ std::ostream& operator<<(std::ostream& os, const CompactionStrategy& compaction_ } CompactionStrategy -CompactionStrategy::make_compact_all_active_buffers_strategy() +CompactionStrategy::make_compact_all_active_buffers_strategy() noexcept { return CompactionStrategy(0.0, 0.0, std::numeric_limits::max(), 1.0); } diff --git a/vespalib/src/vespa/vespalib/datastore/compaction_strategy.h b/vespalib/src/vespa/vespalib/datastore/compaction_strategy.h index f78e123e5de..c0c1857deae 100644 --- a/vespalib/src/vespa/vespalib/datastore/compaction_strategy.h +++ b/vespalib/src/vespa/vespalib/datastore/compaction_strategy.h @@ -25,15 +25,15 @@ public: static constexpr size_t DEAD_BYTES_SLACK = 0x10000u; static constexpr size_t DEAD_ADDRESS_SPACE_SLACK = 0x10000u; private: - double _maxDeadBytesRatio; // Max ratio of dead bytes before compaction - double _maxDeadAddressSpaceRatio; // Max ratio of dead address space before compaction + float _maxDeadBytesRatio; // Max ratio of dead bytes before compaction + float _maxDeadAddressSpaceRatio; // Max ratio of dead address space before compaction + float _active_buffers_ratio; // Ratio of active buffers to compact for each reason (memory usage, address space usage) uint32_t _max_buffers; // Max number of buffers to compact for each reason (memory usage, address space usage) - double _active_buffers_ratio; // Ratio of active buffers to compact for each reason (memory usage, address space usage) - bool should_compact_memory(size_t used_bytes, size_t dead_bytes) const { + bool should_compact_memory(size_t used_bytes, size_t dead_bytes) const noexcept { return ((dead_bytes >= DEAD_BYTES_SLACK) && (dead_bytes > used_bytes * getMaxDeadBytesRatio())); } - bool should_compact_address_space(size_t used_address_space, size_t dead_address_space) const { + bool should_compact_address_space(size_t used_address_space, size_t dead_address_space) const noexcept { return ((dead_address_space >= DEAD_ADDRESS_SPACE_SLACK) && (dead_address_space > used_address_space * getMaxDeadAddressSpaceRatio())); } @@ -41,40 +41,37 @@ public: CompactionStrategy() noexcept : _maxDeadBytesRatio(0.05), _maxDeadAddressSpaceRatio(0.2), - _max_buffers(1), - _active_buffers_ratio(0.1) - { - } - CompactionStrategy(double maxDeadBytesRatio, double maxDeadAddressSpaceRatio) noexcept + _active_buffers_ratio(0.1), + _max_buffers(1) + { } + CompactionStrategy(float maxDeadBytesRatio, float maxDeadAddressSpaceRatio) noexcept : _maxDeadBytesRatio(maxDeadBytesRatio), _maxDeadAddressSpaceRatio(maxDeadAddressSpaceRatio), - _max_buffers(1), - _active_buffers_ratio(0.1) - { - } - CompactionStrategy(double maxDeadBytesRatio, double maxDeadAddressSpaceRatio, uint32_t max_buffers, double active_buffers_ratio) noexcept + _active_buffers_ratio(0.1), + _max_buffers(1) + { } + CompactionStrategy(float maxDeadBytesRatio, float maxDeadAddressSpaceRatio, uint32_t max_buffers, float active_buffers_ratio) noexcept : _maxDeadBytesRatio(maxDeadBytesRatio), _maxDeadAddressSpaceRatio(maxDeadAddressSpaceRatio), - _max_buffers(max_buffers), - _active_buffers_ratio(active_buffers_ratio) - { - } - double getMaxDeadBytesRatio() const { return _maxDeadBytesRatio; } - double getMaxDeadAddressSpaceRatio() const { return _maxDeadAddressSpaceRatio; } + _active_buffers_ratio(active_buffers_ratio), + _max_buffers(max_buffers) + { } + float getMaxDeadBytesRatio() const noexcept { return _maxDeadBytesRatio; } + float getMaxDeadAddressSpaceRatio() const noexcept { return _maxDeadAddressSpaceRatio; } uint32_t get_max_buffers() const noexcept { return _max_buffers; } - double get_active_buffers_ratio() const noexcept { return _active_buffers_ratio; } - bool operator==(const CompactionStrategy & rhs) const { + float get_active_buffers_ratio() const noexcept { return _active_buffers_ratio; } + bool operator==(const CompactionStrategy & rhs) const noexcept { return (_maxDeadBytesRatio == rhs._maxDeadBytesRatio) && (_maxDeadAddressSpaceRatio == rhs._maxDeadAddressSpaceRatio) && (_max_buffers == rhs._max_buffers) && (_active_buffers_ratio == rhs._active_buffers_ratio); } - bool operator!=(const CompactionStrategy & rhs) const { return !(operator==(rhs)); } + bool operator!=(const CompactionStrategy & rhs) const noexcept { return !(operator==(rhs)); } - bool should_compact_memory(const MemoryUsage& memory_usage) const; - bool should_compact_address_space(const AddressSpace& address_space) const; - CompactionSpec should_compact(const MemoryUsage& memory_usage, const AddressSpace& address_space) const; - static CompactionStrategy make_compact_all_active_buffers_strategy(); + bool should_compact_memory(const MemoryUsage& memory_usage) const noexcept; + bool should_compact_address_space(const AddressSpace& address_space) const noexcept; + CompactionSpec should_compact(const MemoryUsage& memory_usage, const AddressSpace& address_space) const noexcept; + static CompactionStrategy make_compact_all_active_buffers_strategy() noexcept; }; std::ostream& operator<<(std::ostream& os, const CompactionStrategy& compaction_strategy); diff --git a/vespalib/src/vespa/vespalib/text/lowercase.h b/vespalib/src/vespa/vespalib/text/lowercase.h index dc081c6ba2d..5c4e3e34e07 100644 --- a/vespalib/src/vespa/vespalib/text/lowercase.h +++ b/vespalib/src/vespa/vespalib/text/lowercase.h @@ -43,9 +43,9 @@ public: * @param codepoint the character codepoint to be lowercased. * @return lowercase UCS-4 character (codepoint if no lowercasing is performed). **/ - static uint32_t convert(uint32_t codepoint) + static uint32_t convert(uint32_t codepoint) noexcept { - if (codepoint < 0x100) { + if (codepoint < 0x100) [[likely]] { return lowercase_0_block[codepoint]; } else if (codepoint < 0x600) { return lowercase_0_5_blocks[codepoint]; diff --git a/vespalib/src/vespa/vespalib/text/utf8.cpp b/vespalib/src/vespa/vespalib/text/utf8.cpp index cae2bbae682..c950f62985f 100644 --- a/vespalib/src/vespa/vespalib/text/utf8.cpp +++ b/vespalib/src/vespa/vespalib/text/utf8.cpp @@ -16,18 +16,16 @@ void Utf8::throwX(const char *msg, unsigned int number) throw IllegalArgumentException(what); } -uint32_t Utf8Reader::getComplexChar(unsigned char firstbyte, uint32_t fallback) +uint32_t Utf8Reader::getComplexChar(unsigned char firstbyte, uint32_t fallback) noexcept { if (_pos == size()) { // this shouldn't happen ... - LOG(warning, "last byte %02X of Utf8Reader block was incomplete UTF-8", - firstbyte); + LOG(warning, "last byte %02X of Utf8Reader block was incomplete UTF-8", firstbyte); return fallback; } assert(hasMore()); // should never fall out of range if (! Utf8::validFirstByte(firstbyte)) { - LOG(debug, "invalid first byte %02X in Utf8Reader data block", - firstbyte); + LOG(debug, "invalid first byte %02X in Utf8Reader data block", firstbyte); return fallback; } int need = Utf8::numContBytes(firstbyte); @@ -48,8 +46,7 @@ uint32_t Utf8Reader::getComplexChar(unsigned char firstbyte, uint32_t fallback) // check > 0x7F ? return r; } else { - LOG(debug, "invalid continuation byte %02X in Utf8Reader data block", - contbyte); + LOG(debug, "invalid continuation byte %02X in Utf8Reader data block", contbyte); return fallback; } } @@ -69,8 +66,7 @@ uint32_t Utf8Reader::getComplexChar(unsigned char firstbyte, uint32_t fallback) // check > 0x7FF ? return r; } else { - LOG(debug, "invalid continuation bytes %02X/%02X in Utf8Reader data block", - contbyte1, contbyte2); + LOG(debug, "invalid continuation bytes %02X/%02X in Utf8Reader data block", contbyte1, contbyte2); return fallback; } } @@ -95,11 +91,10 @@ uint32_t Utf8Reader::getComplexChar(unsigned char firstbyte, uint32_t fallback) uint32_t -Utf8ReaderForZTS::getComplexChar(unsigned char firstbyte, uint32_t fallback) +Utf8ReaderForZTS::getComplexChar(unsigned char firstbyte, uint32_t fallback) noexcept { if (! Utf8::validFirstByte(firstbyte)) { - LOG(debug, "invalid first byte %02X in Utf8Reader data block", - firstbyte); + LOG(debug, "invalid first byte %02X in Utf8Reader data block", firstbyte); return fallback; } int need = Utf8::numContBytes(firstbyte); @@ -108,8 +103,7 @@ Utf8ReaderForZTS::getComplexChar(unsigned char firstbyte, uint32_t fallback) if (need == 1) { if (_p[0] == 0) { - LOG(debug, "incomplete character (first byte %02X) in Utf8ReaderZTS", - firstbyte); + LOG(debug, "incomplete character (first byte %02X) in Utf8ReaderZTS", firstbyte); return fallback; } unsigned char contbyte = _p[0]; @@ -119,16 +113,14 @@ Utf8ReaderForZTS::getComplexChar(unsigned char firstbyte, uint32_t fallback) // check > 0x7F ? return r; } else { - LOG(debug, "invalid continuation byte %02X in Utf8Reader data block", - contbyte); + LOG(debug, "invalid continuation byte %02X in Utf8Reader data block", contbyte); return fallback; } } if (need == 2) { if (_p[0] == 0 || _p[1] == 0) { - LOG(debug, "incomplete character (first byte %02X) in Utf8ReaderZTS", - firstbyte); + LOG(debug, "incomplete character (first byte %02X) in Utf8ReaderZTS", firstbyte); return fallback; } unsigned char contbyte1 = _p[0]; @@ -145,16 +137,14 @@ Utf8ReaderForZTS::getComplexChar(unsigned char firstbyte, uint32_t fallback) // check > 0x7FF ? return r; } else { - LOG(debug, "invalid continuation bytes %02X/%02X in Utf8Reader data block", - contbyte1, contbyte2); + LOG(debug, "invalid continuation bytes %02X/%02X in Utf8Reader data block", contbyte1, contbyte2); return fallback; } } assert(need == 3); if (_p[0] == 0 || _p[1] == 0 || _p[2] == 0) { - LOG(debug, "incomplete character (first byte %02X) in Utf8ReaderZTS", - firstbyte); + LOG(debug, "incomplete character (first byte %02X) in Utf8ReaderZTS", firstbyte); return fallback; } unsigned char contbyte1 = _p[0]; @@ -168,8 +158,7 @@ Utf8ReaderForZTS::getComplexChar(unsigned char firstbyte, uint32_t fallback) // check > 0xFFFF? return decode4(firstbyte, contbyte1, contbyte2, contbyte3); } else { - LOG(debug, "invalid continuation bytes %02X/%02X/%02X in Utf8Reader data block", - contbyte1, contbyte2, contbyte3); + LOG(debug, "invalid continuation bytes %02X/%02X/%02X in Utf8Reader data block", contbyte1, contbyte2, contbyte3); return fallback; } } @@ -234,7 +223,7 @@ template class Utf8Writer; template class Utf8Writer; template -T Utf8::filter_invalid_sequences(const T& input) +T Utf8::filter_invalid_sequences(const T& input) noexcept { T retval; Utf8Reader reader(input.c_str(), input.size()); diff --git a/vespalib/src/vespa/vespalib/text/utf8.h b/vespalib/src/vespa/vespalib/text/utf8.h index 98e06ca5faf..3367bd5b3d2 100644 --- a/vespalib/src/vespa/vespalib/text/utf8.h +++ b/vespalib/src/vespa/vespalib/text/utf8.h @@ -34,14 +34,14 @@ public: * UTF-8 encoded surrogates are also considered invalid. **/ template - static T filter_invalid_sequences(const T& input); + static T filter_invalid_sequences(const T& input) noexcept; /** * check if a byte is valid as the first byte of an UTF-8 character. * @param c the byte to be checked * @return true if a valid UTF-8 character can start with this byte **/ - static bool validFirstByte(unsigned char c) { + static bool validFirstByte(unsigned char c) noexcept { return (c < 0x80 || (c > 0xC1 && c < 0xF5)); } @@ -52,12 +52,12 @@ public: * @param c the first byte (must pass validFirstByte check) * @return 0, 1, 2, or 3 **/ - static int numContBytes(unsigned char c) { + static int numContBytes(unsigned char c) noexcept { if (c < 0x80) return 0; if (c > 0xC1 && c < 0xE0) return 1; if (c > 0xDF && c < 0xF0) return 2; if (c > 0xEF && c < 0xF5) return 3; - throwX("invalid first byte of UTF8 sequence", c); + return -1; } /** @@ -65,7 +65,7 @@ public: * @param c the byte to be checked * @return true if a valid UTF-8 character can contain this byte **/ - static bool validContByte(unsigned char c) { + static bool validContByte(unsigned char c) noexcept { return (c > 0x7F && c < 0xC0); } @@ -82,8 +82,7 @@ public: * @param contbyte second byte in this UTF-8 character * @return decoded UCS-4 codepoint in range [0, 0x7FF] **/ - static uint32_t decode2(unsigned char firstbyte, - unsigned char contbyte) + static uint32_t decode2(unsigned char firstbyte, unsigned char contbyte) noexcept { uint32_t r = (firstbyte & low_5bits_mask); r <<= 6; @@ -108,7 +107,7 @@ public: **/ static uint32_t decode3(unsigned char firstbyte, unsigned char contbyte1, - unsigned char contbyte2) + unsigned char contbyte2) noexcept { uint32_t r = (firstbyte & low_4bits_mask); r <<= 6; @@ -138,7 +137,7 @@ public: static uint32_t decode4(unsigned char firstbyte, unsigned char contbyte1, unsigned char contbyte2, - unsigned char contbyte3) + unsigned char contbyte3) noexcept { uint32_t r = (firstbyte & low_3bits_mask); r <<= 6; @@ -177,14 +176,14 @@ class Utf8Reader private: size_type _pos; - uint32_t getComplexChar(unsigned char firstbyte, uint32_t fallback); + uint32_t getComplexChar(unsigned char firstbyte, uint32_t fallback) noexcept; public: /** * Construct a reader for the given block of data * @param input data to read UTF-8 from (can be read-only) **/ - Utf8Reader(stringref input) + Utf8Reader(stringref input) noexcept : stringref(input), _pos(0) {} @@ -193,7 +192,7 @@ public: * @param start pointer to the start of the block * @param sz size of the block in bytes **/ - Utf8Reader(const char *start, size_t sz) + Utf8Reader(const char *start, size_t sz) noexcept : stringref(start, sz), _pos(0) {} @@ -201,7 +200,7 @@ public: * check if the buffer has more data. * @return true if there is more data **/ - bool hasMore() const { return _pos < size(); } + bool hasMore() const noexcept { return _pos < size(); } /** * Decode the UTF-8 character at the current position. @@ -211,7 +210,7 @@ public: * @param fallback the value to return if invalid UTF-8 is found * @return a valid UCS-4 codepoint (or the fallback value) **/ - uint32_t getChar(uint32_t fallback) { + uint32_t getChar(uint32_t fallback) noexcept { unsigned char firstbyte = (*this)[_pos++]; // always steps at least 1 position if (firstbyte < 0x80) { return firstbyte; @@ -232,13 +231,13 @@ public: * * @return a valid UCS-4 codepoint **/ - uint32_t getChar() { return getChar(Utf8::REPLACEMENT_CHAR); } + uint32_t getChar() noexcept { return getChar(Utf8::REPLACEMENT_CHAR); } /** * obtain the current byte offset position * @return position in bytes **/ - size_type getPos() const { return _pos; } + size_type getPos() const noexcept { return _pos; } }; @@ -252,7 +251,7 @@ class Utf8ReaderForZTS { private: const char * &_p; - uint32_t getComplexChar(unsigned char firstbyte, uint32_t fallback); + uint32_t getComplexChar(unsigned char firstbyte, uint32_t fallback) noexcept; public: /** @@ -265,7 +264,7 @@ public: * * @param start pointer to the start of the block **/ - Utf8ReaderForZTS(const char * &start) + Utf8ReaderForZTS(const char * &start) noexcept : _p(start) {} @@ -273,7 +272,7 @@ public: * check if the buffer has more data. * @return true if there is more data **/ - bool hasMore() const { + bool hasMore() const noexcept { return (*_p) != '\0'; } @@ -285,9 +284,9 @@ public: * @param fallback the value to return if invalid UTF-8 is found * @return a valid UCS-4 codepoint (or the fallback value) **/ - uint32_t getChar(uint32_t fallback) { + uint32_t getChar(uint32_t fallback) noexcept { unsigned char firstbyte = *_p++; // always steps at least 1 position - if (firstbyte < 0x80) { + if (firstbyte < 0x80) [[likely]] { return firstbyte; } else { return getComplexChar(firstbyte, fallback); @@ -306,7 +305,7 @@ public: * * @return a valid UCS-4 codepoint **/ - uint32_t getChar() { 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 @@ -314,7 +313,7 @@ public: * "strlen" does not count the zero termination, but bytes * that aren't valid UTF-8 will count as one character each. **/ - static size_t countChars(const char *p) { + static size_t countChars(const char *p) noexcept { Utf8ReaderForZTS reader(p); size_t i; for (i = 0; reader.hasMore(); ++i) { @@ -340,7 +339,7 @@ public: * that the writer will append to. Must be writable * and must be kept alive while the writer is active. **/ - Utf8Writer(Target &target) : _target(target) {} + Utf8Writer(Target &target) noexcept : _target(target) {} /** * append the given character to the target string. diff --git a/vespalib/src/vespa/vespalib/util/alloc.cpp b/vespalib/src/vespa/vespalib/util/alloc.cpp index 204d80340aa..2ba3bc252ae 100644 --- a/vespalib/src/vespa/vespalib/util/alloc.cpp +++ b/vespalib/src/vespa/vespalib/util/alloc.cpp @@ -292,7 +292,7 @@ HeapAllocator::alloc(size_t sz) const { PtrAndSize HeapAllocator::salloc(size_t sz) { if (sz == 0) { - return PtrAndSize(nullptr, sz); + return PtrAndSize(); } void * ptr = malloc(sz); if (ptr == nullptr) { @@ -311,7 +311,7 @@ void HeapAllocator::sfree(PtrAndSize alloc) noexcept { PtrAndSize AlignedHeapAllocator::alloc(size_t sz) const { - if (!sz) { return PtrAndSize(nullptr, 0); } + if (!sz) { return PtrAndSize(); } void* ptr; int result = posix_memalign(&ptr, _alignment, sz); if (result != 0) { diff --git a/vespalib/src/vespa/vespalib/util/alloc.h b/vespalib/src/vespa/vespalib/util/alloc.h index a27bcca0b47..dca4d633b43 100644 --- a/vespalib/src/vespa/vespalib/util/alloc.h +++ b/vespalib/src/vespa/vespalib/util/alloc.h @@ -49,7 +49,7 @@ public: } return *this; } - Alloc() noexcept : _alloc(nullptr, 0), _allocator(nullptr) { } + Alloc() noexcept : _alloc(), _allocator(nullptr) { } ~Alloc() noexcept { reset(); } @@ -83,10 +83,9 @@ private: Alloc(const MemoryAllocator * allocator, size_t sz) noexcept : _alloc(allocator->alloc(sz)), _allocator(allocator) - { - } + { } Alloc(const MemoryAllocator * allocator) noexcept - : _alloc(nullptr, 0), + : _alloc(), _allocator(allocator) { } void clear() noexcept { diff --git a/vespalib/src/vespa/vespalib/util/growstrategy.h b/vespalib/src/vespa/vespalib/util/growstrategy.h index 02e18e44925..643e3f03023 100644 --- a/vespalib/src/vespa/vespalib/util/growstrategy.h +++ b/vespalib/src/vespa/vespalib/util/growstrategy.h @@ -4,14 +4,15 @@ #include #include +#include namespace vespalib { class GrowStrategy { private: - size_t _initialCapacity; - size_t _minimumCapacity; - size_t _growDelta; + uint32_t _initialCapacity; + uint32_t _minimumCapacity; + uint32_t _growDelta; float _growFactor; public: GrowStrategy() noexcept @@ -33,7 +34,7 @@ public: void setInitialCapacity(size_t v) noexcept { _initialCapacity = v; } void setGrowDelta(size_t v) noexcept { _growDelta = v; } - size_t calc_new_size(size_t base_size) const { + size_t calc_new_size(size_t base_size) const noexcept { size_t delta = (base_size * getGrowFactor()) + getGrowDelta(); size_t new_size = base_size + std::max(delta, static_cast(1)); return std::max(new_size, getMinimumCapacity()); diff --git a/vespalib/src/vespa/vespalib/util/mmap_file_allocator.cpp b/vespalib/src/vespa/vespalib/util/mmap_file_allocator.cpp index 9ed4806385d..2c0d0f4339d 100644 --- a/vespalib/src/vespa/vespalib/util/mmap_file_allocator.cpp +++ b/vespalib/src/vespa/vespalib/util/mmap_file_allocator.cpp @@ -46,7 +46,7 @@ PtrAndSize MmapFileAllocator::alloc(size_t sz) const { if (sz == 0) { - return PtrAndSize(nullptr, 0); // empty allocation + return PtrAndSize(); // empty allocation } sz = round_up_to_page_size(sz); uint64_t offset = alloc_area(sz); diff --git a/vespalib/src/vespa/vespalib/util/small_vector.h b/vespalib/src/vespa/vespalib/util/small_vector.h index b47cb5903b9..ba166362d33 100644 --- a/vespalib/src/vespa/vespalib/util/small_vector.h +++ b/vespalib/src/vespa/vespalib/util/small_vector.h @@ -216,7 +216,7 @@ public: template bool operator==(const SmallVector &a, - const SmallVector &b) + const SmallVector &b) noexcept { if (a.size() != b.size()) { return false; -- cgit v1.2.3