Skip to content
This repository has been archived by the owner on Jun 10, 2020. It is now read-only.

Commit

Permalink
Merge pull request #232 from diesalbla/recycle_string_builder_storage
Browse files Browse the repository at this point in the history
ConsoleAppender: reuse/recycle StringBuilder storage
  • Loading branch information
eed3si9n authored Oct 22, 2019
2 parents f5358db + 3657910 commit 098796c
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package sbt.internal.util

import sbt.util._
import java.io.{ PrintStream, PrintWriter }
import java.lang.StringBuilder
import java.util.Locale
import java.util.concurrent.atomic.{ AtomicBoolean, AtomicInteger, AtomicReference }
import org.apache.logging.log4j.{ Level => XLevel }
Expand Down Expand Up @@ -507,10 +508,10 @@ class ConsoleAppender private[ConsoleAppender] (
message: String
): Unit =
out.lockObject.synchronized {
val builder: StringBuilder = new StringBuilder(labelColor.length + label.length + messageColor.length + reset.length * 3)
message.linesIterator.foreach { line =>
val builder = new java.lang.StringBuilder(
labelColor.length + label.length + messageColor.length + line.length + reset.length * 3 + 3
)
builder.ensureCapacity(labelColor.length + label.length + messageColor.length + line.length + reset.length * 3 + 3)
builder.setLength(0)
def fmted(a: String, b: String) = builder.append(reset).append(a).append(b).append(reset)
builder.append(reset).append('[')
fmted(labelColor, label)
Expand Down

0 comments on commit 098796c

Please sign in to comment.