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

Side by Side Diff: compiled/Map.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.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « compiled/ElemHide.cpp ('k') | compiled/StringMap.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-present eyeo GmbH 3 * Copyright (C) 2006-present eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 } 138 }
139 } 139 }
140 140
141 void resize(size_type bucketCount) 141 void resize(size_type bucketCount)
142 { 142 {
143 std::unique_ptr<entry_type[]> oldBuckets(std::move(mBuckets)); 143 std::unique_ptr<entry_type[]> oldBuckets(std::move(mBuckets));
144 size_type oldCount = mBucketCount; 144 size_type oldCount = mBucketCount;
145 145
146 mEntryCount = 0; 146 mEntryCount = 0;
147 mBucketCount = bucketCount; 147 mBucketCount = bucketCount;
148 mBuckets.reset(new entry_type[mBucketCount]); 148 allocate();
149 // Working around https://github.com/waywardmonkeys/emscripten-trace-colle ctor/issues/2 here
150 annotate_address(reinterpret_cast<size_type*>(mBuckets.get()) - 1, "Hash t able buffer");
151 149
152 // Copy old entries into the new buffer 150 // Copy old entries into the new buffer
153 for (size_type i = 0; i < oldCount; i++) 151 for (size_type i = 0; i < oldCount; i++)
154 { 152 {
155 entry_type& entry = oldBuckets[i]; 153 entry_type& entry = oldBuckets[i];
156 if (!entry.is_invalid() && !entry.is_deleted()) 154 if (!entry.is_invalid() && !entry.is_deleted())
157 { 155 {
158 *find_bucket(entry.first) = entry; 156 *find_bucket(entry.first) = entry;
159 mEntryCount++; 157 mEntryCount++;
160 } 158 }
(...skipping 11 matching lines...) Expand all
172 } 170 }
173 mEntryCount++; 171 mEntryCount++;
174 #if defined(DEBUG) 172 #if defined(DEBUG)
175 mInsertCounter++; 173 mInsertCounter++;
176 #endif 174 #endif
177 } 175 }
178 *existing = entry; 176 *existing = entry;
179 return existing; 177 return existing;
180 } 178 }
181 179
180 void allocate()
181 {
182 mBuckets.reset(new entry_type[mBucketCount]);
183 // Working around https://github.com/waywardmonkeys/emscripten-trace-colle ctor/issues/2 here
184 annotate_address(reinterpret_cast<size_type*>(mBuckets.get()) - 1, "Hash t able buffer");
185 }
186
182 public: 187 public:
183 explicit HashContainer(size_type expectedEntries = 0) 188 explicit HashContainer(size_type expectedEntries = 0)
184 : mEntryCount(0) 189 : mEntryCount(0)
185 { 190 {
186 expectedEntries = ceil(expectedEntries / LOAD_FACTOR); 191 expectedEntries = ceil(expectedEntries / LOAD_FACTOR);
187 mBucketCount = MIN_BUCKETS; 192 mBucketCount = MIN_BUCKETS;
188 while (mBucketCount < expectedEntries) 193 while (mBucketCount < expectedEntries)
189 mBucketCount <<= 1; 194 mBucketCount <<= 1;
190 195
191 mBuckets.reset(new entry_type[mBucketCount]); 196 allocate();
192 // Working around https://github.com/waywardmonkeys/emscripten-trace-colle ctor/issues/2 here 197 }
193 annotate_address(reinterpret_cast<size_type*>(mBuckets.get()) - 1, "Hash t able buffer"); 198
199 void clear()
200 {
201 mEntryCount = 0;
202 allocate();
194 } 203 }
195 204
196 void insert(const entry_type& entry) 205 void insert(const entry_type& entry)
197 { 206 {
198 assign(find_bucket(entry.first), entry); 207 assign(find_bucket(entry.first), entry);
199 } 208 }
200 209
201 bool erase(const key_type& key) 210 bool erase(const key_type& key)
202 { 211 {
203 entry_type* entry = find_bucket(key); 212 entry_type* entry = find_bucket(key);
(...skipping 12 matching lines...) Expand all
216 const_iterator begin() const 225 const_iterator begin() const
217 { 226 {
218 return const_iterator(&mBuckets[0], &mBuckets[mBucketCount]); 227 return const_iterator(&mBuckets[0], &mBuckets[mBucketCount]);
219 } 228 }
220 229
221 const_iterator end() const 230 const_iterator end() const
222 { 231 {
223 return const_iterator(&mBuckets[mBucketCount], &mBuckets[mBucketCount]); 232 return const_iterator(&mBuckets[mBucketCount], &mBuckets[mBucketCount]);
224 } 233 }
225 234
235 bool empty() const
236 {
237 return mEntryCount == 0;
238 }
239
226 size_type size() const 240 size_type size() const
227 { 241 {
228 return mEntryCount; 242 return mEntryCount;
229 } 243 }
230 }; 244 };
231 245
232 template<typename Entry> 246 template<typename Entry>
233 struct MapReference : public HashContainerReference<Entry> 247 struct MapReference : public HashContainerReference<Entry>
234 { 248 {
235 typedef HashContainerReference<Entry> super; 249 typedef HashContainerReference<Entry> super;
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 const_reference find(const key_type& key) const 324 const_reference find(const key_type& key) const
311 { 325 {
312 return super::find(key); 326 return super::find(key);
313 } 327 }
314 328
315 reference find(const key_type& key) 329 reference find(const key_type& key)
316 { 330 {
317 return reference(this, key, super::find_bucket(key)); 331 return reference(this, key, super::find_bucket(key));
318 } 332 }
319 }; 333 };
OLDNEW
« no previous file with comments | « compiled/ElemHide.cpp ('k') | compiled/StringMap.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld