You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by GitBox <gi...@apache.org> on 2020/06/05 06:37:06 UTC

[GitHub] [commons-lang] XenoAmess commented on a change in pull request #534: [LANG-1548] split regionMatches for better performance

XenoAmess commented on a change in pull request #534:
URL: https://github.com/apache/commons-lang/pull/534#discussion_r435717449



##########
File path: src/main/java/org/apache/commons/lang3/CharSequenceUtils.java
##########
@@ -252,17 +252,58 @@ static int lastIndexOf(final CharSequence cs, final CharSequence searchChar, fin
      * Green implementation of regionMatches.
      *
      * @param cs the {@code CharSequence} to be processed
-     * @param ignoreCase whether or not to be case insensitive
      * @param thisStart the index to start on the {@code cs} CharSequence
      * @param substring the {@code CharSequence} to be looked for
      * @param start the index to start on the {@code substring} CharSequence
      * @param length character length of the region
      * @return whether the region matched
      */
-    static boolean regionMatches(final CharSequence cs, final boolean ignoreCase, final int thisStart,
-            final CharSequence substring, final int start, final int length)    {
+    static boolean regionMatches(final CharSequence cs, final int thisStart,
+                                 final CharSequence substring, final int start, final int length)    {
+        if (cs instanceof String && substring instanceof String) {
+            return ((String) cs).regionMatches(thisStart, (String) substring, start, length);
+        }
+        int index1 = thisStart;
+        int index2 = start;
+        int tmpLen = length;
+
+        // Extract these first so we detect NPEs the same as the java.lang.String version
+        final int srcLen = cs.length() - thisStart;
+        final int otherLen = substring.length() - start;
+
+        // Check for invalid parameters
+        if (thisStart < 0 || start < 0 || length < 0) {
+            return false;
+        }
+
+        // Check that the regions are long enough
+        if (srcLen < length || otherLen < length) {
+            return false;
+        }
+
+        while (tmpLen-- > 0) {

Review comment:
       the `while (tmpLen-- > 0) {` is same as it in original codes.
   I just want to make as less changes as possible.
   If you think we should reformat the codes I feel like agreed, but lets' do that after this pr, or at least, when merging this pr.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org