diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2021-06-04 16:57:05 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-04 16:57:05 +0200 |
commit | 11da9c85cc5d44cf0a36baa4ce7c471d58fba5b3 (patch) | |
tree | 3117667fd3b0087ee0737e2a381d374045af7ec1 /vespalib | |
parent | e7e8208b6b180454d62d47c22d3250e2dfc8b8de (diff) | |
parent | 6c537290ad1df8469b54dee80079542c171fac1a (diff) |
Merge pull request #18114 from vespa-engine/balder/explicit-erase-when-capacity-is-low
Use explicit erase to avoid clearing and resizing the hashtable when …
Diffstat (limited to 'vespalib')
-rw-r--r-- | vespalib/src/vespa/vespalib/util/alloc.h | 12 | ||||
-rw-r--r-- | vespalib/src/vespa/vespalib/util/optimized.h | 6 |
2 files changed, 13 insertions, 5 deletions
diff --git a/vespalib/src/vespa/vespalib/util/alloc.h b/vespalib/src/vespa/vespalib/util/alloc.h index f608a244035..a97e8c9f25e 100644 --- a/vespalib/src/vespa/vespalib/util/alloc.h +++ b/vespalib/src/vespa/vespalib/util/alloc.h @@ -102,13 +102,21 @@ private: namespace vespalib { /// Rounds up to the closest number that is a power of 2 -inline size_t roundUp2inN(size_t minimum) { +inline size_t +roundUp2inN(size_t minimum) { return 2ul << Optimized::msbIdx(minimum - 1); } /// Rounds minElems up to the closest number where minElems*elemSize is a power of 2 -inline size_t roundUp2inN(size_t minElems, size_t elemSize) { +inline size_t +roundUp2inN(size_t minElems, size_t elemSize) { return roundUp2inN(minElems * elemSize)/elemSize; } +template <typename T> +size_t +roundUp2inN(size_t elems) { + return roundUp2inN(elems, sizeof(T)); +} + } diff --git a/vespalib/src/vespa/vespalib/util/optimized.h b/vespalib/src/vespa/vespalib/util/optimized.h index 92cf1f0ca24..6c6d1b12a71 100644 --- a/vespalib/src/vespa/vespalib/util/optimized.h +++ b/vespalib/src/vespa/vespalib/util/optimized.h @@ -22,9 +22,9 @@ public: static int lsbIdx(unsigned int v); static int lsbIdx(unsigned long v); static int lsbIdx(unsigned long long v); - static int popCount(unsigned int v) { return __builtin_popcount(v); } - static int popCount(unsigned long v) { return __builtin_popcountl(v); } - static int popCount(unsigned long long v) { return __builtin_popcountll(v); } + static constexpr int popCount(unsigned int v) { return __builtin_popcount(v); } + static constexpr int popCount(unsigned long v) { return __builtin_popcountl(v); } + static constexpr int popCount(unsigned long long v) { return __builtin_popcountll(v); } }; /** |