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

Unified Diff: compiled/StringMap.h

Issue 29556737: Issue 5141 - Convert filter match to C++ (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Fixed many issues. One test left out. Created Oct. 6, 2017, 1:45 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/StringMap.h
===================================================================
--- a/compiled/StringMap.h
+++ b/compiled/StringMap.h
@@ -112,32 +112,26 @@
void operator=(const HashContainer& other);
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;
+ size_type mExpectedEntries;
Wladimir Palant 2017/10/09 08:39:46 No point recalculating bucket count if the map is
#if defined(DEBUG)
size_type mInsertCounter;
#endif
explicit HashContainer(size_type expectedEntries = 0)
- : mEntryCount(0)
+ : mEntryCount(0), mExpectedEntries(expectedEntries)
{
- 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");
+ init(expectedEntries);
}
static size_type hash(const String& str)
{
// FNV-1a hash function
size_type result = 2166136261;
for (String::size_type i = 0; i < str.length(); i++)
result = (result ^ str[i]) * 16777619;
@@ -232,16 +226,35 @@
{
return const_iterator(&mBuckets[mBucketCount], &mBuckets[mBucketCount]);
}
size_type size() const
{
return mEntryCount;
}
+
+ void clear()
+ {
+ mEntryCount = 0;
+ init(mExpectedEntries);
Wladimir Palant 2017/10/09 08:39:45 IMHO, the shared function between constructor and
+ }
+
+ private:
+ void init(size_type expectedEntries)
+ {
+ 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");
+ }
};
struct StringSetEntry
{
StringSetEntry() {}
StringSetEntry(const String& key)
: first(key)
{

Powered by Google App Engine
This is Rietveld