@@ -7,7 +7,7 @@ import core.StdNames._, core.Comments._
7
7
import util .SourceFile
8
8
import java .lang .Character .isDigit
9
9
import scala .internal .Chars ._
10
- import util .SourcePosition
10
+ import util .{ SourcePosition , CharBuffer }
11
11
import util .Spans .Span
12
12
import config .Config
13
13
import config .Printers .lexical
@@ -21,38 +21,6 @@ import config.Feature.migrateTo3
21
21
import config .SourceVersion ._
22
22
import reporting .Message
23
23
24
- object Cbufs {
25
- import java .lang .StringBuilder
26
-
27
- private final val TargetCapacity = 256
28
-
29
- opaque type Cbuf = StringBuilder
30
- object Cbuf :
31
- def apply (): Cbuf = new StringBuilder (TargetCapacity )
32
-
33
- extension (buf : Cbuf ):
34
- def clear (): Unit = {
35
- if buf.capacity() > TargetCapacity then
36
- buf.setLength(TargetCapacity )
37
- buf.trimToSize()
38
- end if
39
- buf.setLength(0 )
40
- }
41
- def toCharArray : Array [Char ] = {
42
- val n = buf.length()
43
- val res = new Array [Char ](n)
44
- buf.getChars(0 , n, res, 0 )
45
- res
46
- }
47
- def append (c : Char ): buf.type = { buf.append(c) ; buf }
48
- def isEmpty : Boolean = buf.length() == 0
49
- def length : Int = buf.length()
50
- def last : Char = buf.charAt(buf.length() - 1 )
51
- end extension
52
- }
53
-
54
- import Cbufs ._
55
-
56
24
object Scanners {
57
25
58
26
/** Offset into source character array */
@@ -142,22 +110,16 @@ object Scanners {
142
110
143
111
/** A character buffer for literals
144
112
*/
145
- protected val litBuf = Cbuf ()
113
+ protected val litBuf = CharBuffer ()
146
114
147
115
/** append Unicode character to "litBuf" buffer
148
116
*/
149
117
protected def putChar (c : Char ): Unit = litBuf.append(c)
150
118
151
- /** Return buffer contents and clear */
152
- def flushBuf (buf : Cbuf ): String = {
153
- val str = buf.toString
154
- buf.clear()
155
- str
156
- }
157
-
158
119
/** Clear buffer and set name and token */
159
120
def finishNamed (idtoken : Token = IDENTIFIER , target : TokenData = this ): Unit = {
160
- target.name = termName(flushBuf(litBuf))
121
+ target.name = termName(litBuf.chars, 0 , litBuf.length)
122
+ litBuf.clear()
161
123
target.token = idtoken
162
124
if (idtoken == IDENTIFIER )
163
125
target.token = toToken(target.name)
@@ -168,7 +130,8 @@ object Scanners {
168
130
169
131
/** Clear buffer and set string */
170
132
def setStrVal (): Unit =
171
- strVal = flushBuf(litBuf)
133
+ strVal = litBuf.toString
134
+ litBuf.clear()
172
135
173
136
@ inline def isNumberSeparator (c : Char ): Boolean = c == '_'
174
137
@@ -241,7 +204,7 @@ object Scanners {
241
204
def getDocComment (pos : Int ): Option [Comment ] = docstringMap.get(pos)
242
205
243
206
/** A buffer for comments */
244
- private val commentBuf = Cbuf ()
207
+ private val commentBuf = CharBuffer ()
245
208
246
209
private def handleMigration (keyword : Token ): Token =
247
210
if keyword == ERASED && ! ctx.settings.YerasedTerms .value then IDENTIFIER
@@ -888,7 +851,8 @@ object Scanners {
888
851
def finishComment (): Boolean = {
889
852
if (keepComments) {
890
853
val pos = Span (start, charOffset - 1 , start)
891
- val comment = Comment (pos, flushBuf(commentBuf))
854
+ val comment = Comment (pos, commentBuf.toString)
855
+ commentBuf.clear()
892
856
commentPosBuf += pos
893
857
894
858
if (comment.isDocComment)
0 commit comments