[HTTPCLIENT-1858] Clone some code from Log4j 2 to cache a StringBuilder

in a ThreadLocal. Update to use the StringBuilder's capacity instead of
its length to measure upper bound.
This commit is contained in:
Gary Gregory 2017-07-25 15:25:20 -07:00 committed by Oleg Kalnichevski
parent fe6b90a8c6
commit f2146cab62

View File

@ -64,7 +64,7 @@ private static StringBuilder getStringBuilder() {
*/ */
// TODO Delete wheb Log4j's 2.9 (see #trimToMaxSize(StringBuild)) // TODO Delete wheb Log4j's 2.9 (see #trimToMaxSize(StringBuild))
private static void trimToMaxSize(final StringBuilder stringBuilder, final int maxSize) { private static void trimToMaxSize(final StringBuilder stringBuilder, final int maxSize) {
if (stringBuilder != null && stringBuilder.length() > maxSize) { if (stringBuilder != null && stringBuilder.capacity() > maxSize) {
stringBuilder.setLength(maxSize); stringBuilder.setLength(maxSize);
stringBuilder.trimToSize(); stringBuilder.trimToSize();
} }