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

Unified Diff: compiled/Map.h

Issue 29587914: Issue 5142 - Convert Element Hiding to C++ (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Re-added elemHide.js test. Fixed test failures related. Addresses review comments. Created Jan. 19, 2018, 2:02 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/ElemHide.cpp ('k') | compiled/String.h » ('j') | test/elemHide.js » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: compiled/Map.h
===================================================================
--- a/compiled/Map.h
+++ b/compiled/Map.h
@@ -141,19 +141,17 @@
void resize(size_type bucketCount)
{
std::unique_ptr<entry_type[]> oldBuckets(std::move(mBuckets));
size_type oldCount = mBucketCount;
mEntryCount = 0;
mBucketCount = bucketCount;
- 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");
+ 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;
@@ -175,28 +173,39 @@
#if defined(DEBUG)
mInsertCounter++;
#endif
}
*existing = 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:
explicit HashContainer(size_type expectedEntries = 0)
: mEntryCount(0)
{
expectedEntries = ceil(expectedEntries / LOAD_FACTOR);
mBucketCount = MIN_BUCKETS;
while (mBucketCount < expectedEntries)
mBucketCount <<= 1;
- 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");
+ allocate();
+ }
+
+ void clear()
+ {
+ mEntryCount = 0;
+ allocate();
}
void insert(const entry_type& entry)
{
assign(find_bucket(entry.first), entry);
}
bool erase(key_type_cref key)
« no previous file with comments | « compiled/ElemHide.cpp ('k') | compiled/String.h » ('j') | test/elemHide.js » ('J')

Powered by Google App Engine
This is Rietveld