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: Rebased on master. Created Dec. 5, 2017, 6:01 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
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)
@@ -219,16 +228,21 @@
return const_iterator(&mBuckets[0], &mBuckets[mBucketCount]);
}
const_iterator end() const
{
return const_iterator(&mBuckets[mBucketCount], &mBuckets[mBucketCount]);
}
+ bool empty() const
sergei 2018/01/15 15:31:19 What about renaming of `empty` and `size` methods
hub 2018/01/16 02:57:39 I'm willing to not add empty() and use size() == 0
sergei 2018/01/16 16:43:58 As I see it's really used as !((filter.GetDomains
+ {
+ return mEntryCount == 0;
+ }
+
size_type size() const
{
return mEntryCount;
}
};
template<typename Entry>
struct MapReference : public HashContainerReference<Entry>

Powered by Google App Engine
This is Rietveld