This is an automated email from the ASF dual-hosted git repository. schultz pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/main by this push: new a652b71630 Optimize Request#getCharsetHolder to avoid repeated parsing when charset is null a652b71630 is described below commit a652b71630c2ca68e72757f0325629436ddda9da 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 e2870bf06e..451361bd06 100644 --- a/java/org/apache/coyote/Request.java +++ b/java/org/apache/coyote/Request.java @@ -139,7 +139,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 ? @@ -389,7 +389,7 @@ public final class Request { // -------------------- encoding/type -------------------- public CharsetHolder getCharsetHolder() { - if (charsetHolder.getName() == null) { + if (charsetHolder == null) { charsetHolder = CharsetHolder.getInstance(getCharsetFromContentType(getContentType())); } return charsetHolder; @@ -397,7 +397,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; + } } @@ -724,7 +728,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 ef55820e92..270f4c2e6a 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -187,6 +187,10 @@ <update> Remove NIO2 connector. (remm) </update> + <update> + Optimize <code>Request#getCharsetHolder</code> to avoid repeated parsing + when charset is null. Patch provided by morning-gu. (schultz) + </update> <!-- Entries for backport and removal before 12.0.0-M1 below this line --> </changelog> </subsection> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org