@@ -59,7 +59,7 @@ private interface TreePart {
59
59
}
60
60
61
61
@ CompilerDirectives .ValueType
62
- public final static class Entry implements TreePart {
62
+ public static final class Entry implements TreePart {
63
63
final Object key ;
64
64
final int hash ;
65
65
final Object value ;
@@ -115,12 +115,12 @@ private static int bitmapToIdx(int bitmap, int position) {
115
115
}
116
116
}
117
117
118
- private static BitmapPart bitmapNodesForPair (TreePart one , int hashOne , TreePart two , int hashTwo , int hashShift ) {
119
- assert hashOne != hashTwo : "bitmapNodesForPair cannot work with colliding nodes" ;
118
+ private static BitmapPart bitmapPartsForPair (TreePart one , int hashOne , TreePart two , int hashTwo , int hashShift ) {
119
+ assert hashOne != hashTwo : "cannot work with colliding nodes" ;
120
120
int oneIdx = hashIdx (hashOne , hashShift );
121
121
int twoIdx = hashIdx (hashTwo , hashShift );
122
122
if (oneIdx == twoIdx ) {
123
- return new BitmapPart (new TreePart []{bitmapNodesForPair (one , hashOne , two , hashTwo , hashShift + 5 )}, idxToBit (twoIdx ));
123
+ return new BitmapPart (new TreePart []{bitmapPartsForPair (one , hashOne , two , hashTwo , hashShift + 5 )}, idxToBit (twoIdx ));
124
124
}
125
125
return new BitmapPart (oneIdx > twoIdx ? new TreePart []{one , two } : new TreePart []{two , one }, idxToBit (twoIdx ) | idxToBit (oneIdx ));
126
126
}
@@ -139,7 +139,7 @@ private static TreePart nodeWithEntry(TreePart original, Entry newEntry, int has
139
139
return new CollisionPart (existing .hash , existing , newEntry );
140
140
}
141
141
}
142
- return bitmapNodesForPair (newEntry , newEntry .hash , existing , existing .hash , hashShift );
142
+ return bitmapPartsForPair (newEntry , newEntry .hash , existing , existing .hash , hashShift );
143
143
}
144
144
if (original instanceof BitmapPart ) {
145
145
BitmapPart existing = (BitmapPart ) original ;
@@ -198,7 +198,7 @@ private static TreePart nodeWithEntry(TreePart original, Entry newEntry, int has
198
198
System .arraycopy (existing .elems , 0 , newElems , 0 , originalLength );
199
199
return new CollisionPart (existing .hash , newElems );
200
200
} else {
201
- return bitmapNodesForPair (existing , existing .hash , newEntry , newEntry .hash , hashShift );
201
+ return bitmapPartsForPair (existing , existing .hash , newEntry , newEntry .hash , hashShift );
202
202
}
203
203
}
204
204
throw CompilerDirectives .shouldNotReachHere ("TreePart type is not handled" );
@@ -255,59 +255,53 @@ public Object lookup(Object key, int hash) {
255
255
return lookupKeyInPart (root , key , hash , 0 );
256
256
}
257
257
258
- @ SuppressWarnings ("fallthrough" )
259
258
private static TreePart bitmapWithoutKey (BitmapPart existing , Object key , int hash , int hashShift ) {
260
259
int position = hashIdx (hash , hashShift );
261
260
int sparseIdx = bitmapToIdx (existing .bitmap , position );
262
261
if (sparseIdx < 0 ) {
263
262
return existing ;
264
263
}
265
264
TreePart replacement = partWithoutKey (existing .elems [sparseIdx ], key , hash , hashShift + 5 );
266
- switch (existing .elems .length ) {
267
- case 1 : {
268
- if (replacement == null ) {
269
- // if we have no elements, we can simply delete the BitmapPart entirely
270
- return null ;
271
- } else if (replacement instanceof Entry || replacement instanceof CollisionPart ) {
272
- // if the only element is an entry, we can simply skip the BitmapPart
273
- // we cannot do the same for the other TreeParts, since those rely on
274
- // depth to find which part of the hash is relevant to them.
275
- return replacement ;
276
- }
277
- // fall through to default
265
+ int currentLen = existing .elems .length ;
266
+ if (currentLen == 1 ) {
267
+ if (replacement == null ) {
268
+ // if we have no elements, we can simply delete the BitmapPart entirely
269
+ return null ;
270
+ } else if (replacement instanceof Entry || replacement instanceof CollisionPart ) {
271
+ // if the only element is an entry, we can simply skip the BitmapPart
272
+ // we cannot do the same for the other TreeParts, since those rely on
273
+ // depth to find which part of the hash is relevant to them.
274
+ return replacement ;
278
275
}
279
- case 2 : {
280
- if (replacement == null ) {
281
- // we have one element left, if it is an element which doesn't rely on its
282
- // depth,
283
- // return that element, otherwise, run the normal removal logic
284
- int otherIdx = sparseIdx == 0 ? 1 : 0 ;
285
- TreePart otherElem = existing .elems [otherIdx ];
286
- if (otherElem instanceof Entry || otherElem instanceof CollisionPart ) {
287
- return otherElem ;
288
- }
289
- }
290
- // fall through
276
+ // fall through to default
277
+ }
278
+ if (currentLen == 2 && replacement == null ) {
279
+ // we have one element left, if it is an element which doesn't rely on its
280
+ // depth,
281
+ // return that element, otherwise, run the normal removal logic
282
+ int otherIdx = sparseIdx == 0 ? 1 : 0 ;
283
+ TreePart otherElem = existing .elems [otherIdx ];
284
+ if (otherElem instanceof Entry || otherElem instanceof CollisionPart ) {
285
+ return otherElem ;
291
286
}
292
- default : {
293
- if (replacement == null ) {
294
- int newBitmap = existing .bitmap & ~idxToBit (position );
295
- TreePart [] newElems = new TreePart [existing .elems .length - 1 ];
296
- int newI = 0 ;
297
- for (int i = 0 ; i < existing .elems .length ; ++i ) {
298
- if (i != sparseIdx ) {
299
- newElems [newI ++] = existing .elems [i ];
300
- }
301
- }
302
- assert newI == newElems .length ;
303
- return new BitmapPart (newElems , newBitmap );
287
+ // fall through
288
+ }
289
+
290
+ if (replacement == null ) {
291
+ int newBitmap = existing .bitmap & ~idxToBit (position );
292
+ TreePart [] newElems = new TreePart [existing .elems .length - 1 ];
293
+ int newI = 0 ;
294
+ for (int i = 0 ; i < existing .elems .length ; ++i ) {
295
+ if (i != sparseIdx ) {
296
+ newElems [newI ++] = existing .elems [i ];
304
297
}
305
- TreePart [] newElems = existing .elems .clone ();
306
- newElems [sparseIdx ] = replacement ;
307
- return new BitmapPart (newElems , existing .bitmap );
308
298
}
299
+ assert newI == newElems .length ;
300
+ return new BitmapPart (newElems , newBitmap );
309
301
}
310
-
302
+ TreePart [] newElems = existing .elems .clone ();
303
+ newElems [sparseIdx ] = replacement ;
304
+ return new BitmapPart (newElems , existing .bitmap );
311
305
}
312
306
313
307
private static TreePart partWithoutKey (TreePart root , Object key , int hash , int hashShift ) {
@@ -326,7 +320,7 @@ private static TreePart partWithoutKey(TreePart root, Object key, int hash, int
326
320
return bitmapWithoutKey (existing , key , hash , hashShift );
327
321
}
328
322
if (root instanceof ArrayPart ) {
329
- ArrayPart existing = (ArrayPart ) root ;
323
+ ArrayPart existing = (ArrayPart ) root ;
330
324
int position = hashIdx (hash , hashShift );
331
325
TreePart replacement = partWithoutKey (existing .elems [position ], key , hash , hashShift + 5 );
332
326
if (replacement == null ) {
@@ -387,7 +381,7 @@ public Hamt without(Object key, int hash) {
387
381
return new Hamt (partWithoutKey (root , key , hash , 0 ));
388
382
}
389
383
390
- private final static class BitmapPart implements TreePart {
384
+ private static final class BitmapPart implements TreePart {
391
385
final int bitmap ;
392
386
final TreePart [] elems ;
393
387
@@ -413,7 +407,7 @@ public String dump(int indent) {
413
407
}
414
408
}
415
409
416
- private final static class ArrayPart implements TreePart {
410
+ private static final class ArrayPart implements TreePart {
417
411
final TreePart [] elems ;
418
412
419
413
public ArrayPart (TreePart [] elems ) {
@@ -433,7 +427,7 @@ public String dump(int indent) {
433
427
}
434
428
}
435
429
436
- private final static class CollisionPart implements TreePart {
430
+ private static final class CollisionPart implements TreePart {
437
431
final int hash ;
438
432
final Entry [] elems ;
439
433
0 commit comments