Improve array checking for Serializable/Clonable.
Check if something is array over class instance is costly and
direct check is simple to implement.
Change-Id: Iaeb32125ded3cde99a6f53bc40cc65d3ce41b838
diff --git a/user/super/com/google/gwt/emul/java/io/Serializable.java b/user/super/com/google/gwt/emul/java/io/Serializable.java
index 3032baf..9458df5 100644
--- a/user/super/com/google/gwt/emul/java/io/Serializable.java
+++ b/user/super/com/google/gwt/emul/java/io/Serializable.java
@@ -16,6 +16,7 @@
package java.io;
import javaemul.internal.JsUtils;
+import javaemul.internal.NativeArray;
import jsinterop.annotations.JsMethod;
/**
@@ -37,7 +38,7 @@
|| type.equals("string")
|| instance.getTypeMarker()
// Arrays are implicitly instances of Serializable (JLS 10.7).
- || instance.getClass().isArray();
+ || NativeArray.isArray(instance);
}
// CHECKSTYLE_ON: end utility methods
}
diff --git a/user/super/com/google/gwt/emul/java/lang/Cloneable.java b/user/super/com/google/gwt/emul/java/lang/Cloneable.java
index 74535b4..907f569 100644
--- a/user/super/com/google/gwt/emul/java/lang/Cloneable.java
+++ b/user/super/com/google/gwt/emul/java/lang/Cloneable.java
@@ -15,6 +15,7 @@
*/
package java.lang;
+import javaemul.internal.NativeArray;
import jsinterop.annotations.JsMethod;
/**
@@ -31,7 +32,7 @@
return instance.getTypeMarker()
// Arrays are implicitly instances of Cloneable (JLS 10.7).
- || instance.getClass().isArray();
+ || NativeArray.isArray(instance);
}
// CHECKSTYLE_ON: end utility methods
}
diff --git a/user/super/com/google/gwt/emul/javaemul/internal/NativeArray.java b/user/super/com/google/gwt/emul/javaemul/internal/NativeArray.java
index 7f0ea99..792ab3c 100644
--- a/user/super/com/google/gwt/emul/javaemul/internal/NativeArray.java
+++ b/user/super/com/google/gwt/emul/javaemul/internal/NativeArray.java
@@ -39,4 +39,6 @@
public native Object[] slice(int fromIndex, int toIndex);
public native void splice(int index, int deleteCount, @DoNotAutobox Object... value);
public native <T> void sort(CompareFunction compareFunction);
+
+ public static native boolean isArray(Object o);
}