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 |
||
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
24741
diff
changeset
|
28 |
import static jdk.nashorn.internal.codegen.CompilerConstants.specialCall; |
24719 | 29 |
import static jdk.nashorn.internal.lookup.Lookup.MH; |
30 |
import java.lang.invoke.MethodHandle; |
|
31 |
import java.lang.invoke.MethodHandles; |
|
16147 | 32 |
import java.util.Arrays; |
24719 | 33 |
import jdk.nashorn.internal.codegen.types.Type; |
16147 | 34 |
import jdk.nashorn.internal.runtime.JSType; |
35 |
import jdk.nashorn.internal.runtime.ScriptRuntime; |
|
36 |
||
37 |
/** |
|
38 |
* Implementation of {@link ArrayData} as soon as a long has been |
|
39 |
* written to the array |
|
40 |
*/ |
|
26768
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
41 |
final class LongArrayData extends ContinuousArrayData implements IntOrLongElements { |
16147 | 42 |
/** |
43 |
* The wrapped array |
|
44 |
*/ |
|
45 |
private long[] array; |
|
46 |
||
47 |
/** |
|
48 |
* Constructor |
|
49 |
* @param array an int array |
|
50 |
* @param length a length, not necessarily array.length |
|
51 |
*/ |
|
52 |
LongArrayData(final long array[], final int length) { |
|
53 |
super(length); |
|
19236
73d242d205f9
8020132: Big object literal with numerical keys exceeds method size
hannesw
parents:
18879
diff
changeset
|
54 |
assert array.length >= length; |
16147 | 55 |
this.array = array; |
56 |
} |
|
57 |
||
58 |
@Override |
|
26768
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
59 |
public Class<?> getElementType() { |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
60 |
return long.class; |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
61 |
} |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
62 |
|
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
63 |
@Override |
19236
73d242d205f9
8020132: Big object literal with numerical keys exceeds method size
hannesw
parents:
18879
diff
changeset
|
64 |
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
|
65 |
return new LongArrayData(array.clone(), (int)length); |
19236
73d242d205f9
8020132: Big object literal with numerical keys exceeds method size
hannesw
parents:
18879
diff
changeset
|
66 |
} |
73d242d205f9
8020132: Big object literal with numerical keys exceeds method size
hannesw
parents:
18879
diff
changeset
|
67 |
|
73d242d205f9
8020132: Big object literal with numerical keys exceeds method size
hannesw
parents:
18879
diff
changeset
|
68 |
@Override |
16147 | 69 |
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
|
70 |
return toObjectArray(array, (int)length); |
16147 | 71 |
} |
72 |
||
73 |
private static Object[] toObjectArray(final long[] array, final int length) { |
|
18879
382986b34105
8020283: Don't use exceptions for widening of ArrayData
hannesw
parents:
16151
diff
changeset
|
74 |
assert length <= array.length : "length exceeds internal array size"; |
382986b34105
8020283: Don't use exceptions for widening of ArrayData
hannesw
parents:
16151
diff
changeset
|
75 |
final Object[] oarray = new Object[array.length]; |
382986b34105
8020283: Don't use exceptions for widening of ArrayData
hannesw
parents:
16151
diff
changeset
|
76 |
|
16147 | 77 |
for (int index = 0; index < length; index++) { |
78 |
oarray[index] = Long.valueOf(array[index]); |
|
79 |
} |
|
80 |
||
81 |
return oarray; |
|
82 |
} |
|
83 |
||
84 |
@Override |
|
85 |
public Object asArrayOfType(final Class<?> componentType) { |
|
24719 | 86 |
if (componentType == long.class) { |
26886
18c744ab4df2
8059211: Changed ArrayData.length accessor to use the protected field and fixed javadoc warnings related to this
lagergren
parents:
26768
diff
changeset
|
87 |
return array.length == length ? array.clone() : Arrays.copyOf(array, (int)length); |
16147 | 88 |
} |
89 |
return super.asArrayOfType(componentType); |
|
90 |
} |
|
91 |
||
18879
382986b34105
8020283: Don't use exceptions for widening of ArrayData
hannesw
parents:
16151
diff
changeset
|
92 |
private static double[] toDoubleArray(final long[] array, final int length) { |
382986b34105
8020283: Don't use exceptions for widening of ArrayData
hannesw
parents:
16151
diff
changeset
|
93 |
assert length <= array.length : "length exceeds internal array size"; |
16147 | 94 |
final double[] darray = new double[array.length]; |
18879
382986b34105
8020283: Don't use exceptions for widening of ArrayData
hannesw
parents:
16151
diff
changeset
|
95 |
|
382986b34105
8020283: Don't use exceptions for widening of ArrayData
hannesw
parents:
16151
diff
changeset
|
96 |
for (int index = 0; index < length; index++) { |
16147 | 97 |
darray[index] = array[index]; |
98 |
} |
|
99 |
||
100 |
return darray; |
|
101 |
} |
|
102 |
||
103 |
@Override |
|
104 |
public ArrayData convert(final Class<?> type) { |
|
21438
4292865c758b
8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents:
19472
diff
changeset
|
105 |
if (type == Integer.class || type == Long.class) { |
16147 | 106 |
return this; |
18879
382986b34105
8020283: Don't use exceptions for widening of ArrayData
hannesw
parents:
16151
diff
changeset
|
107 |
} |
26886
18c744ab4df2
8059211: Changed ArrayData.length accessor to use the protected field and fixed javadoc warnings related to this
lagergren
parents:
26768
diff
changeset
|
108 |
final int len = (int)length; |
18879
382986b34105
8020283: Don't use exceptions for widening of ArrayData
hannesw
parents:
16151
diff
changeset
|
109 |
if (type == Double.class) { |
26886
18c744ab4df2
8059211: Changed ArrayData.length accessor to use the protected field and fixed javadoc warnings related to this
lagergren
parents:
26768
diff
changeset
|
110 |
return new NumberArrayData(LongArrayData.toDoubleArray(array, len), len); |
16147 | 111 |
} |
26886
18c744ab4df2
8059211: Changed ArrayData.length accessor to use the protected field and fixed javadoc warnings related to this
lagergren
parents:
26768
diff
changeset
|
112 |
return new ObjectArrayData(LongArrayData.toObjectArray(array, len), len); |
16147 | 113 |
} |
114 |
||
115 |
@Override |
|
116 |
public void shiftLeft(final int by) { |
|
117 |
System.arraycopy(array, by, array, 0, array.length - by); |
|
118 |
} |
|
119 |
||
120 |
@Override |
|
121 |
public ArrayData shiftRight(final int by) { |
|
26886
18c744ab4df2
8059211: Changed ArrayData.length accessor to use the protected field and fixed javadoc warnings related to this
lagergren
parents:
26768
diff
changeset
|
122 |
final ArrayData newData = ensure(by + length - 1); |
16147 | 123 |
if (newData != this) { |
124 |
newData.shiftRight(by); |
|
125 |
return newData; |
|
126 |
} |
|
127 |
System.arraycopy(array, 0, array, by, array.length - by); |
|
128 |
||
129 |
return this; |
|
130 |
} |
|
131 |
||
132 |
@Override |
|
133 |
public ArrayData ensure(final long safeIndex) { |
|
24720 | 134 |
if (safeIndex >= SparseArrayData.MAX_DENSE_LENGTH) { |
16147 | 135 |
return new SparseArrayData(this, safeIndex + 1); |
136 |
} |
|
24720 | 137 |
final int alen = array.length; |
138 |
if (safeIndex >= alen) { |
|
139 |
final int newLength = ArrayData.nextSize((int)safeIndex); |
|
16147 | 140 |
array = Arrays.copyOf(array, newLength); |
141 |
} |
|
142 |
setLength(safeIndex + 1); |
|
143 |
return this; |
|
144 |
} |
|
145 |
||
146 |
@Override |
|
147 |
public ArrayData shrink(final long newLength) { |
|
148 |
Arrays.fill(array, (int) newLength, array.length, 0); |
|
149 |
||
150 |
return this; |
|
151 |
} |
|
152 |
||
153 |
@Override |
|
154 |
public ArrayData set(final int index, final Object value, final boolean strict) { |
|
18879
382986b34105
8020283: Don't use exceptions for widening of ArrayData
hannesw
parents:
16151
diff
changeset
|
155 |
if (value instanceof Long || value instanceof Integer) { |
382986b34105
8020283: Don't use exceptions for widening of ArrayData
hannesw
parents:
16151
diff
changeset
|
156 |
return set(index, ((Number)value).longValue(), strict); |
382986b34105
8020283: Don't use exceptions for widening of ArrayData
hannesw
parents:
16151
diff
changeset
|
157 |
} else if (value == ScriptRuntime.UNDEFINED) { |
382986b34105
8020283: Don't use exceptions for widening of ArrayData
hannesw
parents:
16151
diff
changeset
|
158 |
return new UndefinedArrayFilter(this).set(index, value, strict); |
16147 | 159 |
} |
160 |
||
161 |
final ArrayData newData = convert(value == null ? Object.class : value.getClass()); |
|
162 |
return newData.set(index, value, strict); |
|
163 |
} |
|
164 |
||
165 |
@Override |
|
166 |
public ArrayData set(final int index, final int value, final boolean strict) { |
|
167 |
array[index] = 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
|
168 |
setLength(Math.max(index + 1, length)); |
16147 | 169 |
return this; |
170 |
} |
|
171 |
||
172 |
@Override |
|
173 |
public ArrayData set(final int index, final long value, final boolean strict) { |
|
174 |
array[index] = 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
|
175 |
setLength(Math.max(index + 1, length)); |
16147 | 176 |
return this; |
177 |
} |
|
178 |
||
179 |
@Override |
|
180 |
public ArrayData set(final int index, final double value, final boolean strict) { |
|
181 |
if (JSType.isRepresentableAsLong(value)) { |
|
182 |
array[index] = (long)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
|
183 |
setLength(Math.max(index + 1, length)); |
16147 | 184 |
return this; |
185 |
} |
|
186 |
return convert(Double.class).set(index, value, strict); |
|
187 |
} |
|
188 |
||
189 |
@Override |
|
24719 | 190 |
public Type getOptimisticType() { |
191 |
return Type.LONG; |
|
192 |
} |
|
193 |
||
24741
4232289c3235
8040102: Remove all references to Unsafe and definition of anonymous clases from the code
lagergren
parents:
24720
diff
changeset
|
194 |
private static final MethodHandle HAS_GET_ELEM = specialCall(MethodHandles.lookup(), LongArrayData.class, "getElem", long.class, int.class).methodHandle(); |
4232289c3235
8040102: Remove all references to Unsafe and definition of anonymous clases from the code
lagergren
parents:
24720
diff
changeset
|
195 |
private static final MethodHandle SET_ELEM = specialCall(MethodHandles.lookup(), LongArrayData.class, "setElem", void.class, int.class, long.class).methodHandle(); |
24719 | 196 |
|
197 |
@SuppressWarnings("unused") |
|
198 |
private long getElem(final int index) { |
|
199 |
if (has(index)) { |
|
200 |
return array[index]; |
|
201 |
} |
|
202 |
throw new ClassCastException(); |
|
203 |
} |
|
204 |
||
205 |
@SuppressWarnings("unused") |
|
206 |
private void setElem(final int index, final long elem) { |
|
24720 | 207 |
if (hasRoomFor(index)) { |
208 |
array[index] = elem; |
|
209 |
return; |
|
210 |
} |
|
211 |
throw new ClassCastException(); |
|
24719 | 212 |
} |
213 |
||
214 |
@Override |
|
215 |
public MethodHandle getElementGetter(final Class<?> returnType, final int programPoint) { |
|
216 |
if (returnType == int.class) { |
|
217 |
return null; |
|
218 |
} |
|
219 |
return getContinuousElementGetter(HAS_GET_ELEM, returnType, programPoint); |
|
220 |
} |
|
221 |
||
222 |
@Override |
|
223 |
public MethodHandle getElementSetter(final Class<?> elementType) { |
|
24720 | 224 |
return elementType == int.class || elementType == long.class ? getContinuousElementSetter(MH.asType(SET_ELEM, SET_ELEM.type().changeParameterType(2, elementType)), elementType) : null; |
24719 | 225 |
} |
226 |
||
227 |
@Override |
|
16147 | 228 |
public int getInt(final int index) { |
229 |
return (int)array[index]; |
|
230 |
} |
|
231 |
||
232 |
@Override |
|
233 |
public long getLong(final int index) { |
|
234 |
return array[index]; |
|
235 |
} |
|
236 |
||
237 |
@Override |
|
24719 | 238 |
public long getLongOptimistic(final int index, final int programPoint) { |
239 |
return array[index]; |
|
240 |
} |
|
241 |
||
242 |
@Override |
|
16147 | 243 |
public double getDouble(final int index) { |
244 |
return array[index]; |
|
245 |
} |
|
246 |
||
247 |
@Override |
|
24719 | 248 |
public double getDoubleOptimistic(final int index, final int programPoint) { |
249 |
return array[index]; |
|
250 |
} |
|
251 |
||
252 |
@Override |
|
16147 | 253 |
public Object getObject(final int index) { |
254 |
return array[index]; |
|
255 |
} |
|
256 |
||
257 |
@Override |
|
258 |
public boolean has(final int 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
|
259 |
return 0 <= index && index < length; |
16147 | 260 |
} |
261 |
||
262 |
@Override |
|
263 |
public ArrayData delete(final int index) { |
|
264 |
return new DeletedRangeArrayFilter(this, index, index); |
|
265 |
} |
|
266 |
||
267 |
@Override |
|
268 |
public ArrayData delete(final long fromIndex, final long toIndex) { |
|
269 |
return new DeletedRangeArrayFilter(this, fromIndex, toIndex); |
|
270 |
} |
|
271 |
||
272 |
@Override |
|
273 |
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
|
274 |
if (length == 0) { |
16147 | 275 |
return ScriptRuntime.UNDEFINED; |
276 |
} |
|
277 |
||
26886
18c744ab4df2
8059211: Changed ArrayData.length accessor to use the protected field and fixed javadoc warnings related to this
lagergren
parents:
26768
diff
changeset
|
278 |
final int newLength = (int)length - 1; |
16147 | 279 |
final long elem = array[newLength]; |
280 |
array[newLength] = 0; |
|
281 |
setLength(newLength); |
|
282 |
||
283 |
return elem; |
|
284 |
} |
|
285 |
||
286 |
@Override |
|
287 |
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
|
288 |
final long start = from < 0 ? from + length : from; |
16147 | 289 |
final long newLength = to - start; |
290 |
return new LongArrayData(Arrays.copyOfRange(array, (int)from, (int)to), (int)newLength); |
|
291 |
} |
|
21438
4292865c758b
8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents:
19472
diff
changeset
|
292 |
|
4292865c758b
8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents:
19472
diff
changeset
|
293 |
@Override |
24720 | 294 |
public final ArrayData push(final boolean strict, final long item) { |
26886
18c744ab4df2
8059211: Changed ArrayData.length accessor to use the protected field and fixed javadoc warnings related to this
lagergren
parents:
26768
diff
changeset
|
295 |
final long len = length; |
18c744ab4df2
8059211: Changed ArrayData.length accessor to use the protected field and fixed javadoc warnings related to this
lagergren
parents:
26768
diff
changeset
|
296 |
final ArrayData newData = ensure(len); |
24720 | 297 |
if (newData == this) { |
26886
18c744ab4df2
8059211: Changed ArrayData.length accessor to use the protected field and fixed javadoc warnings related to this
lagergren
parents:
26768
diff
changeset
|
298 |
array[(int)len] = item; |
24720 | 299 |
return this; |
300 |
} |
|
26886
18c744ab4df2
8059211: Changed ArrayData.length accessor to use the protected field and fixed javadoc warnings related to this
lagergren
parents:
26768
diff
changeset
|
301 |
return newData.set((int)len, item, strict); |
24720 | 302 |
} |
303 |
||
304 |
@Override |
|
21438
4292865c758b
8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents:
19472
diff
changeset
|
305 |
public ArrayData fastSplice(final int start, final int removed, final int added) throws UnsupportedOperationException { |
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 |
final long oldLength = length; |
21438
4292865c758b
8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents:
19472
diff
changeset
|
307 |
final long newLength = oldLength - removed + added; |
4292865c758b
8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents:
19472
diff
changeset
|
308 |
if (newLength > SparseArrayData.MAX_DENSE_LENGTH && newLength > array.length) { |
4292865c758b
8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents:
19472
diff
changeset
|
309 |
throw new UnsupportedOperationException(); |
4292865c758b
8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents:
19472
diff
changeset
|
310 |
} |
24720 | 311 |
final ArrayData returnValue = removed == 0 ? |
21438
4292865c758b
8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents:
19472
diff
changeset
|
312 |
EMPTY_ARRAY : new LongArrayData(Arrays.copyOfRange(array, start, start + removed), removed); |
4292865c758b
8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents:
19472
diff
changeset
|
313 |
|
4292865c758b
8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents:
19472
diff
changeset
|
314 |
if (newLength != oldLength) { |
4292865c758b
8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents:
19472
diff
changeset
|
315 |
final long[] newArray; |
4292865c758b
8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents:
19472
diff
changeset
|
316 |
|
4292865c758b
8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents:
19472
diff
changeset
|
317 |
if (newLength > array.length) { |
4292865c758b
8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents:
19472
diff
changeset
|
318 |
newArray = new long[ArrayData.nextSize((int)newLength)]; |
4292865c758b
8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents:
19472
diff
changeset
|
319 |
System.arraycopy(array, 0, newArray, 0, start); |
4292865c758b
8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents:
19472
diff
changeset
|
320 |
} else { |
4292865c758b
8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents:
19472
diff
changeset
|
321 |
newArray = array; |
4292865c758b
8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents:
19472
diff
changeset
|
322 |
} |
4292865c758b
8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents:
19472
diff
changeset
|
323 |
|
4292865c758b
8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents:
19472
diff
changeset
|
324 |
System.arraycopy(array, start + removed, newArray, start + added, (int)(oldLength - start - removed)); |
4292865c758b
8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents:
19472
diff
changeset
|
325 |
array = newArray; |
4292865c758b
8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents:
19472
diff
changeset
|
326 |
setLength(newLength); |
4292865c758b
8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents:
19472
diff
changeset
|
327 |
} |
4292865c758b
8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents:
19472
diff
changeset
|
328 |
|
4292865c758b
8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents:
19472
diff
changeset
|
329 |
return returnValue; |
4292865c758b
8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents:
19472
diff
changeset
|
330 |
} |
26768
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
331 |
|
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
332 |
@Override |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
333 |
public long fastPush(final int arg) { |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
334 |
return fastPush((long)arg); |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
335 |
} |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
336 |
|
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
337 |
@Override |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
338 |
public long fastPush(final long arg) { |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
339 |
final int len = (int)length; |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
340 |
if (len == array.length) { |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
341 |
array = Arrays.copyOf(array, nextSize(len)); |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
342 |
} |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
343 |
array[len] = arg; |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
344 |
return ++length; |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
345 |
} |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
346 |
|
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
347 |
@Override |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
348 |
public long fastPopLong() { |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
349 |
if (length == 0) { |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
350 |
throw new ClassCastException(); |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
351 |
} |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
352 |
final int newLength = (int)--length; |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
353 |
final long elem = array[newLength]; |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
354 |
array[newLength] = 0; |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
355 |
return elem; |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
356 |
} |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
357 |
|
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
358 |
@Override |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
359 |
public double fastPopDouble() { |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
360 |
return fastPopLong(); |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
361 |
} |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
362 |
|
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
363 |
@Override |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
364 |
public Object fastPopObject() { |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
365 |
return fastPopLong(); |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
366 |
} |
16147 | 367 |
} |