@@ -163,10 +163,10 @@ private void tryMakeAvailable(int indexToMakeAvailable) {
163
163
164
164
PooledObject <T > toMove = partitionedList .get (indexToMakeAvailable );
165
165
PooledObject <T > other = partitionedList .get (unavailableStartIndex );
166
- partitionedList .set (indexToMakeAvailable , other );
167
- partitionedList .set (unavailableStartIndex , toMove );
168
166
toMove .index (unavailableStartIndex );
169
167
other .index (indexToMakeAvailable );
168
+ partitionedList .set (other .index (), other );
169
+ partitionedList .set (toMove .index (), toMove );
170
170
this .unavailableStartIndex ++;
171
171
}
172
172
@@ -180,23 +180,21 @@ private void tryMakeUnavailable(int indexToMakeUnavailable) {
180
180
indexToMakeUnavailable < partitionedList .size (),
181
181
"Index to make unavailable should be < elements.size()" );
182
182
183
- final int unavailableStartIndex = this .unavailableStartIndex ;
184
-
185
183
if (indexToMakeUnavailable >= unavailableStartIndex ) {
186
184
// This index is already unavailable!
187
185
return ;
188
186
}
187
+ final int newUnavailableStartIndex = this .unavailableStartIndex - 1 ;
189
188
if (partitionedList .get (indexToMakeUnavailable ).activeLeases < hardMaxLeasesPerObject ) {
190
189
// Object at index has not reached the hard max leases yet. So it cannot be made unavailable
191
190
return ;
192
191
}
193
192
PooledObject <T > toMove = partitionedList .get (indexToMakeUnavailable );
194
- int otherIndex = unavailableStartIndex - 1 ;
195
- PooledObject <T > other = partitionedList .get (otherIndex );
196
- partitionedList .set (indexToMakeUnavailable , other );
197
- partitionedList .set (otherIndex , toMove );
198
- toMove .index (unavailableStartIndex );
193
+ PooledObject <T > other = partitionedList .get (newUnavailableStartIndex );
199
194
other .index (indexToMakeUnavailable );
195
+ toMove .index (newUnavailableStartIndex );
196
+ partitionedList .set (other .index (), other );
197
+ partitionedList .set (toMove .index (), toMove );
200
198
this .unavailableStartIndex --;
201
199
}
202
200
0 commit comments