Skip to content

Commit 5800569

Browse files
authored
Use BitSet for boolean TASTy attributes (#19092)
2 parents 78c3721 + 476a617 commit 5800569

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@ package dotty.tools.dotc
22
package core.tasty
33

44
import scala.language.unsafeNulls
5+
import scala.collection.immutable.BitSet
56

67
import dotty.tools.tasty.{TastyFormat, TastyReader, TastyBuffer}
78

89
class AttributeUnpickler(reader: TastyReader):
910
import reader._
1011

1112
lazy val attributes: Attributes = {
12-
val booleanTags = List.newBuilder[Int]
13+
val booleanTags = BitSet.newBuilder
1314

1415
while !isAtEnd do
1516
booleanTags += readByte()
Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,26 @@
11
package dotty.tools.dotc.core.tasty
22

3-
import dotty.tools.tasty.TastyFormat
3+
import dotty.tools.tasty.TastyFormat.*
44

5-
class Attributes(
6-
val booleanTags: List[Int],
5+
import scala.collection.immutable.BitSet
6+
7+
class Attributes private[tasty](
8+
private[tasty] val booleanTags: BitSet,
79
) {
8-
def scala2StandardLibrary: Boolean =
9-
booleanTags.contains(TastyFormat.SCALA2STANDARDLIBRARYattr)
10-
def explicitNulls: Boolean =
11-
booleanTags.contains(TastyFormat.EXPLICITNULLSattr)
10+
def scala2StandardLibrary: Boolean = booleanTags(SCALA2STANDARDLIBRARYattr)
11+
def explicitNulls: Boolean = booleanTags(EXPLICITNULLSattr)
1212
}
1313

1414
object Attributes:
1515
def apply(
1616
scala2StandardLibrary: Boolean,
1717
explicitNulls: Boolean,
1818
): Attributes =
19-
val booleanTags = List.newBuilder[Int]
20-
if scala2StandardLibrary then booleanTags += TastyFormat.SCALA2STANDARDLIBRARYattr
21-
if explicitNulls then booleanTags += TastyFormat.EXPLICITNULLSattr
19+
val booleanTags = BitSet.newBuilder
20+
if scala2StandardLibrary then booleanTags += SCALA2STANDARDLIBRARYattr
21+
if explicitNulls then booleanTags += EXPLICITNULLSattr
2222
new Attributes(booleanTags.result())
2323
end apply
24+
25+
val empty: Attributes =
26+
new Attributes(BitSet.empty)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class DottyUnpickler(bytes: Array[Byte], mode: UnpickleMode = UnpickleMode.TopLe
5757
private val treeUnpickler = unpickler.unpickle(treeSectionUnpickler(posUnpicklerOpt, commentUnpicklerOpt, attributeUnpicklerOpt)).get
5858

5959
def tastyAttributes: Attributes =
60-
attributeUnpicklerOpt.map(_.attributes).getOrElse(new Attributes(booleanTags = Nil))
60+
attributeUnpicklerOpt.map(_.attributes).getOrElse(Attributes.empty)
6161

6262
/** Enter all toplevel classes and objects into their scopes
6363
* @param roots a set of SymDenotations that should be overwritten by unpickling

0 commit comments

Comments
 (0)