[tomcat] branch 8.5.x updated: Small optimizations in HpackEncoder

Previous Topic Next Topic
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

[tomcat] branch 8.5.x updated: Small optimizations in HpackEncoder

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

mgrigorov 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 685a58e  Small optimizations in HpackEncoder
685a58e is described below

commit 685a58eb4155135ffe9d8f28acfb1561beb6d3f3
Author: Martin Tzvetanov Grigorov <[hidden email]>
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 a024ca2..7331ca6 100644
--- a/java/org/apache/coyote/http2/HpackEncoder.java
+++ b/java/org/apache/coyote/http2/HpackEncoder.java
@@ -44,7 +44,13 @@ public 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;
+            }
@@ -258,8 +264,8 @@ public 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: [hidden email]
For additional commands, e-mail: [hidden email]