commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pascalschumac...@apache.org
Subject [lang] use StringBuilder#append(CharSequence, int, int) were possible to improve performance
Date Thu, 12 Oct 2017 17:53:23 GMT
Repository: commons-lang
Updated Branches:
  refs/heads/master 04ca0852b -> 713c77ced


use StringBuilder#append(CharSequence, int, int) were possible to improve performance

(similar to LANG-1358, thanks to Stephane Landelle for the suggestion)


Project: http://git-wip-us.apache.org/repos/asf/commons-lang/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-lang/commit/713c77ce
Tree: http://git-wip-us.apache.org/repos/asf/commons-lang/tree/713c77ce
Diff: http://git-wip-us.apache.org/repos/asf/commons-lang/diff/713c77ce

Branch: refs/heads/master
Commit: 713c77ceda21d0c3cc9c213341259d64fb46fdc7
Parents: 04ca085
Author: pascalschumacher <pascalschumacher@gmx.net>
Authored: Thu Oct 12 19:53:14 2017 +0200
Committer: pascalschumacher <pascalschumacher@gmx.net>
Committed: Thu Oct 12 19:53:14 2017 +0200

----------------------------------------------------------------------
 .../org/apache/commons/lang3/builder/ToStringStyle.java   |  3 +--
 .../java/org/apache/commons/lang3/text/WordUtils.java     | 10 +++++-----
 2 files changed, 6 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-lang/blob/713c77ce/src/main/java/org/apache/commons/lang3/builder/ToStringStyle.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/lang3/builder/ToStringStyle.java b/src/main/java/org/apache/commons/lang3/builder/ToStringStyle.java
index f40ecce..e24aa31 100644
--- a/src/main/java/org/apache/commons/lang3/builder/ToStringStyle.java
+++ b/src/main/java/org/apache/commons/lang3/builder/ToStringStyle.java
@@ -387,11 +387,10 @@ public abstract class ToStringStyle implements Serializable {
             final int pos1 = toString.indexOf(contentStart) + contentStart.length();
             final int pos2 = toString.lastIndexOf(contentEnd);
             if (pos1 != pos2 && pos1 >= 0 && pos2 >= 0) {
-                final String data = toString.substring(pos1, pos2);
                 if (fieldSeparatorAtStart) {
                     removeLastFieldSeparator(buffer);
                 }
-                buffer.append(data);
+                buffer.append(toString, pos1, pos2);
                 appendFieldSeparator(buffer);
             }
         }

http://git-wip-us.apache.org/repos/asf/commons-lang/blob/713c77ce/src/main/java/org/apache/commons/lang3/text/WordUtils.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/lang3/text/WordUtils.java b/src/main/java/org/apache/commons/lang3/text/WordUtils.java
index fef20d0..b4c5999 100644
--- a/src/main/java/org/apache/commons/lang3/text/WordUtils.java
+++ b/src/main/java/org/apache/commons/lang3/text/WordUtils.java
@@ -308,7 +308,7 @@ public class WordUtils {
 
             if (spaceToWrapAt >= offset) {
                 // normal case
-                wrappedLine.append(str.substring(offset, spaceToWrapAt));
+                wrappedLine.append(str, offset, spaceToWrapAt);
                 wrappedLine.append(newLineStr);
                 offset = spaceToWrapAt + 1;
 
@@ -316,7 +316,7 @@ public class WordUtils {
                 // really long word or URL
                 if (wrapLongWords) {
                     // wrap really long word one line at a time
-                    wrappedLine.append(str.substring(offset, wrapLength + offset));
+                    wrappedLine.append(str, offset, wrapLength + offset);
                     wrappedLine.append(newLineStr);
                     offset += wrapLength;
                 } else {
@@ -327,11 +327,11 @@ public class WordUtils {
                     }
 
                     if (spaceToWrapAt >= 0) {
-                        wrappedLine.append(str.substring(offset, spaceToWrapAt));
+                        wrappedLine.append(str, offset, spaceToWrapAt);
                         wrappedLine.append(newLineStr);
                         offset = spaceToWrapAt + 1;
                     } else {
-                        wrappedLine.append(str.substring(offset));
+                        wrappedLine.append(str, offset, str.length());
                         offset = inputLineLength;
                     }
                 }
@@ -339,7 +339,7 @@ public class WordUtils {
         }
 
         // Whatever is left in line is short enough to just pass through
-        wrappedLine.append(str.substring(offset));
+        wrappedLine.append(str, offset, str.length());
 
         return wrappedLine.toString();
     }


Mime
View raw message