LEFT | RIGHT |
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 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 { | 155 { |
156 entry_type& entry = oldBuckets[i]; | 156 entry_type& entry = oldBuckets[i]; |
157 if (!entry.is_invalid() && !entry.is_deleted()) | 157 if (!entry.is_invalid() && !entry.is_deleted()) |
158 { | 158 { |
159 *find_bucket(entry.first) = std::move(entry); | 159 *find_bucket(entry.first) = std::move(entry); |
160 mEntryCount++; | 160 mEntryCount++; |
161 } | 161 } |
162 } | 162 } |
163 } | 163 } |
164 | 164 |
165 entry_type* _assign(entry_type* existing, const entry_type& entry) | 165 // Prepare the bucket for assigning entry at key. |
| 166 entry_type* prepare_bucket(entry_type* existing, key_type_cref key) |
166 { | 167 { |
167 if (existing->is_invalid()) | 168 if (existing->is_invalid()) |
168 { | 169 { |
169 if (mEntryCount + 1 >= mBucketCount * LOAD_FACTOR) | 170 if (mEntryCount + 1 >= mBucketCount * LOAD_FACTOR) |
170 { | 171 { |
171 resize(mBucketCount << 1); | 172 resize(mBucketCount << 1); |
172 existing = find_bucket(entry.first); | 173 existing = find_bucket(key); |
173 } | 174 } |
174 mEntryCount++; | 175 mEntryCount++; |
175 #if defined(DEBUG) | 176 #if defined(DEBUG) |
176 mInsertCounter++; | 177 mInsertCounter++; |
177 #endif | 178 #endif |
178 } | 179 } |
179 return existing; | 180 return existing; |
180 } | 181 } |
181 | 182 |
182 entry_type* assign(entry_type* existing, const entry_type& entry) | 183 entry_type* assign(entry_type* existing, const entry_type& entry) |
183 { | 184 { |
184 existing = _assign(existing, entry); | 185 existing = prepare_bucket(existing, entry.first); |
185 *existing = entry; | 186 *existing = entry; |
186 return existing; | 187 return existing; |
187 } | 188 } |
188 | 189 |
189 entry_type* assign(entry_type* existing, entry_type&& entry) | 190 entry_type* assign(entry_type* existing, entry_type&& entry) |
190 { | 191 { |
191 existing = _assign(existing, entry); | 192 existing = prepare_bucket(existing, entry.first); |
192 *existing = std::move(entry); | 193 *existing = std::move(entry); |
193 return existing; | 194 return existing; |
194 } | 195 } |
195 | 196 |
196 void allocate() | 197 void allocate() |
197 { | 198 { |
198 mBuckets.reset(new entry_type[mBucketCount]); | 199 mBuckets.reset(new entry_type[mBucketCount]); |
199 // Working around https://github.com/waywardmonkeys/emscripten-trace-colle
ctor/issues/2 here | 200 // Working around https://github.com/waywardmonkeys/emscripten-trace-colle
ctor/issues/2 here |
200 annotate_address(reinterpret_cast<size_type*>(mBuckets.get()) - 1, "Hash t
able buffer"); | 201 annotate_address(reinterpret_cast<size_type*>(mBuckets.get()) - 1, "Hash t
able buffer"); |
201 } | 202 } |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 const_reference find(key_type_cref key) const | 330 const_reference find(key_type_cref key) const |
330 { | 331 { |
331 return super::find(key); | 332 return super::find(key); |
332 } | 333 } |
333 | 334 |
334 reference find(key_type_cref key) | 335 reference find(key_type_cref key) |
335 { | 336 { |
336 return reference(this, key, super::find_bucket(key)); | 337 return reference(this, key, super::find_bucket(key)); |
337 } | 338 } |
338 }; | 339 }; |
LEFT | RIGHT |