anuragdy opened a new pull request, #666:
URL: https://github.com/apache/tomcat/pull/666

   Fixes [67080](https://bz.apache.org/bugzilla/show_bug.cgi?id=67080). 
   
   
   Tested the speed using following Test Code -
   
   ```
   package com.amazon.weblab;
   
   import java.util.Arrays;
   import java.util.HashMap;
   
   public class TestImplicitObjectELResolver {
       private static final String[] SCOPE_NAMES = new 
String[]{"applicationScope", "cookie", "header", "headerValues",
               "initParam", "pageContext", "pageScope", "param", "paramValues", 
"requestScope", "sessionScope"};
   
       private enum Scope {
           applicationScope(0), cookie(1), header(2), headerValues(3), 
initParam(4), pageContext(5), pageScope(6), param(7), paramValues(8),
           requestScope(9), sessionScope(10);
   
           final public int idx;
   
           private static final HashMap<String, Scope> lookupMap = new 
HashMap<>();
   
           static {
               lookupMap.put("applicationScope", applicationScope);
               lookupMap.put("cookie", cookie);
               lookupMap.put("header", header);
               lookupMap.put("headerValues", headerValues);
               lookupMap.put("initParam", initParam);
               lookupMap.put("pageContext", pageContext);
               lookupMap.put("pageScope", pageScope);
               lookupMap.put("param", param);
               lookupMap.put("paramValues", paramValues);
               lookupMap.put("requestScope", requestScope);
               lookupMap.put("sessionScope", sessionScope);
           }
   
           Scope(int idx) {
               this.idx = idx;
           }
   
           public static Scope fromValue(String value){
               return lookupMap.get(value);
           }
   
       }
   
       private static final String[] TEST_SCOPES = {"requestScope", 
"pageScope", "sessionScope", "pageContext", "header",
               "applicationScope", "cookie", "headerValues", "initParam", 
"param", "paramValues"};
   
       public static void main(String[] args) {
           new TestImplicitObjectELResolver().runTests();
       }
   
       private final int numTestIterations;
   
       private final int numTests;
   
       public TestImplicitObjectELResolver() {
           numTests = 10;
           numTestIterations = 10000000;
       }
   
       protected void runNewTest() {
           int foundScope = -1;
           for (int i = 0; i < TEST_SCOPES.length; i++) {
               String scope = TEST_SCOPES[i];
               switch (scope) {
                   case "requestScope":
                       foundScope = 1;
                       break;
                   case "pageScope":
                       foundScope = 2;
                       break;
                   case "sessionScope":
                       foundScope = 3;
                       break;
                   case "pageContext":
                       foundScope = 4;
                       break;
                   case "header":
                       foundScope = 5;
                       break;
                   case "applicationScope":
                       foundScope = 6;
                       break;
                   case "cookie":
                       foundScope = 7;
                       break;
                   case "headerValues":
                       foundScope = 8;
                       break;
                   case "initParam":
                       foundScope = 9;
                       break;
                   case "param":
                       foundScope = 10;
                       break;
                   case "paramValues":
                       foundScope = 11;
                       break;
                   default:
                       throw new RuntimeException("Did not find scope for value 
" + scope);
               }
               if (foundScope < 0) {
                   throw new RuntimeException();
               }
           }
       }
   
       protected void runOldTest() {
           for (int i = 0; i < TEST_SCOPES.length; i++) {
               Arrays.binarySearch(SCOPE_NAMES, TEST_SCOPES[i]);
           }
       }
   
       protected void runSecondNewTest() {
           for (int i = 0; i < TEST_SCOPES.length; i++) {
               Scope.fromValue(TEST_SCOPES[i]);
           }
       }
   
       protected void runTests() {
           // warmup
           for (int i = 0; i < numTestIterations; i++) {
               runOldTest();
               runNewTest();
               runSecondNewTest();
           }
   
           for (int i = 0; i < numTests; i++) {
               System.gc();
               long startOld = System.currentTimeMillis();
               for (int j = 0; j < numTestIterations; j++) {
                   runOldTest();
               }
               System.out.println("Done with old in " + 
(System.currentTimeMillis() - startOld));
           }
   
           for (int i = 0; i < numTests; i++) {
               System.gc();
               long startNew = System.currentTimeMillis();
               for (int j = 0; j < numTestIterations; j++) {
                   runNewTest();
               }
               System.out.println("Done with new in " + 
(System.currentTimeMillis() - startNew));
           }
   
           for (int i = 0; i < numTests; i++) {
               System.gc();
               long startNew = System.currentTimeMillis();
               for (int j = 0; j < numTestIterations; j++) {
                   runSecondNewTest();
               }
               System.out.println("Done with runSecondNewTest in " + 
(System.currentTimeMillis() - startNew));
           }
   
       }
   }
   ```
   
   Which produced following output
   
   ```
   Done with old in 663
   Done with old in 737
   Done with old in 734
   Done with old in 738
   Done with old in 742
   Done with old in 737
   Done with old in 734
   Done with old in 734
   Done with old in 736
   Done with old in 735
   Done with new in 373
   Done with new in 374
   Done with new in 373
   Done with new in 373
   Done with new in 373
   Done with new in 373
   Done with new in 374
   Done with new in 373
   Done with new in 375
   Done with new in 373
   Done with runSecondNewTest in 170
   Done with runSecondNewTest in 170
   Done with runSecondNewTest in 169
   Done with runSecondNewTest in 169
   Done with runSecondNewTest in 169
   Done with runSecondNewTest in 173
   Done with runSecondNewTest in 171
   Done with runSecondNewTest in 172
   Done with runSecondNewTest in 171
   Done with runSecondNewTest in 170
   ```


-- 
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.

To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org

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


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

Reply via email to