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: remove more unused ctor Created Jan. 25, 2018, 3:10 p.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') | no next file with comments »
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,54 @@
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)
+ // Prepare the bucket for assigning entry at key.
+ entry_type* prepare_bucket(entry_type* existing, key_type_cref key)
{
if (existing->is_invalid())
{
if (mEntryCount + 1 >= mBucketCount * LOAD_FACTOR)
{
resize(mBucketCount << 1);
- existing = find_bucket(entry.first);
+ existing = find_bucket(key);
}
mEntryCount++;
#if defined(DEBUG)
mInsertCounter++;
#endif
}
+ return existing;
+ }
+
+ entry_type* assign(entry_type* existing, const entry_type& entry)
+ {
+ existing = prepare_bucket(existing, entry.first);
*existing = entry;
return existing;
}
+ entry_type* assign(entry_type* existing, entry_type&& entry)
+ {
+ existing = prepare_bucket(existing, entry.first);
+ *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') | no next file with comments »

Powered by Google App Engine
This is Rietveld