Skip to content

Commit 15a54b6

Browse files
committed
Avoid creating large CharBuffers in LookaheadScanners
There are many LookaheadScanner objects, and most don't need a CharBuffer for literals or comments at all.
1 parent 27452fb commit 15a54b6

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

compiler/src/dotty/tools/dotc/parsing/Scanners.scala

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,11 @@ object Scanners {
128128

129129
// Setting token data ----------------------------------------------------
130130

131+
protected def initialCharBufferSize = 1024
132+
131133
/** A character buffer for literals
132134
*/
133-
protected val litBuf = CharBuffer()
135+
protected val litBuf = CharBuffer(initialCharBufferSize)
134136

135137
/** append Unicode character to "litBuf" buffer
136138
*/
@@ -244,7 +246,7 @@ object Scanners {
244246
def getDocComment(pos: Int): Option[Comment] = docstringMap.get(pos)
245247

246248
/** A buffer for comments */
247-
private val commentBuf = CharBuffer()
249+
private val commentBuf = CharBuffer(initialCharBufferSize)
248250

249251
def toToken(identifier: SimpleName): Token =
250252
def handleMigration(keyword: Token): Token =
@@ -1079,6 +1081,7 @@ object Scanners {
10791081
next
10801082

10811083
class LookaheadScanner(val allowIndent: Boolean = false) extends Scanner(source, offset, allowIndent = allowIndent) {
1084+
override protected def initialCharBufferSize = 8
10821085
override def languageImportContext = Scanner.this.languageImportContext
10831086
}
10841087

0 commit comments

Comments
 (0)