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

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


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

commit cba91c71767559c0e7c707cc27ca2fd5f12bf200
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 38515e3460..341c612e2b 100644
--- a/java/org/apache/catalina/util/ParameterMap.java
+++ b/java/org/apache/catalina/util/ParameterMap.java
@@ -82,7 +82,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);
     }
 
@@ -95,7 +100,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 ce6977fbaf..02e3094384 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -127,6 +127,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