Skip to content

Commit 30f639d

Browse files
committed
Do not pickle number of lines
1 parent 6e47481 commit 30f639d

File tree

3 files changed

+12
-24
lines changed

3 files changed

+12
-24
lines changed

compiler/src/dotty/tools/dotc/core/tasty/LineSizesPickler.scala

+4-10
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,14 @@ class LineSizesPickler(pickler: TastyPickler) {
2222
val buf: TastyBuffer = new TastyBuffer(5000)
2323
pickler.newSection("LineSizes", buf)
2424

25-
def pickleLineNumbers(source: SourceFile): Unit = {
25+
def pickleLineNumbers(source: SourceFile): Unit =
2626
val content = source.content()
27-
28-
val numLines = content.count(_ == '\n')
29-
buf.writeInt(numLines + 1)
30-
3127
var lastIndex = content.indexOf('\n', 0)
3228
buf.writeInt(lastIndex) // size of first line
3329
while lastIndex != -1 do
3430
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
3933
lastIndex = nextIndex
40-
}
34+
4135
}

compiler/src/dotty/tools/dotc/core/tasty/LineSizesUnpickler.scala

+8-13
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,18 @@ import Names.TermName
1515
class LineSizesUnpickler(reader: TastyReader) {
1616
import reader._
1717

18-
private var myLines: Int = _
1918
private var mySizes: Array[Int] = _
2019
private var isDefined = false
2120

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()
2829
isDefined = true
29-
}
30-
}
31-
32-
private[tasty] def lines: Int =
33-
ensureDefined()
34-
myLines
3530

3631
private[tasty] def sizes: Array[Int] =
3732
ensureDefined()

compiler/src/dotty/tools/dotc/core/tasty/TastyPrinter.scala

-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,6 @@ class TastyPrinter(bytes: Array[Byte]) {
163163
sb.append(" ").append(reader.endAddr.index - reader.currentAddr.index)
164164
sb.append(" line sizes bytes:\n")
165165
val lineSizes = new LineSizesUnpickler(reader)
166-
sb.append(" lines: ").append(lineSizes.lines).append("\n")
167166
sb.append(" sizes: ")
168167
sb.append(lineSizes.sizes.mkString(", "))
169168
sb.result

0 commit comments

Comments
 (0)