Reduce JSNI on String and MathContext
Change-Id: If79a6884ffa5236ab9f1b6f6a3b2ece9668f8b81
Review-Link: https://gwt-review.googlesource.com/#/c/18300/
diff --git a/user/super/com/google/gwt/emul/java/lang/String.java b/user/super/com/google/gwt/emul/java/lang/String.java
index 7db2125..4c927f1 100644
--- a/user/super/com/google/gwt/emul/java/lang/String.java
+++ b/user/super/com/google/gwt/emul/java/lang/String.java
@@ -349,13 +349,9 @@
}
private NativeString asNativeString() {
- return toNative(this);
+ return JsUtils.uncheckedCast(this);
}
- private static native NativeString toNative(String str) /*-{
- return str;
- }-*/;
-
@Override
public char charAt(int index) {
return asNativeString().charCodeAt(index);
@@ -592,13 +588,9 @@
return asNativeString().replace(jsRegEx, replace);
}
- private static native int getMatchIndex(Object matchObject) /*-{
- return matchObject.index;
- }-*/;
-
- private static native int getMatchLength(Object matchObject, int index) /*-{
- return matchObject[index].length;
- }-*/;
+ private static int getMatchIndex(String[] matchObject) {
+ return JsUtils.getIntProperty(matchObject, "index");
+ }
/**
* Regular expressions vary from the standard implementation. The
@@ -635,14 +627,14 @@
while (true) {
// None of the information in the match returned are useful as we have no
// subgroup handling
- Object matchObj = compiled.exec(trail);
+ String[] matchObj = compiled.exec(trail);
if (matchObj == null || trail == "" || (count == (maxMatch - 1) && maxMatch > 0)) {
out[count] = trail;
break;
} else {
out[count] = trail.substring(0, getMatchIndex(matchObj));
- trail = trail.substring(
- getMatchIndex(matchObj) + getMatchLength(matchObj, 0), trail.length());
+ trail =
+ trail.substring(getMatchIndex(matchObj) + matchObj[0].length(), trail.length());
// Force the compiled pattern to reset internal state
compiled.lastIndex = 0;
// Only one zero length match per character to ensure termination
diff --git a/user/super/com/google/gwt/emul/java/math/MathContext.java b/user/super/com/google/gwt/emul/java/math/MathContext.java
index 468e6fe..0f5d2a2 100644
--- a/user/super/com/google/gwt/emul/java/math/MathContext.java
+++ b/user/super/com/google/gwt/emul/java/math/MathContext.java
@@ -142,15 +142,15 @@
public MathContext(String val) {
checkNotNull(val, "null string");
- Object[] extractedValues = (Object[]) createParseRegexp().exec(val);
+ String[] extractedValues = createParseRegexp().exec(val);
if (extractedValues == null || extractedValues.length != 3) {
throw new IllegalArgumentException("bad string format");
}
try {
- this.precision = Integer.parseInt((String) extractedValues[1]);
+ this.precision = Integer.parseInt(extractedValues[1]);
// Can use RoundingMode.valueOf here because it is blacklisted in enum obfuscation.
- this.roundingMode = RoundingMode.valueOf((String) extractedValues[2]);
+ this.roundingMode = RoundingMode.valueOf(extractedValues[2]);
} catch (RuntimeException re) {
// Ensure that we only throw IllegalArgumentException for any illegal value.
throw new IllegalArgumentException("bad string format");
diff --git a/user/super/com/google/gwt/emul/javaemul/internal/NativeRegExp.java b/user/super/com/google/gwt/emul/javaemul/internal/NativeRegExp.java
index 6f7ca76..0d3457c 100644
--- a/user/super/com/google/gwt/emul/javaemul/internal/NativeRegExp.java
+++ b/user/super/com/google/gwt/emul/javaemul/internal/NativeRegExp.java
@@ -25,6 +25,6 @@
public int lastIndex;
public NativeRegExp(String regex) { }
public NativeRegExp(String regex, String mode) { }
- public native Object exec(String value);
+ public native String[] exec(String value);
public native boolean test(String value);
}