author | sundar |
Wed, 06 May 2015 20:04:42 +0530 | |
changeset 30394 | 72a59e4dffea |
parent 24778 | 2ff5d7041566 |
permissions | -rw-r--r-- |
21438
4292865c758b
8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents:
diff
changeset
|
1 |
/* |
4292865c758b
8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents:
diff
changeset
|
2 |
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. |
4292865c758b
8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
21438
diff
changeset
|
4 |
* |
21438
4292865c758b
8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
4292865c758b
8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
4292865c758b
8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
21438
diff
changeset
|
8 |
* |
21438
4292865c758b
8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
4292865c758b
8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
4292865c758b
8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
4292865c758b
8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
4292865c758b
8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents:
diff
changeset
|
13 |
* accompanied this code). |
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
21438
diff
changeset
|
14 |
* |
21438
4292865c758b
8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
4292865c758b
8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
4292865c758b
8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
21438
diff
changeset
|
18 |
* |
21438
4292865c758b
8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
4292865c758b
8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
4292865c758b
8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents:
diff
changeset
|
21 |
* questions. |
4292865c758b
8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents:
diff
changeset
|
22 |
*/ |
4292865c758b
8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents:
diff
changeset
|
23 |
|
4292865c758b
8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents:
diff
changeset
|
24 |
/** |
4292865c758b
8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents:
diff
changeset
|
25 |
* JDK-8026701: Array.prototype.splice is slow on dense arrays |
4292865c758b
8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents:
diff
changeset
|
26 |
* |
4292865c758b
8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents:
diff
changeset
|
27 |
* @test |
4292865c758b
8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents:
diff
changeset
|
28 |
* @run |
4292865c758b
8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents:
diff
changeset
|
29 |
*/ |
4292865c758b
8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents:
diff
changeset
|
30 |
|
4292865c758b
8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents:
diff
changeset
|
31 |
function testSplice(arr, e1, e2, e3) { |
4292865c758b
8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents:
diff
changeset
|
32 |
try { |
4292865c758b
8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents:
diff
changeset
|
33 |
print(arr); |
4292865c758b
8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents:
diff
changeset
|
34 |
print(arr.splice(3, 0, e1, e2, e3)); |
4292865c758b
8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents:
diff
changeset
|
35 |
print(arr); |
4292865c758b
8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents:
diff
changeset
|
36 |
print(arr.splice(2, 3)); |
4292865c758b
8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents:
diff
changeset
|
37 |
print(arr); |
4292865c758b
8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents:
diff
changeset
|
38 |
print(arr.splice(2, 3, arr[2], arr[3], arr[4])); |
4292865c758b
8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents:
diff
changeset
|
39 |
print(arr); |
4292865c758b
8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents:
diff
changeset
|
40 |
print(arr.splice(20, 10)); |
4292865c758b
8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents:
diff
changeset
|
41 |
print(arr); |
4292865c758b
8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents:
diff
changeset
|
42 |
print(arr.splice(arr.length, 0, e1, e2, e3)); |
4292865c758b
8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents:
diff
changeset
|
43 |
print(arr); |
4292865c758b
8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents:
diff
changeset
|
44 |
print(arr.splice(0, 2, arr[0], arr[1], arr[2], arr[3])); |
4292865c758b
8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents:
diff
changeset
|
45 |
print(arr); |
4292865c758b
8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents:
diff
changeset
|
46 |
} catch (error) { |
4292865c758b
8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents:
diff
changeset
|
47 |
print(error); |
4292865c758b
8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents:
diff
changeset
|
48 |
} |
4292865c758b
8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents:
diff
changeset
|
49 |
} |
4292865c758b
8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents:
diff
changeset
|
50 |
|
4292865c758b
8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents:
diff
changeset
|
51 |
function convert(array, type) { |
4292865c758b
8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents:
diff
changeset
|
52 |
return (typeof Java === "undefined") ? array : Java.from(Java.to(array, type)); |
4292865c758b
8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents:
diff
changeset
|
53 |
} |
4292865c758b
8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents:
diff
changeset
|
54 |
|
4292865c758b
8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents:
diff
changeset
|
55 |
// run some splice tests on all dense array implementations |
4292865c758b
8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents:
diff
changeset
|
56 |
testSplice([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], -1, -2, -3); |
4292865c758b
8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents:
diff
changeset
|
57 |
testSplice(convert([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], "long[]"), -1, -2, -3); |
4292865c758b
8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents:
diff
changeset
|
58 |
testSplice(convert([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], "double[]"), -1, -2, -3); |
4292865c758b
8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents:
diff
changeset
|
59 |
testSplice(["1", "2", "3", "4", "5", "6", "7", "8", "9", "10"], -1, -2, -3); |
4292865c758b
8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents:
diff
changeset
|
60 |
|
4292865c758b
8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents:
diff
changeset
|
61 |
// test array conversion during splice |
4292865c758b
8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents:
diff
changeset
|
62 |
testSplice([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], -1, "-2", "-3"); |
4292865c758b
8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents:
diff
changeset
|
63 |
testSplice([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], -1, -2.5, -3.5); |
4292865c758b
8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents:
diff
changeset
|
64 |
testSplice(convert([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], "long[]"), -1, "-2", "-3"); |
4292865c758b
8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents:
diff
changeset
|
65 |
testSplice(convert([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], "long[]"), -1, -2.5, -3.5); |
4292865c758b
8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents:
diff
changeset
|
66 |
testSplice(convert([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], "double[]"), -1, "-2", "-3"); |
4292865c758b
8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents:
diff
changeset
|
67 |
|
4292865c758b
8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents:
diff
changeset
|
68 |
// test combination with defined elements |
4292865c758b
8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents:
diff
changeset
|
69 |
testSplice(Object.defineProperty([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 5, {value: 13}), -1, -2, -3); |
4292865c758b
8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents:
diff
changeset
|
70 |
testSplice(Object.defineProperty([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 5, {value: 13, writable: false}), -1, -2, -3); |
4292865c758b
8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents:
diff
changeset
|
71 |
testSplice(Object.defineProperty([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 5, {value: 13, configurable: false}), -1, -2, -3); |
4292865c758b
8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents:
diff
changeset
|
72 |
testSplice(Object.defineProperty([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 5, {value: 13, writable: false, configurable: false}), -1, -2, -3); |