Skip to content

Commit 798f3c2

Browse files
author
Adam Hrbac
committed
Fix style
1 parent 72b7faf commit 798f3c2

File tree

1 file changed

+45
-51
lines changed
  • graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/contextvars

1 file changed

+45
-51
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/contextvars/Hamt.java

Lines changed: 45 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ private interface TreePart {
5959
}
6060

6161
@CompilerDirectives.ValueType
62-
public final static class Entry implements TreePart {
62+
public static final class Entry implements TreePart {
6363
final Object key;
6464
final int hash;
6565
final Object value;
@@ -115,12 +115,12 @@ private static int bitmapToIdx(int bitmap, int position) {
115115
}
116116
}
117117

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";
120120
int oneIdx = hashIdx(hashOne, hashShift);
121121
int twoIdx = hashIdx(hashTwo, hashShift);
122122
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));
124124
}
125125
return new BitmapPart(oneIdx > twoIdx ? new TreePart[]{one, two} : new TreePart[]{two, one}, idxToBit(twoIdx) | idxToBit(oneIdx));
126126
}
@@ -139,7 +139,7 @@ private static TreePart nodeWithEntry(TreePart original, Entry newEntry, int has
139139
return new CollisionPart(existing.hash, existing, newEntry);
140140
}
141141
}
142-
return bitmapNodesForPair(newEntry, newEntry.hash, existing, existing.hash, hashShift);
142+
return bitmapPartsForPair(newEntry, newEntry.hash, existing, existing.hash, hashShift);
143143
}
144144
if (original instanceof BitmapPart) {
145145
BitmapPart existing = (BitmapPart) original;
@@ -198,7 +198,7 @@ private static TreePart nodeWithEntry(TreePart original, Entry newEntry, int has
198198
System.arraycopy(existing.elems, 0, newElems, 0, originalLength);
199199
return new CollisionPart(existing.hash, newElems);
200200
} else {
201-
return bitmapNodesForPair(existing, existing.hash, newEntry, newEntry.hash, hashShift);
201+
return bitmapPartsForPair(existing, existing.hash, newEntry, newEntry.hash, hashShift);
202202
}
203203
}
204204
throw CompilerDirectives.shouldNotReachHere("TreePart type is not handled");
@@ -255,59 +255,53 @@ public Object lookup(Object key, int hash) {
255255
return lookupKeyInPart(root, key, hash, 0);
256256
}
257257

258-
@SuppressWarnings("fallthrough")
259258
private static TreePart bitmapWithoutKey(BitmapPart existing, Object key, int hash, int hashShift) {
260259
int position = hashIdx(hash, hashShift);
261260
int sparseIdx = bitmapToIdx(existing.bitmap, position);
262261
if (sparseIdx < 0) {
263262
return existing;
264263
}
265264
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;
278275
}
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;
291286
}
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];
304297
}
305-
TreePart[] newElems = existing.elems.clone();
306-
newElems[sparseIdx] = replacement;
307-
return new BitmapPart(newElems, existing.bitmap);
308298
}
299+
assert newI == newElems.length;
300+
return new BitmapPart(newElems, newBitmap);
309301
}
310-
302+
TreePart[] newElems = existing.elems.clone();
303+
newElems[sparseIdx] = replacement;
304+
return new BitmapPart(newElems, existing.bitmap);
311305
}
312306

313307
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
326320
return bitmapWithoutKey(existing, key, hash, hashShift);
327321
}
328322
if (root instanceof ArrayPart) {
329-
ArrayPart existing = (ArrayPart) root;
323+
ArrayPart existing = (ArrayPart) root;
330324
int position = hashIdx(hash, hashShift);
331325
TreePart replacement = partWithoutKey(existing.elems[position], key, hash, hashShift + 5);
332326
if (replacement == null) {
@@ -387,7 +381,7 @@ public Hamt without(Object key, int hash) {
387381
return new Hamt(partWithoutKey(root, key, hash, 0));
388382
}
389383

390-
private final static class BitmapPart implements TreePart {
384+
private static final class BitmapPart implements TreePart {
391385
final int bitmap;
392386
final TreePart[] elems;
393387

@@ -413,7 +407,7 @@ public String dump(int indent) {
413407
}
414408
}
415409

416-
private final static class ArrayPart implements TreePart {
410+
private static final class ArrayPart implements TreePart {
417411
final TreePart[] elems;
418412

419413
public ArrayPart(TreePart[] elems) {
@@ -433,7 +427,7 @@ public String dump(int indent) {
433427
}
434428
}
435429

436-
private final static class CollisionPart implements TreePart {
430+
private static final class CollisionPart implements TreePart {
437431
final int hash;
438432
final Entry[] elems;
439433

0 commit comments

Comments
 (0)