diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2021-03-31 18:29:29 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-31 18:29:29 +0200 |
commit | 377a98264c368abc53b11db078b62a63b315370a (patch) | |
tree | 0a39f56e082470622d3c50335b82ecd5ed4c13b8 /vespalib/src | |
parent | 2d5ccce9bb3cd48ad75d411b54ee9a76f1bed49f (diff) | |
parent | 19cfcdcf14cdfabf3b197726d6017382b5855e2c (diff) |
Merge pull request #17252 from vespa-engine/balder/inline-frequently-called-methods
Balder/inline frequently called methods
Diffstat (limited to 'vespalib/src')
-rw-r--r-- | vespalib/src/vespa/vespalib/datastore/sharded_hash_map.cpp | 4 | ||||
-rw-r--r-- | vespalib/src/vespa/vespalib/datastore/sharded_hash_map.h | 3 | ||||
-rw-r--r-- | vespalib/src/vespa/vespalib/util/alloc.cpp | 26 | ||||
-rw-r--r-- | vespalib/src/vespa/vespalib/util/alloc.h | 32 |
4 files changed, 28 insertions, 37 deletions
diff --git a/vespalib/src/vespa/vespalib/datastore/sharded_hash_map.cpp b/vespalib/src/vespa/vespalib/datastore/sharded_hash_map.cpp index 6bb372ff212..6dc8f55f3ee 100644 --- a/vespalib/src/vespa/vespalib/datastore/sharded_hash_map.cpp +++ b/vespalib/src/vespa/vespalib/datastore/sharded_hash_map.cpp @@ -12,7 +12,7 @@ class ShardedHashMapShardHeld : public GenerationHeldBase std::unique_ptr<const FixedSizeHashMap> _data; public: ShardedHashMapShardHeld(size_t size, std::unique_ptr<const FixedSizeHashMap> data); - ~ShardedHashMapShardHeld(); + ~ShardedHashMapShardHeld() override; }; ShardedHashMapShardHeld::ShardedHashMapShardHeld(size_t size, std::unique_ptr<const FixedSizeHashMap> data) @@ -40,7 +40,7 @@ ShardedHashMap::~ShardedHashMap() } size_t -ShardedHashMap::get_shard_idx(const EntryComparator& comp, EntryRef key_ref) const +ShardedHashMap::get_shard_idx(const EntryComparator& comp, EntryRef key_ref) { return comp.hash(key_ref) % num_shards; } diff --git a/vespalib/src/vespa/vespalib/datastore/sharded_hash_map.h b/vespalib/src/vespa/vespalib/datastore/sharded_hash_map.h index 30bbb2fbe4d..73ee8c05feb 100644 --- a/vespalib/src/vespa/vespalib/datastore/sharded_hash_map.h +++ b/vespalib/src/vespa/vespalib/datastore/sharded_hash_map.h @@ -5,6 +5,7 @@ #include "atomic_entry_ref.h" #include <atomic> #include <vespa/vespalib/util/generationholder.h> +#include <vespa/vespalib/stllike/string.h> #include <functional> namespace vespalib { class MemoryUsage; } @@ -41,7 +42,7 @@ private: std::atomic<FixedSizeHashMap *> _maps[num_shards]; std::unique_ptr<const EntryComparator> _comp; - size_t get_shard_idx(const EntryComparator& comp, EntryRef key_ref) const; + VESPA_DLL_LOCAL static size_t get_shard_idx(const EntryComparator& comp, EntryRef key_ref); void alloc_shard(size_t shard_idx); void hold_shard(std::unique_ptr<const FixedSizeHashMap> map); public: diff --git a/vespalib/src/vespa/vespalib/util/alloc.cpp b/vespalib/src/vespa/vespalib/util/alloc.cpp index b6003f43792..5f1faa785ba 100644 --- a/vespalib/src/vespa/vespalib/util/alloc.cpp +++ b/vespalib/src/vespa/vespalib/util/alloc.cpp @@ -467,32 +467,6 @@ MemoryAllocator::select_allocator(size_t mmapLimit, size_t alignment) { return & AutoAllocator::getAllocator(mmapLimit, alignment); } -Alloc::Alloc(const MemoryAllocator * allocator, size_t sz) noexcept - : _alloc(allocator->alloc(sz)), - _allocator(allocator) -{ -} - -void -Alloc::free() { - _allocator->free(_alloc); - _alloc.first = nullptr; -} - -Alloc& -Alloc::operator=(Alloc && rhs) noexcept -{ - if (this != & rhs) { - if (_alloc.first != nullptr) { - _allocator->free(_alloc); - } - _alloc = rhs._alloc; - _allocator = rhs._allocator; - rhs.clear(); - } - return *this; -} - Alloc Alloc::allocHeap(size_t sz) { diff --git a/vespalib/src/vespa/vespalib/util/alloc.h b/vespalib/src/vespa/vespalib/util/alloc.h index f1cb0fb0337..f608a244035 100644 --- a/vespalib/src/vespa/vespalib/util/alloc.h +++ b/vespalib/src/vespa/vespalib/util/alloc.h @@ -1,13 +1,12 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #pragma once -#include <vespa/vespalib/util/optimized.h> +#include "optimized.h" +#include "memory_allocator.h" #include <memory> namespace vespalib::alloc { -class MemoryAllocator; - /** * This represents an allocation. * It can be created, moved, swapped. @@ -41,11 +40,22 @@ public: { rhs.clear(); } - Alloc & operator=(Alloc && rhs) noexcept; + Alloc & operator=(Alloc && rhs) noexcept { + if (this != & rhs) { + if (_alloc.first != nullptr) { + _allocator->free(_alloc); + } + _alloc = rhs._alloc; + _allocator = rhs._allocator; + rhs.clear(); + } + return *this; + } Alloc() noexcept : _alloc(nullptr, 0), _allocator(nullptr) { } ~Alloc() { if (_alloc.first != nullptr) { - free(); + _allocator->free(_alloc); + _alloc.first = nullptr; } } void swap(Alloc & rhs) noexcept { @@ -69,14 +79,20 @@ public: static Alloc alloc() noexcept; static Alloc alloc_with_allocator(const MemoryAllocator* allocator) noexcept; private: - Alloc(const MemoryAllocator * allocator, size_t sz) noexcept; - Alloc(const MemoryAllocator * allocator) noexcept : _alloc(nullptr, 0), _allocator(allocator) { } + Alloc(const MemoryAllocator * allocator, size_t sz) noexcept + : _alloc(allocator->alloc(sz)), + _allocator(allocator) + { + } + Alloc(const MemoryAllocator * allocator) noexcept + : _alloc(nullptr, 0), + _allocator(allocator) + { } void clear() { _alloc.first = nullptr; _alloc.second = 0; _allocator = nullptr; } - void free(); PtrAndSize _alloc; const MemoryAllocator * _allocator; }; |