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

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


The following commit(s) were added to refs/heads/master by this push:
     new f7c41d1  Replace custom split(String,String) method with call to 
String.split.
f7c41d1 is described below

commit f7c41d120c6374a8221b684a5ad5ede3d1621ff4
Author: Christopher Schultz <ch...@christopherschultz.net>
AuthorDate: Wed May 8 21:55:13 2019 +0200

    Replace custom split(String,String) method with call to String.split.
    
    String.split will optimize for a single-character delimiter and not
    actually use the regular expression engine.
---
 java/org/apache/jasper/compiler/JspUtil.java | 37 +++++-----------------------
 1 file changed, 6 insertions(+), 31 deletions(-)

diff --git a/java/org/apache/jasper/compiler/JspUtil.java 
b/java/org/apache/jasper/compiler/JspUtil.java
index 3a65eff..bf2f41c 100644
--- a/java/org/apache/jasper/compiler/JspUtil.java
+++ b/java/org/apache/jasper/compiler/JspUtil.java
@@ -741,45 +741,20 @@ public class JspUtil {
      * @return Java package corresponding to the given path
      */
     public static final String makeJavaPackage(String path) {
-        String classNameComponents[] = split(path, "/");
+        String classNameComponents[] = path.split("/");
         StringBuilder legalClassNames = new StringBuilder();
         for (int i = 0; i < classNameComponents.length; i++) {
-            legalClassNames.append(makeJavaIdentifier(classNameComponents[i]));
-            if (i < classNameComponents.length - 1) {
-                legalClassNames.append('.');
+            if(0 < classNameComponents[i].length()) {
+                if(0 < i) {
+                    legalClassNames.append('.');
+                }
+                
legalClassNames.append(makeJavaIdentifier(classNameComponents[i]));
             }
         }
         return legalClassNames.toString();
     }
 
     /**
-     * Splits a string into it's components.
-     *
-     * @param path
-     *            String to split
-     * @param pat
-     *            Pattern to split at
-     * @return the components of the path
-     */
-    private static final String[] split(String path, String pat) {
-        ArrayList<String> comps = new ArrayList<>();
-        int pos = path.indexOf(pat);
-        int start = 0;
-        while (pos >= 0) {
-            if (pos > start) {
-                String comp = path.substring(start, pos);
-                comps.add(comp);
-            }
-            start = pos + pat.length();
-            pos = path.indexOf(pat, start);
-        }
-        if (start < path.length()) {
-            comps.add(path.substring(start));
-        }
-        return comps.toArray(new String[comps.size()]);
-    }
-
-    /**
      * Converts the given identifier to a legal Java identifier
      *
      * @param identifier


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

Reply via email to