@@ -317,7 +317,8 @@ ref TValue AddKey(in ReadOnlySpan<byte> key, int bucketIndex, int hash)
317
317
_buckets [ oldbucketIndex ] = candidate . Next + 1 ;
318
318
}
319
319
320
- entries [ entryIndex ] = default ;
320
+ _freeBytes += candidate . Length ;
321
+ candidate = default ;
321
322
_count -- ;
322
323
break ;
323
324
}
@@ -338,9 +339,6 @@ ref TValue AddKey(in ReadOnlySpan<byte> key, int bucketIndex, int hash)
338
339
}
339
340
340
341
ref var entry = ref entries [ entryIndex ] ;
341
- entry . Hash = hash ;
342
- entry . Length = key . Length ;
343
- entry . Offset = _usedBytes ;
344
342
if ( _bytes . Length < _usedBytes + key . Length )
345
343
{
346
344
if ( _freeBytes >= _usedBytes >> 1 && _usedBytes - _freeBytes + key . Length <= _bytes . Length )
@@ -350,7 +348,7 @@ ref TValue AddKey(in ReadOnlySpan<byte> key, int bucketIndex, int hash)
350
348
_usedBytes = 0 ;
351
349
_freeBytes = 0 ;
352
350
var newBytes = new byte [ _bytes . Length ] ;
353
- for ( var i = 0 ; i < _count ; i ++ )
351
+ for ( var i = 0 ; i <= _count ; i ++ )
354
352
{
355
353
ref var e = ref entries [ i ] ;
356
354
if ( e . Next < - 1 )
@@ -370,9 +368,11 @@ ref TValue AddKey(in ReadOnlySpan<byte> key, int bucketIndex, int hash)
370
368
}
371
369
}
372
370
371
+ entry . Hash = hash ;
372
+ entry . Length = key . Length ;
373
+ entry . Offset = _usedBytes ;
373
374
key . CopyTo ( _bytes . AsSpan ( _usedBytes ) ) ;
374
375
_usedBytes += key . Length ;
375
-
376
376
entry . Next = _buckets [ bucketIndex ] - 1 ;
377
377
entry . UsagePrev = - 1 ;
378
378
entry . UsageNext = UsageHead ;
0 commit comments