@@ -209,7 +209,7 @@ class HashMapBuffer {
209
209
return bitwise_cast<BucketType**>(this);
210
210
}
211
211
212
- static HashMapBuffer* create (JSGlobalObject* globalObject, VM& vm, JSCell* , uint32_t capacity)
212
+ static HashMapBuffer* tryCreate (JSGlobalObject* globalObject, VM& vm, uint32_t capacity)
213
213
{
214
214
auto scope = DECLARE_THROW_SCOPE(vm);
215
215
size_t allocationSize = HashMapBuffer::allocationSize(capacity);
@@ -239,7 +239,7 @@ ALWAYS_INLINE uint32_t wangsInt64Hash(uint64_t key);
239
239
ALWAYS_INLINE uint32_t jsMapHash(JSBigInt*);
240
240
ALWAYS_INLINE uint32_t jsMapHash(JSGlobalObject*, VM&, JSValue);
241
241
ALWAYS_INLINE uint32_t shouldShrink(uint32_t capacity, uint32_t keyCount);
242
- ALWAYS_INLINE uint32_t shouldRehashAfterAdd (uint32_t capacity, uint32_t keyCount, uint32_t deleteCount);
242
+ ALWAYS_INLINE uint32_t shouldRehash (uint32_t capacity, uint32_t keyCount, uint32_t deleteCount);
243
243
ALWAYS_INLINE uint32_t nextCapacity(uint32_t capacity, uint32_t keyCount);
244
244
245
245
template <typename HashMapBucketType>
@@ -256,28 +256,15 @@ class HashMapImpl : public JSNonFinalObject {
256
256
257
257
HashMapImpl(VM& vm, Structure* structure)
258
258
: Base(vm, structure)
259
- , m_keyCount(0)
260
- , m_deleteCount(0)
261
- , m_capacity(4)
262
259
{
263
260
}
264
261
265
- HashMapImpl(VM& vm, Structure* structure, uint32_t sizeHint)
266
- : Base(vm, structure)
267
- , m_keyCount(0)
268
- , m_deleteCount(0)
269
- {
270
- uint32_t capacity = (Checked<uint32_t>(sizeHint) * 2) + 1;
271
- capacity = std::max<uint32_t>(WTF::roundUpToPowerOfTwo(capacity), 4U);
272
- m_capacity = capacity;
273
- }
274
-
275
262
ALWAYS_INLINE HashMapBucketType** buffer() const
276
263
{
277
264
return m_buffer->buffer();
278
265
}
279
266
280
- void finishCreation(JSGlobalObject*, VM&);
267
+ void finishCreation(VM&);
281
268
void finishCreation(JSGlobalObject*, VM&, HashMapImpl* base);
282
269
283
270
static HashMapBucketType* emptyValue()
@@ -320,7 +307,7 @@ class HashMapImpl : public JSNonFinalObject {
320
307
return m_keyCount;
321
308
}
322
309
323
- ALWAYS_INLINE void clear(JSGlobalObject* );
310
+ ALWAYS_INLINE void clear(VM& );
324
311
325
312
ALWAYS_INLINE size_t bufferSizeInBytes() const
326
313
{
@@ -355,42 +342,39 @@ class HashMapImpl : public JSNonFinalObject {
355
342
}
356
343
357
344
private:
358
- ALWAYS_INLINE uint32_t shouldRehashAfterAdd() const
359
- {
360
- return JSC::shouldRehashAfterAdd(m_capacity, m_keyCount, m_deleteCount);
361
- }
362
-
363
345
ALWAYS_INLINE uint32_t shouldShrink() const
364
346
{
365
347
return JSC::shouldShrink(m_capacity, m_keyCount);
366
348
}
367
349
368
- ALWAYS_INLINE void setUpHeadAndTail(JSGlobalObject*, VM&);
350
+ ALWAYS_INLINE void setUpHeadAndTail(VM&);
369
351
370
352
ALWAYS_INLINE void addNormalizedNonExistingForCloning(JSGlobalObject*, JSValue key, JSValue = JSValue());
353
+ ALWAYS_INLINE HashMapBucketType* addNormalizedNonExistingForCloningInternal(JSGlobalObject*, JSValue key, JSValue, uint32_t hash);
371
354
372
355
template<typename CanUseBucket>
373
356
ALWAYS_INLINE void addNormalizedInternal(JSGlobalObject*, JSValue key, JSValue, const CanUseBucket&);
374
357
375
358
template<typename CanUseBucket>
376
- ALWAYS_INLINE HashMapBucketType* addNormalizedInternal(VM& , JSValue key, JSValue, uint32_t hash, const CanUseBucket&);
359
+ ALWAYS_INLINE HashMapBucketType* addNormalizedInternal(JSGlobalObject* , JSValue key, JSValue, uint32_t hash, const CanUseBucket&);
377
360
378
361
ALWAYS_INLINE HashMapBucketType** findBucketAlreadyHashedAndNormalized(JSGlobalObject*, JSValue key, uint32_t hash);
379
362
380
- void rehash(JSGlobalObject*);
363
+ enum class RehashMode { BeforeAddition, AfterRemoval };
364
+ void rehash(JSGlobalObject*, RehashMode);
381
365
382
366
ALWAYS_INLINE void checkConsistency() const;
383
367
384
- void makeAndSetNewBuffer(JSGlobalObject*, VM&);
368
+ void makeAndSetNewBuffer(JSGlobalObject*, uint32_t newCapacity, VM&);
385
369
386
- ALWAYS_INLINE void assertBufferIsEmpty() const ;
370
+ ALWAYS_INLINE static void assertBufferIsEmpty(HashMapBucketType**, uint32_t capacity) ;
387
371
388
372
WriteBarrier<HashMapBucketType> m_head;
389
373
WriteBarrier<HashMapBucketType> m_tail;
390
374
AuxiliaryBarrier<HashMapBufferType*> m_buffer;
391
- uint32_t m_keyCount;
392
- uint32_t m_deleteCount;
393
- uint32_t m_capacity;
375
+ uint32_t m_keyCount { 0 } ;
376
+ uint32_t m_deleteCount { 0 } ;
377
+ uint32_t m_capacity { 0 } ;
394
378
};
395
379
396
380
} // namespace JSC
0 commit comments