changeset 5247:8baf1c812ced

iOS: replacing StringBuffer occurrences in favour of StringBuilder
author Oldrich Maticka <oldrich.maticka@oracle.com>
date Thu, 03 Oct 2013 16:00:56 +0200
parents abbc53855b43
children 5fd60ebdb9d5
files modules/web/src/ios/java/javafx/scene/web/ExportedJavaObject.java modules/web/src/ios/java/javafx/scene/web/JS2JavaBridge.java modules/web/src/ios/java/javafx/scene/web/JSONEncoder.java
diffstat 3 files changed, 18 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/modules/web/src/ios/java/javafx/scene/web/ExportedJavaObject.java	Thu Oct 03 06:51:27 2013 -0700
+++ b/modules/web/src/ios/java/javafx/scene/web/ExportedJavaObject.java	Thu Oct 03 16:00:56 2013 +0200
@@ -248,7 +248,9 @@
         }
 
         try {
-            return getJSBridge().encode(resObj);
+            StringBuilder sb = new StringBuilder(1024);
+            getJSBridge().encode(resObj, sb);
+            return sb.toString();
         } catch (Exception ex) {
             throw new CallException("Result encoding error", ex);
         }
--- a/modules/web/src/ios/java/javafx/scene/web/JS2JavaBridge.java	Thu Oct 03 06:51:27 2013 -0700
+++ b/modules/web/src/ios/java/javafx/scene/web/JS2JavaBridge.java	Thu Oct 03 16:00:56 2013 +0200
@@ -107,13 +107,14 @@
         if (exportedObjectsByJSIds.containsValue(jsObj)) {
             return;
         }
-        StringBuilder sb = new StringBuilder(getJavaBridge());
+        StringBuilder sb;
+        sb = new StringBuilder(1024).append(getJavaBridge());
         String script = sb.append("['").append(jsName).append("'] = ").append(jsObj.getJSDecl()).toString();
         log(script);
         log("populateObject>>executeScript");
         webEngine.executeScriptDirect(script);
-        
-        sb = new StringBuilder( getJavaBridge()).append(".exportJSObject(").append(
+        sb.delete(0, sb.length());
+        sb = sb.append(getJavaBridge()).append(".exportJSObject(").append(
              getJavaBridge()).append("['").append(jsName).append("'])");
         
         Long jsId = (Long) webEngine.executeScript(sb.toString());
@@ -137,12 +138,9 @@
     }
     
     void encode(Object arg, StringBuilder script) {
-        script.append(encoder.encode(arg));
+        encoder.encode(script, arg);
     }
 
-    String encode(Object arg) {
-        return encoder.encode(arg);
-    }
     
     String getjsIdForJavaObject(Object object) {
         
@@ -229,7 +227,8 @@
                 String result = jsObj.call(methodId, args);
                 if (!"0".equals(callbackID)) {
                     String script;
-                    script = new StringBuilder(getJavaBridge()).append(".callBack(").append(callbackID).append(", true").append(
+                    StringBuilder sb = new StringBuilder(1024);
+                    script = sb.append(getJavaBridge()).append(".callBack(").append(callbackID).append(", true").append(
                          (result == null ? "" : ", " + result)).append(")").toString();
                     if (_log) {
                         log("result callback script (success): >" + script + "<");
@@ -243,9 +242,10 @@
                 log(ex);
                 // report failure
                 if (!"".equals(callbackID)) {
-                    String errStr = encoder.encode(ex.getMessage());
-                    String script = new StringBuilder(getJavaBridge()).append(".callBack(").
-                            append(callbackID).append(", false, ").append(errStr).append(")").toString();
+                    StringBuilder sb = new StringBuilder(1024).append(getJavaBridge()).append(".callBack(").
+                            append(callbackID).append(", false, ");
+                    encoder.encode(sb,ex.getMessage());
+                    String script = sb.append(")").toString();
                     log("result callback script (failure): >" + script + "<");
                     log(">>executeScript");
                     webEngine.executeScriptDirect(script);
--- a/modules/web/src/ios/java/javafx/scene/web/JSONEncoder.java	Thu Oct 03 06:51:27 2013 -0700
+++ b/modules/web/src/ios/java/javafx/scene/web/JSONEncoder.java	Thu Oct 03 16:00:56 2013 +0200
@@ -36,15 +36,10 @@
         this.owner = owner;
     }
     
-    public String encode(Object object) {
-        StringBuffer sb = new StringBuffer();
-        encode(sb, object);
-        return sb.toString();
-    }
     
     private static char[] hexChars = "0123456789abcdef".toCharArray();
     
-    private static void encodeString(StringBuffer sb, String s) {
+    private static void encodeString(StringBuilder sb, String s) {
         sb.append('"');
         for (int i=0; i<s.length(); i++) {
             char ch = s.charAt(i);
@@ -90,7 +85,7 @@
         sb.append('"');
     }
     
-    private void encode(StringBuffer sb, Object object) {
+    public void encode(StringBuilder sb, Object object) {
         if (object == null) {
             sb.append("null");
         } else if (object instanceof String || object instanceof Character) {
@@ -117,7 +112,7 @@
 
     //return true if we were able to find index into exportedJSObjects[] for 
     //passed object; false otherwise
-    private boolean encodedJavaObject(Object object, StringBuffer sb) {
+    private boolean encodedJavaObject(Object object, StringBuilder sb) {
         String jsId = owner.getjsIdForJavaObject(object);
         if (jsId != null) {
             sb.append(owner.getJavaBridge()).append(".exportedJSObjects[").append(jsId).append("]"); //reuse object
@@ -126,7 +121,7 @@
         return false;
     }
     
-    private void encodeJavaObject(Object object, StringBuffer sb) {
+    private void encodeJavaObject(Object object, StringBuilder sb) {
         if (!encodedJavaObject(object, sb)) {
             owner.exportObject("anyname",object);
             if (!encodedJavaObject(object, sb)) { // bridge was not exported yet