author | lagergren |
Fri, 26 Sep 2014 18:47:20 +0200 | |
changeset 26886 | 18c744ab4df2 |
parent 26768 | 751b0f427090 |
child 27098 | 2875b30458d3 |
permissions | -rw-r--r-- |
16147 | 1 |
/* |
16151 | 2 |
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. |
16147 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
||
26 |
package jdk.nashorn.internal.runtime.arrays; |
|
27 |
||
28 |
import java.util.Arrays; |
|
29 |
import java.util.Map; |
|
30 |
import java.util.TreeMap; |
|
24719 | 31 |
import jdk.nashorn.internal.codegen.types.Type; |
16147 | 32 |
import jdk.nashorn.internal.runtime.JSType; |
33 |
import jdk.nashorn.internal.runtime.ScriptRuntime; |
|
34 |
||
35 |
/** |
|
36 |
* Handle arrays where the index is very large. |
|
37 |
*/ |
|
38 |
class SparseArrayData extends ArrayData { |
|
24719 | 39 |
static final long MAX_DENSE_LENGTH = 16 * 512 * 1024; |
16147 | 40 |
|
41 |
/** Underlying array. */ |
|
42 |
private ArrayData underlying; |
|
43 |
||
44 |
/** Maximum length to be stored in the array. */ |
|
45 |
private final long maxDenseLength; |
|
46 |
||
47 |
/** Sparse elements. */ |
|
19236
73d242d205f9
8020132: Big object literal with numerical keys exceeds method size
hannesw
parents:
18606
diff
changeset
|
48 |
private TreeMap<Long, Object> sparseMap; |
16147 | 49 |
|
19236
73d242d205f9
8020132: Big object literal with numerical keys exceeds method size
hannesw
parents:
18606
diff
changeset
|
50 |
SparseArrayData(final ArrayData underlying, final long length) { |
73d242d205f9
8020132: Big object literal with numerical keys exceeds method size
hannesw
parents:
18606
diff
changeset
|
51 |
this(underlying, length, new TreeMap<Long, Object>()); |
73d242d205f9
8020132: Big object literal with numerical keys exceeds method size
hannesw
parents:
18606
diff
changeset
|
52 |
} |
73d242d205f9
8020132: Big object literal with numerical keys exceeds method size
hannesw
parents:
18606
diff
changeset
|
53 |
|
73d242d205f9
8020132: Big object literal with numerical keys exceeds method size
hannesw
parents:
18606
diff
changeset
|
54 |
SparseArrayData(final ArrayData underlying, final long length, final TreeMap<Long, Object> sparseMap) { |
73d242d205f9
8020132: Big object literal with numerical keys exceeds method size
hannesw
parents:
18606
diff
changeset
|
55 |
super(length); |
26886
18c744ab4df2
8059211: Changed ArrayData.length accessor to use the protected field and fixed javadoc warnings related to this
lagergren
parents:
26768
diff
changeset
|
56 |
assert underlying.length <= length; |
16147 | 57 |
this.underlying = underlying; |
26886
18c744ab4df2
8059211: Changed ArrayData.length accessor to use the protected field and fixed javadoc warnings related to this
lagergren
parents:
26768
diff
changeset
|
58 |
this.maxDenseLength = Math.max(MAX_DENSE_LENGTH, underlying.length); |
19236
73d242d205f9
8020132: Big object literal with numerical keys exceeds method size
hannesw
parents:
18606
diff
changeset
|
59 |
this.sparseMap = sparseMap; |
16147 | 60 |
} |
61 |
||
19236
73d242d205f9
8020132: Big object literal with numerical keys exceeds method size
hannesw
parents:
18606
diff
changeset
|
62 |
@Override |
73d242d205f9
8020132: Big object literal with numerical keys exceeds method size
hannesw
parents:
18606
diff
changeset
|
63 |
public ArrayData copy() { |
26886
18c744ab4df2
8059211: Changed ArrayData.length accessor to use the protected field and fixed javadoc warnings related to this
lagergren
parents:
26768
diff
changeset
|
64 |
return new SparseArrayData(underlying.copy(), length, new TreeMap<>(sparseMap)); |
16147 | 65 |
} |
66 |
||
67 |
@Override |
|
68 |
public Object[] asObjectArray() { |
|
26886
18c744ab4df2
8059211: Changed ArrayData.length accessor to use the protected field and fixed javadoc warnings related to this
lagergren
parents:
26768
diff
changeset
|
69 |
final int len = (int)Math.min(length, Integer.MAX_VALUE); |
18c744ab4df2
8059211: Changed ArrayData.length accessor to use the protected field and fixed javadoc warnings related to this
lagergren
parents:
26768
diff
changeset
|
70 |
final int underlyingLength = (int)Math.min(len, underlying.length); |
18c744ab4df2
8059211: Changed ArrayData.length accessor to use the protected field and fixed javadoc warnings related to this
lagergren
parents:
26768
diff
changeset
|
71 |
final Object[] objArray = new Object[len]; |
16147 | 72 |
|
18318
5e4244619d79
8012291: NativeArray is inconsistent in using long for length and index in some places and int for the same in other places
hannesw
parents:
17241
diff
changeset
|
73 |
for (int i = 0; i < underlyingLength; i++) { |
16147 | 74 |
objArray[i] = underlying.getObject(i); |
75 |
} |
|
76 |
||
26886
18c744ab4df2
8059211: Changed ArrayData.length accessor to use the protected field and fixed javadoc warnings related to this
lagergren
parents:
26768
diff
changeset
|
77 |
Arrays.fill(objArray, underlyingLength, len, ScriptRuntime.UNDEFINED); |
16147 | 78 |
|
79 |
for (final Map.Entry<Long, Object> entry : sparseMap.entrySet()) { |
|
80 |
final long key = entry.getKey(); |
|
81 |
if (key <= Integer.MAX_VALUE) { |
|
82 |
objArray[(int)key] = entry.getValue(); |
|
83 |
} else { |
|
84 |
break; // ascending key order |
|
85 |
} |
|
86 |
} |
|
87 |
||
88 |
return objArray; |
|
89 |
} |
|
90 |
||
91 |
@Override |
|
92 |
public void shiftLeft(final int by) { |
|
93 |
underlying.shiftLeft(by); |
|
94 |
||
95 |
final TreeMap<Long, Object> newSparseMap = new TreeMap<>(); |
|
96 |
||
97 |
for (final Map.Entry<Long, Object> entry : sparseMap.entrySet()) { |
|
98 |
final long newIndex = entry.getKey().longValue() - by; |
|
99 |
if (newIndex < maxDenseLength) { |
|
100 |
underlying = underlying.set((int) newIndex, entry.getValue(), false); |
|
101 |
} else if (newIndex >= 0) { |
|
102 |
newSparseMap.put(Long.valueOf(newIndex), entry.getValue()); |
|
103 |
} |
|
104 |
} |
|
105 |
||
106 |
sparseMap = newSparseMap; |
|
26886
18c744ab4df2
8059211: Changed ArrayData.length accessor to use the protected field and fixed javadoc warnings related to this
lagergren
parents:
26768
diff
changeset
|
107 |
setLength(Math.max(length - by, 0)); |
16147 | 108 |
} |
109 |
||
110 |
@Override |
|
111 |
public ArrayData shiftRight(final int by) { |
|
112 |
final TreeMap<Long, Object> newSparseMap = new TreeMap<>(); |
|
26886
18c744ab4df2
8059211: Changed ArrayData.length accessor to use the protected field and fixed javadoc warnings related to this
lagergren
parents:
26768
diff
changeset
|
113 |
if (underlying.length + by > maxDenseLength) { |
18c744ab4df2
8059211: Changed ArrayData.length accessor to use the protected field and fixed javadoc warnings related to this
lagergren
parents:
26768
diff
changeset
|
114 |
for (long i = maxDenseLength - by; i < underlying.length; i++) { |
16147 | 115 |
if (underlying.has((int) i)) { |
116 |
newSparseMap.put(Long.valueOf(i + by), underlying.getObject((int) i)); |
|
117 |
} |
|
118 |
} |
|
119 |
underlying = underlying.shrink((int) (maxDenseLength - by)); |
|
120 |
} |
|
121 |
||
122 |
underlying.shiftRight(by); |
|
123 |
||
124 |
for (final Map.Entry<Long, Object> entry : sparseMap.entrySet()) { |
|
125 |
final long newIndex = entry.getKey().longValue() + by; |
|
126 |
newSparseMap.put(Long.valueOf(newIndex), entry.getValue()); |
|
127 |
} |
|
128 |
||
129 |
sparseMap = newSparseMap; |
|
26886
18c744ab4df2
8059211: Changed ArrayData.length accessor to use the protected field and fixed javadoc warnings related to this
lagergren
parents:
26768
diff
changeset
|
130 |
setLength(length + by); |
16147 | 131 |
|
132 |
return this; |
|
133 |
} |
|
134 |
||
135 |
@Override |
|
136 |
public ArrayData ensure(final long safeIndex) { |
|
26886
18c744ab4df2
8059211: Changed ArrayData.length accessor to use the protected field and fixed javadoc warnings related to this
lagergren
parents:
26768
diff
changeset
|
137 |
if (safeIndex < maxDenseLength && underlying.length <= safeIndex) { |
16147 | 138 |
underlying = underlying.ensure(safeIndex); |
139 |
} |
|
26886
18c744ab4df2
8059211: Changed ArrayData.length accessor to use the protected field and fixed javadoc warnings related to this
lagergren
parents:
26768
diff
changeset
|
140 |
setLength(Math.max(safeIndex + 1, length)); |
16147 | 141 |
return this; |
142 |
} |
|
143 |
||
144 |
@Override |
|
145 |
public ArrayData shrink(final long newLength) { |
|
26886
18c744ab4df2
8059211: Changed ArrayData.length accessor to use the protected field and fixed javadoc warnings related to this
lagergren
parents:
26768
diff
changeset
|
146 |
if (newLength < underlying.length) { |
16147 | 147 |
underlying = underlying.shrink(newLength); |
148 |
underlying.setLength(newLength); |
|
149 |
sparseMap.clear(); |
|
150 |
setLength(newLength); |
|
151 |
} |
|
152 |
||
153 |
sparseMap.subMap(Long.valueOf(newLength), Long.MAX_VALUE).clear(); |
|
154 |
setLength(newLength); |
|
155 |
return this; |
|
156 |
} |
|
157 |
||
158 |
@Override |
|
159 |
public ArrayData set(final int index, final Object value, final boolean strict) { |
|
160 |
if (index >= 0 && index < maxDenseLength) { |
|
161 |
ensure(index); |
|
162 |
underlying = underlying.set(index, value, strict); |
|
26886
18c744ab4df2
8059211: Changed ArrayData.length accessor to use the protected field and fixed javadoc warnings related to this
lagergren
parents:
26768
diff
changeset
|
163 |
setLength(Math.max(underlying.length, length)); |
16147 | 164 |
} else { |
24769 | 165 |
final Long longIndex = indexToKey(index); |
166 |
sparseMap.put(longIndex, value); |
|
26886
18c744ab4df2
8059211: Changed ArrayData.length accessor to use the protected field and fixed javadoc warnings related to this
lagergren
parents:
26768
diff
changeset
|
167 |
setLength(Math.max(longIndex + 1, length)); |
16147 | 168 |
} |
169 |
||
170 |
return this; |
|
171 |
} |
|
172 |
||
173 |
@Override |
|
174 |
public ArrayData set(final int index, final int value, final boolean strict) { |
|
175 |
if (index >= 0 && index < maxDenseLength) { |
|
176 |
ensure(index); |
|
177 |
underlying = underlying.set(index, value, strict); |
|
26886
18c744ab4df2
8059211: Changed ArrayData.length accessor to use the protected field and fixed javadoc warnings related to this
lagergren
parents:
26768
diff
changeset
|
178 |
setLength(Math.max(underlying.length, length)); |
16147 | 179 |
} else { |
24769 | 180 |
final Long longIndex = indexToKey(index); |
181 |
sparseMap.put(longIndex, value); |
|
26886
18c744ab4df2
8059211: Changed ArrayData.length accessor to use the protected field and fixed javadoc warnings related to this
lagergren
parents:
26768
diff
changeset
|
182 |
setLength(Math.max(longIndex + 1, length)); |
16147 | 183 |
} |
184 |
return this; |
|
185 |
} |
|
186 |
||
187 |
@Override |
|
188 |
public ArrayData set(final int index, final long value, final boolean strict) { |
|
189 |
if (index >= 0 && index < maxDenseLength) { |
|
190 |
ensure(index); |
|
191 |
underlying = underlying.set(index, value, strict); |
|
26886
18c744ab4df2
8059211: Changed ArrayData.length accessor to use the protected field and fixed javadoc warnings related to this
lagergren
parents:
26768
diff
changeset
|
192 |
setLength(Math.max(underlying.length, length)); |
16147 | 193 |
} else { |
24769 | 194 |
final Long longIndex = indexToKey(index); |
195 |
sparseMap.put(longIndex, value); |
|
26886
18c744ab4df2
8059211: Changed ArrayData.length accessor to use the protected field and fixed javadoc warnings related to this
lagergren
parents:
26768
diff
changeset
|
196 |
setLength(Math.max(longIndex + 1, length)); |
16147 | 197 |
} |
198 |
return this; |
|
199 |
} |
|
200 |
||
201 |
@Override |
|
202 |
public ArrayData set(final int index, final double value, final boolean strict) { |
|
203 |
if (index >= 0 && index < maxDenseLength) { |
|
204 |
ensure(index); |
|
205 |
underlying = underlying.set(index, value, strict); |
|
26886
18c744ab4df2
8059211: Changed ArrayData.length accessor to use the protected field and fixed javadoc warnings related to this
lagergren
parents:
26768
diff
changeset
|
206 |
setLength(Math.max(underlying.length, length)); |
16147 | 207 |
} else { |
24769 | 208 |
final Long longIndex = indexToKey(index); |
209 |
sparseMap.put(longIndex, value); |
|
26886
18c744ab4df2
8059211: Changed ArrayData.length accessor to use the protected field and fixed javadoc warnings related to this
lagergren
parents:
26768
diff
changeset
|
210 |
setLength(Math.max(longIndex + 1, length)); |
16147 | 211 |
} |
212 |
return this; |
|
213 |
} |
|
214 |
||
215 |
@Override |
|
18606 | 216 |
public ArrayData setEmpty(final int index) { |
217 |
underlying.setEmpty(index); |
|
218 |
return this; |
|
219 |
} |
|
220 |
||
221 |
@Override |
|
222 |
public ArrayData setEmpty(final long lo, final long hi) { |
|
223 |
underlying.setEmpty(lo, hi); |
|
224 |
return this; |
|
225 |
} |
|
226 |
||
227 |
@Override |
|
24719 | 228 |
public Type getOptimisticType() { |
229 |
return underlying.getOptimisticType(); |
|
230 |
} |
|
231 |
||
232 |
@Override |
|
16147 | 233 |
public int getInt(final int index) { |
234 |
if (index >= 0 && index < maxDenseLength) { |
|
235 |
return underlying.getInt(index); |
|
236 |
} |
|
237 |
return JSType.toInt32(sparseMap.get(indexToKey(index))); |
|
238 |
} |
|
239 |
||
240 |
@Override |
|
24719 | 241 |
public int getIntOptimistic(final int index, final int programPoint) { |
242 |
if (index >= 0 && index < maxDenseLength) { |
|
243 |
return underlying.getIntOptimistic(index, programPoint); |
|
244 |
} |
|
245 |
return JSType.toInt32Optimistic(sparseMap.get(indexToKey(index)), programPoint); |
|
246 |
} |
|
247 |
||
248 |
@Override |
|
16147 | 249 |
public long getLong(final int index) { |
250 |
if (index >= 0 && index < maxDenseLength) { |
|
251 |
return underlying.getLong(index); |
|
252 |
} |
|
253 |
return JSType.toLong(sparseMap.get(indexToKey(index))); |
|
254 |
} |
|
255 |
||
256 |
@Override |
|
24719 | 257 |
public long getLongOptimistic(final int index, final int programPoint) { |
258 |
if (index >= 0 && index < maxDenseLength) { |
|
259 |
return underlying.getLongOptimistic(index, programPoint); |
|
260 |
} |
|
261 |
return JSType.toLongOptimistic(sparseMap.get(indexToKey(index)), programPoint); |
|
262 |
} |
|
263 |
||
264 |
@Override |
|
16147 | 265 |
public double getDouble(final int index) { |
266 |
if (index >= 0 && index < maxDenseLength) { |
|
267 |
return underlying.getDouble(index); |
|
268 |
} |
|
269 |
return JSType.toNumber(sparseMap.get(indexToKey(index))); |
|
270 |
} |
|
271 |
||
272 |
@Override |
|
24719 | 273 |
public double getDoubleOptimistic(final int index, final int programPoint) { |
274 |
if (index >= 0 && index < maxDenseLength) { |
|
275 |
return underlying.getDouble(index); |
|
276 |
} |
|
277 |
return JSType.toNumberOptimistic(sparseMap.get(indexToKey(index)), programPoint); |
|
278 |
} |
|
279 |
||
280 |
@Override |
|
16147 | 281 |
public Object getObject(final int index) { |
282 |
if (index >= 0 && index < maxDenseLength) { |
|
283 |
return underlying.getObject(index); |
|
284 |
} |
|
285 |
||
286 |
final Long key = indexToKey(index); |
|
287 |
if (sparseMap.containsKey(key)) { |
|
288 |
return sparseMap.get(key); |
|
289 |
} |
|
290 |
||
291 |
return ScriptRuntime.UNDEFINED; |
|
292 |
} |
|
293 |
||
294 |
@Override |
|
295 |
public boolean has(final int index) { |
|
296 |
if (index >= 0 && index < maxDenseLength) { |
|
26886
18c744ab4df2
8059211: Changed ArrayData.length accessor to use the protected field and fixed javadoc warnings related to this
lagergren
parents:
26768
diff
changeset
|
297 |
return index < underlying.length && underlying.has(index); |
16147 | 298 |
} |
299 |
||
300 |
return sparseMap.containsKey(indexToKey(index)); |
|
301 |
} |
|
302 |
||
303 |
@Override |
|
304 |
public ArrayData delete(final int index) { |
|
305 |
if (index >= 0 && index < maxDenseLength) { |
|
26886
18c744ab4df2
8059211: Changed ArrayData.length accessor to use the protected field and fixed javadoc warnings related to this
lagergren
parents:
26768
diff
changeset
|
306 |
if (index < underlying.length) { |
16147 | 307 |
underlying = underlying.delete(index); |
308 |
} |
|
309 |
} else { |
|
310 |
sparseMap.remove(indexToKey(index)); |
|
311 |
} |
|
312 |
||
313 |
return this; |
|
314 |
} |
|
315 |
||
316 |
@Override |
|
317 |
public ArrayData delete(final long fromIndex, final long toIndex) { |
|
26886
18c744ab4df2
8059211: Changed ArrayData.length accessor to use the protected field and fixed javadoc warnings related to this
lagergren
parents:
26768
diff
changeset
|
318 |
if (fromIndex < maxDenseLength && fromIndex < underlying.length) { |
18c744ab4df2
8059211: Changed ArrayData.length accessor to use the protected field and fixed javadoc warnings related to this
lagergren
parents:
26768
diff
changeset
|
319 |
underlying = underlying.delete(fromIndex, Math.min(toIndex, underlying.length - 1)); |
16147 | 320 |
} |
321 |
if (toIndex >= maxDenseLength) { |
|
322 |
sparseMap.subMap(fromIndex, true, toIndex, true).clear(); |
|
323 |
} |
|
324 |
return this; |
|
325 |
} |
|
326 |
||
327 |
private static Long indexToKey(final int index) { |
|
24769 | 328 |
return Long.valueOf(ArrayIndex.toLongIndex(index)); |
16147 | 329 |
} |
330 |
||
331 |
@Override |
|
26768
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
332 |
public ArrayData convert(final Class<?> type) { |
16147 | 333 |
underlying = underlying.convert(type); |
334 |
return this; |
|
335 |
} |
|
336 |
||
337 |
@Override |
|
338 |
public Object pop() { |
|
26886
18c744ab4df2
8059211: Changed ArrayData.length accessor to use the protected field and fixed javadoc warnings related to this
lagergren
parents:
26768
diff
changeset
|
339 |
if (length == 0) { |
16147 | 340 |
return ScriptRuntime.UNDEFINED; |
341 |
} |
|
26886
18c744ab4df2
8059211: Changed ArrayData.length accessor to use the protected field and fixed javadoc warnings related to this
lagergren
parents:
26768
diff
changeset
|
342 |
if (length == underlying.length) { |
16147 | 343 |
final Object result = underlying.pop(); |
26886
18c744ab4df2
8059211: Changed ArrayData.length accessor to use the protected field and fixed javadoc warnings related to this
lagergren
parents:
26768
diff
changeset
|
344 |
setLength(underlying.length); |
16147 | 345 |
return result; |
346 |
} |
|
26886
18c744ab4df2
8059211: Changed ArrayData.length accessor to use the protected field and fixed javadoc warnings related to this
lagergren
parents:
26768
diff
changeset
|
347 |
setLength(length - 1); |
18c744ab4df2
8059211: Changed ArrayData.length accessor to use the protected field and fixed javadoc warnings related to this
lagergren
parents:
26768
diff
changeset
|
348 |
final Long key = Long.valueOf(length); |
16147 | 349 |
return sparseMap.containsKey(key) ? sparseMap.remove(key) : ScriptRuntime.UNDEFINED; |
350 |
} |
|
351 |
||
352 |
@Override |
|
353 |
public ArrayData slice(final long from, final long to) { |
|
26886
18c744ab4df2
8059211: Changed ArrayData.length accessor to use the protected field and fixed javadoc warnings related to this
lagergren
parents:
26768
diff
changeset
|
354 |
assert to <= length; |
18c744ab4df2
8059211: Changed ArrayData.length accessor to use the protected field and fixed javadoc warnings related to this
lagergren
parents:
26768
diff
changeset
|
355 |
final long start = from < 0 ? (from + length) : from; |
16147 | 356 |
final long newLength = to - start; |
357 |
||
358 |
if (start >= 0 && to <= maxDenseLength) { |
|
26886
18c744ab4df2
8059211: Changed ArrayData.length accessor to use the protected field and fixed javadoc warnings related to this
lagergren
parents:
26768
diff
changeset
|
359 |
if (newLength <= underlying.length) { |
16147 | 360 |
return underlying.slice(from, to); |
361 |
} |
|
26886
18c744ab4df2
8059211: Changed ArrayData.length accessor to use the protected field and fixed javadoc warnings related to this
lagergren
parents:
26768
diff
changeset
|
362 |
return underlying.slice(from, to).ensure(newLength - 1).delete(underlying.length, newLength); |
16147 | 363 |
} |
364 |
||
365 |
ArrayData sliced = EMPTY_ARRAY; |
|
366 |
sliced = sliced.ensure(newLength - 1); |
|
367 |
for (long i = start; i < to; i = nextIndex(i)) { |
|
368 |
if (has((int)i)) { |
|
369 |
sliced = sliced.set((int)(i - start), getObject((int)i), false); |
|
370 |
} |
|
371 |
} |
|
26886
18c744ab4df2
8059211: Changed ArrayData.length accessor to use the protected field and fixed javadoc warnings related to this
lagergren
parents:
26768
diff
changeset
|
372 |
assert sliced.length == newLength; |
16147 | 373 |
return sliced; |
374 |
} |
|
375 |
||
376 |
@Override |
|
377 |
public long nextIndex(final long index) { |
|
26886
18c744ab4df2
8059211: Changed ArrayData.length accessor to use the protected field and fixed javadoc warnings related to this
lagergren
parents:
26768
diff
changeset
|
378 |
if (index < underlying.length - 1) { |
16147 | 379 |
return underlying.nextIndex(index); |
380 |
} |
|
381 |
||
382 |
final Long nextKey = sparseMap.higherKey(index); |
|
383 |
if (nextKey != null) { |
|
384 |
return nextKey; |
|
385 |
} |
|
26886
18c744ab4df2
8059211: Changed ArrayData.length accessor to use the protected field and fixed javadoc warnings related to this
lagergren
parents:
26768
diff
changeset
|
386 |
return length; |
16147 | 387 |
} |
388 |
} |