This is an automated email from the ASF dual-hosted git repository.
markt 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 a329e8b4a9 Further performance improvements for BZ 68089
a329e8b4a9 is described below
commit a329e8b4a9d0697b0a888d28d4ab02fa4e0789ee
Author: Mark Thomas <[email protected]>
AuthorDate: Mon Feb 12 14:05:38 2024 +0000
Further performance improvements for BZ 68089
https://bz.apache.org/bugzilla/show_bug.cgi?id=68089
---
.../catalina/core/ApplicationHttpRequest.java | 15 ++++++++++
.../apache/catalina/core/ApplicationRequest.java | 35 ++++++++++++----------
webapps/docs/changelog.xml | 5 ++++
3 files changed, 40 insertions(+), 15 deletions(-)
diff --git a/java/org/apache/catalina/core/ApplicationHttpRequest.java
b/java/org/apache/catalina/core/ApplicationHttpRequest.java
index 931a34d18b..8142a3bd05 100644
--- a/java/org/apache/catalina/core/ApplicationHttpRequest.java
+++ b/java/org/apache/catalina/core/ApplicationHttpRequest.java
@@ -89,6 +89,9 @@ class ApplicationHttpRequest extends
HttpServletRequestWrapper {
}
}
+ private static final int shortestSpecialNameLength =
+ specialsMap.keySet().stream().mapToInt(s ->
s.length()).min().getAsInt();
+
private static final int SPECIALS_FIRST_FORWARD_INDEX = 6;
@@ -733,6 +736,10 @@ class ApplicationHttpRequest extends
HttpServletRequestWrapper {
* @param name Attribute name to be tested
*/
protected boolean isSpecial(String name) {
+ // Performance - see BZ 68089
+ if (name.length() < shortestSpecialNameLength) {
+ return false;
+ }
return specialsMap.containsKey(name);
}
@@ -743,6 +750,10 @@ class ApplicationHttpRequest extends
HttpServletRequestWrapper {
* @return the special attribute pos, or -1 if it is not a special
attribute
*/
protected int getSpecial(String name) {
+ // Performance - see BZ 68089
+ if (name.length() < shortestSpecialNameLength) {
+ return -1;
+ }
Integer index = specialsMap.get(name);
if (index == null) {
return -1;
@@ -757,6 +768,10 @@ class ApplicationHttpRequest extends
HttpServletRequestWrapper {
* @return true if the attribute was a special attribute, false otherwise
*/
protected boolean setSpecial(String name, Object value) {
+ // Performance - see BZ 68089
+ if (name.length() < shortestSpecialNameLength) {
+ return false;
+ }
Integer index = specialsMap.get(name);
if (index == null) {
return false;
diff --git a/java/org/apache/catalina/core/ApplicationRequest.java
b/java/org/apache/catalina/core/ApplicationRequest.java
index fc9516392d..5828045816 100644
--- a/java/org/apache/catalina/core/ApplicationRequest.java
+++ b/java/org/apache/catalina/core/ApplicationRequest.java
@@ -59,6 +59,9 @@ class ApplicationRequest extends ServletRequestWrapper {
*/
private static final Set<String> specialsSet = new
HashSet<>(Arrays.asList(specials));
+ private static final int shortestSpecialNameLength =
+ specialsSet.stream().mapToInt(s -> s.length()).min().getAsInt();
+
/**
* The request attributes for this request. This is initialized from the
wrapped request, but updates are allowed.
@@ -135,6 +138,23 @@ class ApplicationRequest extends ServletRequestWrapper {
}
+ /**
+ * Is this attribute name one of the special ones that is added only for
included servlets?
+ *
+ * @param name Attribute name to be tested
+ *
+ * @deprecated Will be made private in Tomcat 11 onwards.
+ */
+ @Deprecated
+ protected boolean isSpecial(String name) {
+ // Performance - see BZ 68089
+ if (name.length() < shortestSpecialNameLength) {
+ return false;
+ }
+ return specialsSet.contains(name);
+ }
+
+
// ------------------------------------------ ServletRequestWrapper Methods
/**
@@ -157,19 +177,4 @@ class ApplicationRequest extends ServletRequestWrapper {
}
}
}
-
-
- // ------------------------------------------------------ Protected Methods
-
- /**
- * Is this attribute name one of the special ones that is added only for
included servlets?
- *
- * @param name Attribute name to be tested
- *
- * @deprecated Will be removed without replacement in Tomcat 11 onwards.
- */
- @Deprecated
- protected boolean isSpecial(String name) {
- return specialsSet.contains(name);
- }
}
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index d243122586..a5a63eadef 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -120,6 +120,11 @@
Review usage of debug logging and downgrade trace or data dumping
operations from debug level to trace. (remm)
</fix>
+ <fix>
+ <bug>68089</bug>: Further improve the performance of request attribute
+ access for <code>ApplicationHttpRequest</code> and
+ <code>ApplicationRequest</code>. (markt)
+ </fix>
<fix>
<bug>68559</bug>: Allow asynchronous error handling to write to the
response after an error during asynchronous processing. (markt)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]