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

schultz 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 bfdd3af5c9 Optimize Request#getCharsetHolder to avoid repeated parsing 
when charset is null
bfdd3af5c9 is described below

commit bfdd3af5c980d659dc287d1113dd0c72f251367f
Author: Gu Ning <56331831+morning...@users.noreply.github.com>
AuthorDate: Fri Jun 13 02:41:05 2025 +0800

    Optimize Request#getCharsetHolder to avoid repeated parsing when charset is 
null
---
 java/org/apache/coyote/Request.java | 12 ++++++++----
 webapps/docs/changelog.xml          |  4 ++++
 2 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/java/org/apache/coyote/Request.java 
b/java/org/apache/coyote/Request.java
index d5a944bc43..ac44637e87 100644
--- a/java/org/apache/coyote/Request.java
+++ b/java/org/apache/coyote/Request.java
@@ -141,7 +141,7 @@ public final class Request {
      */
     private long contentLength = -1;
     private MessageBytes contentTypeMB = null;
-    private CharsetHolder charsetHolder = CharsetHolder.EMPTY;
+    private CharsetHolder charsetHolder = null;
 
     /**
      * Is there an expectation ?
@@ -443,7 +443,7 @@ public final class Request {
 
 
     public CharsetHolder getCharsetHolder() {
-        if (charsetHolder.getName() == null) {
+        if (charsetHolder == null) {
             charsetHolder = 
CharsetHolder.getInstance(getCharsetFromContentType(getContentType()));
         }
         return charsetHolder;
@@ -451,7 +451,11 @@ public final class Request {
 
 
     public void setCharsetHolder(CharsetHolder charsetHolder) {
-        this.charsetHolder = charsetHolder;
+        if (charsetHolder == null || charsetHolder.getName() == null) {
+            this.charsetHolder = null;
+        } else {
+            this.charsetHolder = charsetHolder;
+        }
     }
 
 
@@ -778,7 +782,7 @@ public final class Request {
 
         contentLength = -1;
         contentTypeMB = null;
-        charsetHolder = CharsetHolder.EMPTY;
+        charsetHolder = null;
         expectation = false;
         headers.recycle();
         trailerFields.recycle();
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 5ae43f6442..aa4d336fc1 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -111,6 +111,10 @@
         Ensure application configured welcome files override the defaults when
         configuring an embedded web application programmatically. (markt)
       </fix>
+      <update>
+        Optimize <code>Request#getCharsetHolder</code> to avoid repeated 
parsing
+        when charset is null. Patch provided by morning-gu. (schultz)
+      </update>
     </changelog>
   </subsection>
   <subsection name="Web applications">


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

Reply via email to