tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1408774 - in /tomcat/trunk: java/org/apache/jasper/el/JasperELResolver.java test/org/apache/jasper/el/ test/org/apache/jasper/el/TestJasperELResolver.java
Date Tue, 13 Nov 2012 15:14:31 GMT
Author: markt
Date: Tue Nov 13 15:14:30 2012
New Revision: 1408774

URL: http://svn.apache.org/viewvc?rev=1408774&view=rev
Log:
Optimisation suggested by kkolinko and a test case to make sure it does what it is meant to.
The test case is obvious but I missed something in my first look at the code so wrote the
test case which may as well be kept.

Added:
    tomcat/trunk/test/org/apache/jasper/el/
    tomcat/trunk/test/org/apache/jasper/el/TestJasperELResolver.java   (with props)
Modified:
    tomcat/trunk/java/org/apache/jasper/el/JasperELResolver.java

Modified: tomcat/trunk/java/org/apache/jasper/el/JasperELResolver.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/jasper/el/JasperELResolver.java?rev=1408774&r1=1408773&r2=1408774&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/jasper/el/JasperELResolver.java (original)
+++ tomcat/trunk/java/org/apache/jasper/el/JasperELResolver.java Tue Nov 13 15:14:30 2012
@@ -44,8 +44,8 @@ public class JasperELResolver extends Co
 
     public JasperELResolver(List<ELResolver> appResolvers) {
         appResolversSize = appResolvers.size();
-        resolvers = new ELResolver[0];
-        size = resolvers.length;
+        resolvers = new ELResolver[appResolversSize + 7];
+        size = 0;
 
         add(new ImplicitObjectELResolver());
         for (ELResolver appResolver : appResolvers) {
@@ -63,11 +63,15 @@ public class JasperELResolver extends Co
     public synchronized void add(ELResolver elResolver) {
         super.add(elResolver);
 
-        ELResolver[] nr = new ELResolver[size + 1];
-        System.arraycopy(resolvers, 0, nr, 0, size);
-        nr[size] = elResolver;
+        if (resolvers.length < size) {
+            resolvers[size] = elResolver;
+        } else {
+            ELResolver[] nr = new ELResolver[size + 1];
+            System.arraycopy(resolvers, 0, nr, 0, size);
+            nr[size] = elResolver;
 
-        resolvers = nr;
+            resolvers = nr;
+        }
         size ++;
     }
 

Added: tomcat/trunk/test/org/apache/jasper/el/TestJasperELResolver.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/jasper/el/TestJasperELResolver.java?rev=1408774&view=auto
==============================================================================
--- tomcat/trunk/test/org/apache/jasper/el/TestJasperELResolver.java (added)
+++ tomcat/trunk/test/org/apache/jasper/el/TestJasperELResolver.java Tue Nov 13 15:14:30 2012
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jasper.el;
+
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.el.ELResolver;
+import javax.servlet.jsp.el.ImplicitObjectELResolver;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TestJasperELResolver {
+
+    @Test
+    public void testConstructorNone() throws Exception {
+        doTestConstructor(0);
+    }
+
+    @Test
+    public void testConstructorOne() throws Exception {
+        doTestConstructor(1);
+    }
+
+    @Test
+    public void testConstructorFive() throws Exception {
+        doTestConstructor(5);
+    }
+
+    private void doTestConstructor(int count) throws Exception {
+
+        List<ELResolver> list = new ArrayList<>();
+        for (int i = 0; i < count; i++) {
+            list.add(new ImplicitObjectELResolver());
+        }
+
+        JasperELResolver resolver = new JasperELResolver(list);
+
+
+        Assert.assertEquals(Integer.valueOf(count),
+                getField("appResolversSize", resolver));
+        Assert.assertEquals(7 + count,
+                ((ELResolver[])getField("resolvers", resolver)).length);
+        Assert.assertEquals(Integer.valueOf(7 + count),
+                getField("size", resolver));
+
+    }
+
+    private static final Object getField(String name, Object target)
+            throws NoSuchFieldException, SecurityException,
+            IllegalArgumentException, IllegalAccessException {
+        Field field = target.getClass().getDeclaredField(name);
+        field.setAccessible(true);
+        return field.get(target);
+    }
+}

Propchange: tomcat/trunk/test/org/apache/jasper/el/TestJasperELResolver.java
------------------------------------------------------------------------------
    svn:eol-style = native



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


Mime
View raw message