harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r785730 - /harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/String.java
Date Wed, 17 Jun 2009 17:07:13 GMT
Author: tellison
Date: Wed Jun 17 17:07:13 2009
New Revision: 785730

URL: http://svn.apache.org/viewvc?rev=785730&view=rev
Log:
Add two new private constructors to String that can be invoked by the JIT as optimizations
when compiling string handling code,
e.g. Common expressions like  String s = s1 + s2;  generates something of the form  String
s = new StringBuffer().append(s1).append(s2).toString(); but with the helpers it can be more
efficiently represented as String s = new String(s1, s2);

Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/String.java

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/String.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/String.java?rev=785730&r1=785729&r2=785730&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/String.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/String.java Wed Jun
17 17:07:13 2009
@@ -162,6 +162,9 @@
         count = 0;
     }
 
+    /*
+     * Private constructor used for JIT optimization.
+     */
     @SuppressWarnings("unused")
     private String(String s, char c) {
         offset = 0;
@@ -412,6 +415,47 @@
         count = string.count;
     }
 
+    /*
+     * Private constructor useful for JIT optimization.
+     */
+    @SuppressWarnings( { "unused", "nls" })
+    private String(String s1, String s2) {
+        if (s1 == null) {
+            s1 = "null";
+        }
+        if (s2 == null) {
+            s2 = "null";
+        }
+        count = s1.count + s2.count;
+        value = new char[count];
+        offset = 0;
+        System.arraycopy(s1.value, s1.offset, value, 0, s1.count);
+        System.arraycopy(s2.value, s2.offset, value, s1.count, s2.count);
+    }
+
+    /*
+     * Private constructor useful for JIT optimization.
+     */
+    @SuppressWarnings( { "unused", "nls" })
+    private String(String s1, String s2, String s3) {
+        if (s1 == null) {
+            s1 = "null";
+        }
+        if (s2 == null) {
+            s2 = "null";
+        }
+        if (s3 == null) {
+            s3 = "null";
+        }
+        count = s1.count + s2.count + s3.count;
+        value = new char[count];
+        offset = 0;
+        System.arraycopy(s1.value, s1.offset, value, 0, s1.count);
+        System.arraycopy(s2.value, s2.offset, value, s1.count, s2.count);
+        System.arraycopy(s3.value, s3.offset, value, s1.count + s2.count,
+                s3.count);
+    }
+
     /**
      * Creates a {@code String} from the contents of the specified
      * {@code StringBuffer}.



Mime
View raw message