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

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

commit 92d2f1317a68f88f60ebfe56cf123bfbd510ab58
Author: Martin Tzvetanov Grigorov <mgrigo...@apache.org>
AuthorDate: Thu Sep 24 13:42:18 2020 +0300

    Small optimizations in HpackEncoder
    
    1) Use switch(String) instead of series of String.equals() calls. The 
switch uses String.hashCode() and falls back to .equals() only if there are 
cases with the same hash code.
    2) Reduce memory allocations: no need to Map.Entry since the key is never 
used
    
    (cherry picked from commit d2ed8ffc75c5e3b425888b456ffc51036d94ac39)
---
 java/org/apache/coyote/http2/HpackEncoder.java | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/java/org/apache/coyote/http2/HpackEncoder.java 
b/java/org/apache/coyote/http2/HpackEncoder.java
index dda5714..ae81033 100644
--- a/java/org/apache/coyote/http2/HpackEncoder.java
+++ b/java/org/apache/coyote/http2/HpackEncoder.java
@@ -44,7 +44,13 @@ class HpackEncoder {
         public boolean shouldUseIndexing(String headerName, String value) {
             //content length and date change all the time
             //no need to index them, or they will churn the table
-            return !headerName.equals("content-length") && 
!headerName.equals("date");
+            switch (headerName) {
+                case "content-length":
+                case "date":
+                    return false;
+                default:
+                    return true;
+            }
         }
 
         @Override
@@ -258,8 +264,8 @@ class HpackEncoder {
     private void preventPositionRollover() {
         //if the position counter is about to roll over we iterate all the 
table entries
         //and set their position to their actual position
-        for (Map.Entry<String, List<TableEntry>> entry : 
dynamicTable.entrySet()) {
-            for (TableEntry t : entry.getValue()) {
+        for (List<TableEntry> tableEntries : dynamicTable.values()) {
+            for (TableEntry t : tableEntries) {
                 t.position = t.getPosition();
             }
         }


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

Reply via email to