You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by sc...@apache.org on 2019/05/08 19:17:14 UTC

[tomcat] branch 8.5.x updated: Remove custom split() method. String.split is already optimized for single-character splits and won't use a regex.

This is an automated email from the ASF dual-hosted git repository.

schultz pushed a commit to branch 8.5.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/8.5.x by this push:
     new f295e8d  Remove custom split() method. String.split is already optimized for single-character splits and won't use a regex.
f295e8d is described below

commit f295e8da59b8719bb3e159d0ea37a3a813d9a81d
Author: Christopher Schultz <ch...@christopherschultz.net>
AuthorDate: Wed May 8 21:15:20 2019 +0200

    Remove custom split() method. String.split is already optimized for
    single-character splits and won't use a regex.
---
 .../apache/catalina/servlets/DefaultServlet.java   | 75 +---------------------
 1 file changed, 1 insertion(+), 74 deletions(-)

diff --git a/java/org/apache/catalina/servlets/DefaultServlet.java b/java/org/apache/catalina/servlets/DefaultServlet.java
index 59dea4e..fdcb1da 100644
--- a/java/org/apache/catalina/servlets/DefaultServlet.java
+++ b/java/org/apache/catalina/servlets/DefaultServlet.java
@@ -2804,7 +2804,7 @@ public class DefaultServlet extends HttpServlet {
             if(null == order || 0 == order.trim().length())
                 return Order.DEFAULT;
 
-            String[] options = split(order);
+            String[] options = order.split(";");
 
             if(0 == options.length)
                 return Order.DEFAULT;
@@ -2851,79 +2851,6 @@ public class DefaultServlet extends HttpServlet {
             return Order.DEFAULT;
         }
 
-        /**
-         * Split a string using a semicolon as a delimiter.
-         *
-         * @param s The string to split.
-         *
-         * @return An array of non-empty/null strings which have been
-         *         separated by semicolons.
-         */
-        private String[] split(String s) {
-            if(null == s)
-                return new String[0];
-            s = s.trim();
-            int length = s.length();
-            if(0 == length)
-                return new String[0];
-
-            String[] strings;
-
-            int index = 0;
-            int start = 0;
-            int pos = s.indexOf(';');
-
-            if(0 <= pos) {
-                int len = 2;
-                strings = new String[len]; // Usually just 2 options
-
-                while(0 <= pos) {
-                    if(len > 9)
-                        pos = length; // Maximum of 10 options
-
-                    if(index + 1 > len) {
-                        // Expand by double
-                        String[] old = strings;
-                        strings = new String[old.length << 1];
-                        System.arraycopy(old, 0, strings, 0, len);
-                        len = len << 1;
-                    }
-
-                    String option = s.substring(start, pos).trim();
-
-                    if(0 < option.length()) {
-                        strings[index++] = option;
-                    }
-
-                    start = pos + 1;
-                    pos = s.indexOf(';', start);
-                }
-
-                if(start < length) {
-                    String option = s.substring(start).trim();
-
-                    if(0 < option.length()) {
-                        strings[index] = option;
-                    } else {
-                        index--;
-                    }
-                } else {
-                    index--;
-                }
-
-                if(len > index) {
-                    // Shrink
-                    String[] old = strings;
-                    strings = new String[index + 1];
-                    System.arraycopy(old, 0, strings, 0, index + 1);
-                }
-            } else {
-                strings = new String[] { s };
-            }
-
-            return strings;
-        }
-
         public static class Order {
             final char column;
             final boolean ascending;


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org