File tree 3 files changed +12
-24
lines changed
compiler/src/dotty/tools/dotc/core/tasty
3 files changed +12
-24
lines changed Original file line number Diff line number Diff line change @@ -22,20 +22,14 @@ class LineSizesPickler(pickler: TastyPickler) {
22
22
val buf : TastyBuffer = new TastyBuffer (5000 )
23
23
pickler.newSection(" LineSizes" , buf)
24
24
25
- def pickleLineNumbers (source : SourceFile ): Unit = {
25
+ def pickleLineNumbers (source : SourceFile ): Unit =
26
26
val content = source.content()
27
-
28
- val numLines = content.count(_ == '\n ' )
29
- buf.writeInt(numLines + 1 )
30
-
31
27
var lastIndex = content.indexOf('\n ' , 0 )
32
28
buf.writeInt(lastIndex) // size of first line
33
29
while lastIndex != - 1 do
34
30
val nextIndex = content.indexOf('\n ' , lastIndex + 1 )
35
- if nextIndex != - 1 then
36
- buf.writeInt(nextIndex - lastIndex - 1 ) // size of the next line
37
- else
38
- buf.writeInt(content.length - 1 - lastIndex) // size of the last line
31
+ val end = if nextIndex != - 1 then nextIndex else content.length
32
+ buf.writeInt(end - lastIndex - 1 ) // size of the next line
39
33
lastIndex = nextIndex
40
- }
34
+
41
35
}
Original file line number Diff line number Diff line change @@ -15,23 +15,18 @@ import Names.TermName
15
15
class LineSizesUnpickler (reader : TastyReader ) {
16
16
import reader ._
17
17
18
- private var myLines : Int = _
19
18
private var mySizes : Array [Int ] = _
20
19
private var isDefined = false
21
20
22
- def ensureDefined (): Unit = {
23
- if (! isDefined) {
24
- myLines = readInt()
25
- mySizes = new Array (myLines)
26
- for i <- 0 until myLines do
27
- mySizes(i) = readInt()
21
+ def ensureDefined (): Unit =
22
+ if ! isDefined then
23
+ val sizeBuf = Array .newBuilder[Int ]
24
+ // Number of lines if all lines are 127 characters or less
25
+ var lowSizeBound = endAddr.index - currentAddr.index
26
+ sizeBuf.sizeHint(lowSizeBound)
27
+ while ! isAtEnd do sizeBuf += readInt()
28
+ mySizes = sizeBuf.result()
28
29
isDefined = true
29
- }
30
- }
31
-
32
- private [tasty] def lines : Int =
33
- ensureDefined()
34
- myLines
35
30
36
31
private [tasty] def sizes : Array [Int ] =
37
32
ensureDefined()
Original file line number Diff line number Diff line change @@ -163,7 +163,6 @@ class TastyPrinter(bytes: Array[Byte]) {
163
163
sb.append(" " ).append(reader.endAddr.index - reader.currentAddr.index)
164
164
sb.append(" line sizes bytes:\n " )
165
165
val lineSizes = new LineSizesUnpickler (reader)
166
- sb.append(" lines: " ).append(lineSizes.lines).append(" \n " )
167
166
sb.append(" sizes: " )
168
167
sb.append(lineSizes.sizes.mkString(" , " ))
169
168
sb.result
You can’t perform that action at this time.
0 commit comments