@@ -86,7 +86,8 @@ private Entry getEntry(int index) {
8686 } else if (gapCount == 0 || index < firstGapPosition ) {
8787 return (Entry ) entries [index ];
8888 }
89- return partialCompact (index );
89+ partialCompact (index );
90+ return (Entry ) entries [index ];
9091 }
9192
9293 /**
@@ -103,10 +104,10 @@ void compact() {
103104 /**
104105 * Avoid calling this when {@code gapCount == 0}.
105106 */
106- private Entry partialCompact (int rightBoundaryPosition ) {
107+ private void partialCompact (int rightBoundaryPosition ) {
107108 if (rightBoundaryPosition < firstGapPosition ) {
108109 // The entire target range is in the already-compacted prefix; no work needed.
109- return ( Entry ) entries [ rightBoundaryPosition ] ;
110+ return ;
110111 }
111112 var encounteredGaps = 0 ;
112113 var lastNonNullPosition = firstGapPosition - 1 ; // firstGapPosition non-nulls are already in place before us.
@@ -131,7 +132,7 @@ private Entry partialCompact(int rightBoundaryPosition) {
131132 } else {
132133 firstGapPosition = rightBoundaryPosition + 1 ;
133134 }
134- return entry ;
135+ return ;
135136 }
136137 }
137138 }
@@ -174,7 +175,7 @@ public void add(int index, T element) {
174175 }
175176 // Compact prefix [0, index-1] so physical position k == logical position k for all k < index.
176177 if (index > 0 ) {
177- partialCompact (index - 1 ); // Increases modCount.
178+ partialCompact (index - 1 );
178179 }
179180 if (entries [index ] == null ) {
180181 // Gap at the target position: fill it directly without shifting the array.
@@ -385,7 +386,9 @@ private ElementAwareListIterator(int startingPosition) {
385386 "The index (%d) must be >= 0 and <= size (%d)." .formatted (startingPosition , currentSize ));
386387 }
387388 if (startingPosition > 0 && gapCount > 0 ) {
388- currentPosition = partialCompact (startingPosition - 1 ).position + 1 ;
389+ var index = startingPosition - 1 ;
390+ partialCompact (index );
391+ currentPosition = ((Entry ) entries [index ]).position + 1 ;
389392 } else {
390393 currentPosition = startingPosition ;
391394 }
0 commit comments