Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: compiled/Map.h

Issue 29677755: Issue 6279 - Make HashContainer movable and optimize resizing by moving entries. (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Forgot IntMap. Remove changes not needed. Minor fix. Created Jan. 24, 2018, 3:10 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « compiled/IntMap.h ('k') | compiled/StringMap.h » ('j') | compiled/StringMap.h » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: compiled/Map.h
===================================================================
--- a/compiled/Map.h
+++ b/compiled/Map.h
@@ -102,19 +102,21 @@
{
public:
typedef Entry entry_type;
typedef typename Entry::key_type_cref key_type_cref;
typedef typename entry_type::size_type size_type;
typedef HashContainerIterator<Entry> const_iterator;
typedef HashContainerReference<const Entry> const_reference;
- private:
- explicit HashContainer(const HashContainer& other);
- void operator=(const HashContainer& other);
+ explicit HashContainer(HashContainer&& other) = default;
+ HashContainer& operator=(HashContainer&&) = default;
+
+ explicit HashContainer(const HashContainer& other) = delete;
+ void operator=(const HashContainer& other) = delete;
protected:
static constexpr size_type MIN_BUCKETS = 1;
static constexpr double LOAD_FACTOR = 0.8;
std::unique_ptr<entry_type[]> mBuckets;
size_type mBucketCount;
size_type mEntryCount;
@@ -149,40 +151,53 @@
allocate();
// Copy old entries into the new buffer
for (size_type i = 0; i < oldCount; i++)
{
entry_type& entry = oldBuckets[i];
if (!entry.is_invalid() && !entry.is_deleted())
{
- *find_bucket(entry.first) = entry;
+ *find_bucket(entry.first) = std::move(entry);
mEntryCount++;
}
}
}
- entry_type* assign(entry_type* existing, const entry_type& entry)
+ entry_type* _assign(entry_type* existing, const entry_type& entry)
sergei 2018/01/24 18:37:12 We normally don't use underscores at the beginning
hub 2018/01/24 19:32:01 I'll call it "prepare_bucket" as we use it to ensu
{
if (existing->is_invalid())
{
if (mEntryCount + 1 >= mBucketCount * LOAD_FACTOR)
{
resize(mBucketCount << 1);
existing = find_bucket(entry.first);
}
mEntryCount++;
#if defined(DEBUG)
mInsertCounter++;
#endif
}
+ return existing;
+ }
+
+ entry_type* assign(entry_type* existing, const entry_type& entry)
+ {
+ existing = _assign(existing, entry);
*existing = entry;
return existing;
}
+ entry_type* assign(entry_type* existing, entry_type&& entry)
+ {
+ existing = _assign(existing, entry);
+ *existing = std::move(entry);
+ return existing;
+ }
+
void allocate()
{
mBuckets.reset(new entry_type[mBucketCount]);
// Working around https://github.com/waywardmonkeys/emscripten-trace-collector/issues/2 here
annotate_address(reinterpret_cast<size_type*>(mBuckets.get()) - 1, "Hash table buffer");
}
public:
« no previous file with comments | « compiled/IntMap.h ('k') | compiled/StringMap.h » ('j') | compiled/StringMap.h » ('J')

Powered by Google App Engine
This is Rietveld