Skip to content

Commit 7ac0363

Browse files
dankurkaGerrit Code Review
authored and
Gerrit Code Review
committed
Move JSNI reference out of Arrays.java
The jsni conversion tool used to make the JRE work for j2cl chokes on JSNI references. Arrays has "valid" JSNI that needs to be converted as well as this reference. By moving it into a seperate file we can still use the conversion tool. Change-Id: I65bf7f4b215d1b976da2e63a04a708545fb3a910
1 parent 8bedfed commit 7ac0363

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright 2015 Google Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
5+
* use this file except in compliance with the License. You may obtain a copy of
6+
* the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations under
14+
* the License.
15+
*/
16+
package javaemul.internal;
17+
18+
/**
19+
* A helper class for long comparison.
20+
*/
21+
public class LongCompareHolder {
22+
// TODO(dankurka): replace this with @JsFunction once its available in GWT.
23+
public static native Object getLongComparator() /*-{
24+
return @com.google.gwt.lang.LongLib::compare(*);
25+
}-*/;
26+
}
27+

user/super/com/google/gwt/emul/java/util/Arrays.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.io.Serializable;
2828

2929
import javaemul.internal.ArrayHelper;
30+
import javaemul.internal.LongCompareHolder;
3031

3132
/**
3233
* Utility methods related to native arrays. <a
@@ -1010,7 +1011,7 @@ public static void sort(int[] array, int fromIndex, int toIndex) {
10101011
}
10111012

10121013
public static void sort(long[] array) {
1013-
nativeLongSort(array);
1014+
nativeLongSort(array, LongCompareHolder.getLongComparator());
10141015
}
10151016

10161017
public static void sort(long[] array, int fromIndex, int toIndex) {
@@ -1356,16 +1357,16 @@ private static void mergeSort(Object[] temp, Object[] array, int low,
13561357
/**
13571358
* Sort an entire array of number primitives.
13581359
*/
1359-
private static native void nativeLongSort(Object array) /*-{
1360-
array.sort(@com.google.gwt.lang.LongLib::compare(*));
1360+
private static native void nativeLongSort(Object array, Object compareFunction) /*-{
1361+
array.sort(compareFunction);
13611362
}-*/;
13621363

13631364
/**
13641365
* Sort a subset of an array of number primitives.
13651366
*/
13661367
private static void nativeLongSort(Object array, int fromIndex, int toIndex) {
13671368
Object temp = ArrayHelper.unsafeClone(array, fromIndex, toIndex);
1368-
nativeLongSort(temp);
1369+
nativeLongSort(temp, LongCompareHolder.getLongComparator());
13691370
ArrayHelper.copy(temp, 0, array, fromIndex, toIndex - fromIndex);
13701371
}
13711372

0 commit comments

Comments
 (0)