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

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


The following commit(s) were added to refs/heads/11.0.x by this push:
     new 30d02c8c9c Further performance improvements for ParameterMap. 
(jengebr/markt)
30d02c8c9c is described below

commit 30d02c8c9ca44f3d46c49f7ee02acf3c2c5481b5
Author: Mark Thomas <[email protected]>
AuthorDate: Fri Sep 19 17:04:54 2025 +0100

    Further performance improvements for ParameterMap. (jengebr/markt)
---
 java/org/apache/catalina/util/ParameterMap.java | 14 ++++++++++++--
 webapps/docs/changelog.xml                      |  3 +++
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/java/org/apache/catalina/util/ParameterMap.java 
b/java/org/apache/catalina/util/ParameterMap.java
index fc8208f442..ca1d65b8d9 100644
--- a/java/org/apache/catalina/util/ParameterMap.java
+++ b/java/org/apache/catalina/util/ParameterMap.java
@@ -84,7 +84,12 @@ public final class ParameterMap<K, V> implements Map<K,V>, 
Serializable {
      * @param map Map whose contents are duplicated in the new map
      */
     public ParameterMap(Map<K,V> map) {
-        delegatedMap = new LinkedHashMap<>(map);
+        // Unroll loop for performance - 
https://bz.apache.org/bugzilla/show_bug.cgi?id=69820
+        int mapSize = map.size();
+        delegatedMap = new LinkedHashMap<>((int) (mapSize * 1.5));
+        for (Map.Entry<K, V> entry : map.entrySet()) {
+            delegatedMap.put(entry.getKey(), entry.getValue());
+        }
         unmodifiableDelegatedMap = Collections.unmodifiableMap(delegatedMap);
     }
 
@@ -97,7 +102,12 @@ public final class ParameterMap<K, V> implements Map<K,V>, 
Serializable {
      * @param map Map whose contents are duplicated in the new map
      */
     public ParameterMap(ParameterMap<K,V> map) {
-        delegatedMap = new LinkedHashMap<>(map.delegatedMap);
+        // Unroll loop for performance - 
https://bz.apache.org/bugzilla/show_bug.cgi?id=69820
+        int mapSize = map.size();
+        delegatedMap = new LinkedHashMap<>((int) (mapSize * 1.5));
+        for (Map.Entry<K, V> entry : map.entrySet()) {
+            delegatedMap.put(entry.getKey(), entry.getValue());
+        }
         unmodifiableDelegatedMap = Collections.unmodifiableMap(delegatedMap);
     }
 
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 4c7bd33371..0b2f7256b0 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -121,6 +121,9 @@
         <bug>69814</bug>: Ensure that <code>HttpSession.isNew()</code> returns
         <code>false</code> once the client has joined the session. (markt)
       </fix>
+      <fix>
+        Further performance improvements for ParameterMap. (jengebr/markt)
+      </fix>
     </changelog>
   </subsection>
   <subsection name="Coyote">


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to