Skip to content

Commit 3e73923

Browse files
committed
Check style refactoring.
1 parent 46d6f2f commit 3e73923

File tree

1 file changed

+14
-19
lines changed
  • graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/list

1 file changed

+14
-19
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/list/ListBuiltins.java

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -507,39 +507,34 @@ public abstract static class ListInsertNode extends PythonBuiltinNode {
507507
@Specialization(guards = "isIntStorage(list)")
508508
public PNone insertIntInt(PList list, int index, int value) {
509509
IntSequenceStorage target = (IntSequenceStorage) list.getSequenceStorage();
510-
index = normalizeIndex(index, list.len());
511-
target.insertIntItem(index, value);
510+
target.insertIntItem(normalizeIndex(index, list.len()), value);
512511
return PNone.NONE;
513512
}
514513

515514
@Specialization(guards = "isLongStorage(list)")
516515
public PNone insertLongLong(PList list, int index, int value) {
517516
LongSequenceStorage target = (LongSequenceStorage) list.getSequenceStorage();
518-
index = normalizeIndex(index, list.len());
519-
target.insertLongItem(index, value);
517+
target.insertLongItem(normalizeIndex(index, list.len()), value);
520518
return PNone.NONE;
521519
}
522520

523521
@Specialization(guards = "isLongStorage(list)")
524522
public PNone insertLongLong(PList list, int index, long value) {
525523
LongSequenceStorage target = (LongSequenceStorage) list.getSequenceStorage();
526-
index = normalizeIndex(index, list.len());
527-
target.insertLongItem(index, value);
524+
target.insertLongItem(normalizeIndex(index, list.len()), value);
528525
return PNone.NONE;
529526
}
530527

531528
@Specialization(guards = "isDoubleStorage(list)")
532529
public PNone insertDoubleDouble(PList list, int index, double value) {
533530
DoubleSequenceStorage target = (DoubleSequenceStorage) list.getSequenceStorage();
534-
index = normalizeIndex(index, list.len());
535-
target.insertDoubleItem(index, value);
531+
target.insertDoubleItem(normalizeIndex(index, list.len()), value);
536532
return PNone.NONE;
537533
}
538534

539535
@Specialization(guards = "isNotSpecialCase(list, value)")
540536
public PNone insert(PList list, int index, Object value) {
541-
index = normalizeIndex(index, list.len());
542-
list.insert(index, value);
537+
list.insert(normalizeIndex(index, list.len()), value);
543538
return PNone.NONE;
544539
}
545540

@@ -551,7 +546,6 @@ public PNone insert(PList list, PInt index, Object value) {
551546
}
552547

553548
@Specialization(guards = {"!isIntegerOrPInt(i)"})
554-
@SuppressWarnings("unused")
555549
public PNone insert(PList list, Object i, Object value,
556550
@Cached("create(__INDEX__)") LookupAndCallUnaryNode indexNode,
557551
@Cached("createListInsertNode()") ListInsertNode insertNode) {
@@ -562,17 +556,18 @@ public PNone insert(PList list, Object i, Object value,
562556
return insertNode.execute(list, indexValue, value);
563557
}
564558

565-
private int normalizeIndex(int index, int len) {
566-
if (index < 0) {
567-
index += len;
568-
if (index < 0) {
569-
index = 0;
559+
private static int normalizeIndex(int index, int len) {
560+
int idx = index;
561+
if (idx < 0) {
562+
idx += len;
563+
if (idx < 0) {
564+
idx = 0;
570565
}
571566
}
572-
if (index > len) {
573-
index = len;
567+
if (idx > len) {
568+
idx = len;
574569
}
575-
return index;
570+
return idx;
576571
}
577572

578573
protected boolean isNotSpecialCase(PList list, Object value) {

0 commit comments

Comments
 (0)