Improve GC for OnCommittedResponseWrapper

Only track content length if disableOnCommitted is false. This improves object creation and thus GC.

Fixes gh-3842
This commit is contained in:
bartolom 2016-05-02 23:19:21 +02:00 committed by Rob Winch
parent 2bdb0231c2
commit 3ca8273a95
1 changed files with 33 additions and 12 deletions

View File

@ -42,7 +42,8 @@ public abstract class OnCommittedResponseWrapper extends HttpServletResponseWrap
private long contentLength; private long contentLength;
/** /**
* The size of data written to the response body. * The size of data written to the response body. The field will only be updated when
* {@link #disableOnCommitted} is false.
*/ */
private long contentWritten; private long contentWritten;
@ -158,45 +159,65 @@ public abstract class OnCommittedResponseWrapper extends HttpServletResponseWrap
} }
private void trackContentLength(boolean content) { private void trackContentLength(boolean content) {
if (!this.disableOnCommitted) {
checkContentLength(content ? 4 : 5); // TODO Localization checkContentLength(content ? 4 : 5); // TODO Localization
} }
}
private void trackContentLength(char content) { private void trackContentLength(char content) {
if (!this.disableOnCommitted) {
checkContentLength(1); checkContentLength(1);
} }
}
private void trackContentLength(Object content) { private void trackContentLength(Object content) {
if (!this.disableOnCommitted) {
trackContentLength(String.valueOf(content)); trackContentLength(String.valueOf(content));
} }
}
private void trackContentLength(byte[] content) { private void trackContentLength(byte[] content) {
if (!this.disableOnCommitted) {
checkContentLength(content == null ? 0 : content.length); checkContentLength(content == null ? 0 : content.length);
} }
}
private void trackContentLength(char[] content) { private void trackContentLength(char[] content) {
if (!this.disableOnCommitted) {
checkContentLength(content == null ? 0 : content.length); checkContentLength(content == null ? 0 : content.length);
} }
}
private void trackContentLength(int content) { private void trackContentLength(int content) {
if (!this.disableOnCommitted) {
trackContentLength(String.valueOf(content)); trackContentLength(String.valueOf(content));
} }
}
private void trackContentLength(float content) { private void trackContentLength(float content) {
if (!this.disableOnCommitted) {
trackContentLength(String.valueOf(content)); trackContentLength(String.valueOf(content));
} }
}
private void trackContentLength(double content) { private void trackContentLength(double content) {
if (!this.disableOnCommitted) {
trackContentLength(String.valueOf(content)); trackContentLength(String.valueOf(content));
} }
}
private void trackContentLengthLn() { private void trackContentLengthLn() {
if (!this.disableOnCommitted) {
trackContentLength("\r\n"); trackContentLength("\r\n");
} }
}
private void trackContentLength(String content) { private void trackContentLength(String content) {
if (!this.disableOnCommitted) {
int contentLength = content == null ? 4 : content.length(); int contentLength = content == null ? 4 : content.length();
checkContentLength(contentLength); checkContentLength(contentLength);
} }
}
/** /**
* Adds the contentLengthToWrite to the total contentWritten size and checks to see if * Adds the contentLengthToWrite to the total contentWritten size and checks to see if