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

Unified Diff: compiled/StringMap.h

Issue 29587914: Issue 5142 - Convert Element Hiding to C++ (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Add proper delete for filters in tests. Created Nov. 8, 2017, 12: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/Map.h ('k') | compiled/bindings/main.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: compiled/StringMap.h
===================================================================
--- a/compiled/StringMap.h
+++ b/compiled/StringMap.h
@@ -17,24 +17,38 @@
#pragma once
#include <cstddef>
#include "Map.h"
#include "String.h"
+class StringHash
+{
+public:
+ size_t operator()(const String& key) const
+ {
+ // FNV-1a hash function
+ size_t result = 2166136261;
+ for (size_t i = 0; i < key.length(); i++)
+ result = (result ^ key[i]) * 16777619;
+ return result;
+ }
+};
+
namespace StringMap_internal
{
struct StringSetEntry
{
typedef String key_type;
typedef size_t size_type;
DependentString first;
+ static StringHash hashFunctor;
StringSetEntry(const key_type& key = DependentString())
{
if (!key.is_invalid())
first.reset(key);
}
bool equals(const key_type& other) const
@@ -54,21 +68,17 @@
void erase()
{
first.erase();
}
static size_type hash(const key_type& key)
{
- // FNV-1a hash function
- size_type result = 2166136261;
- for (String::size_type i = 0; i < key.length(); i++)
- result = (result ^ key[i]) * 16777619;
- return result;
+ return hashFunctor(key);
}
};
template<typename Value>
struct StringMapEntry : StringSetEntry
{
typedef StringSetEntry super;
typedef Value value_type;
« no previous file with comments | « compiled/Map.h ('k') | compiled/bindings/main.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld