Skip to content

Commit 912cefd

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 c8893bd commit 912cefd

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
@@ -126,9 +126,11 @@ object Scanners {
126126

127127
// Setting token data ----------------------------------------------------
128128

129+
protected def initialCharBufferSize = 1024
130+
129131
/** A character buffer for literals
130132
*/
131-
protected val litBuf = CharBuffer()
133+
protected val litBuf = CharBuffer(initialCharBufferSize)
132134

133135
/** append Unicode character to "litBuf" buffer
134136
*/
@@ -242,7 +244,7 @@ object Scanners {
242244
def getDocComment(pos: Int): Option[Comment] = docstringMap.get(pos)
243245

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

247249
def toToken(identifier: SimpleName): Token =
248250
def handleMigration(keyword: Token): Token =
@@ -1076,6 +1078,7 @@ object Scanners {
10761078
next
10771079

10781080
class LookaheadScanner(val allowIndent: Boolean = false) extends Scanner(source, offset, allowIndent = allowIndent) {
1081+
override protected def initialCharBufferSize = 8
10791082
override def languageImportContext = Scanner.this.languageImportContext
10801083
}
10811084

0 commit comments

Comments
 (0)