Skip to content

Commit d56a6aa

Browse files
committed
optimise some definitions
1 parent c03bc93 commit d56a6aa

File tree

8 files changed

+21
-18
lines changed

8 files changed

+21
-18
lines changed

compiler/src/dotty/tools/dotc/semanticdb/Language.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ object Language {
1515
case 0 => UNKNOWN_LANGUAGE
1616
case 1 => SCALA
1717
case 2 => JAVA
18-
case __other => Unrecognized(__other)
18+
case id => Unrecognized(id)
1919
}
2020

2121
}

compiler/src/dotty/tools/dotc/semanticdb/Range.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import dotty.tools.dotc.semanticdb.internal._
44
import scala.annotation.internal.sharable
55

66
object Range {
7-
lazy val defaultInstance: Range = Range(0, 0, 0, 0)
7+
val defaultInstance: Range = Range(0, 0, 0, 0)
88
}
99

1010
final case class Range(

compiler/src/dotty/tools/dotc/semanticdb/Scala.scala

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import dotty.tools.dotc.core.Symbols.{ Symbol => DottySymbol, defn }
44
import dotty.tools.dotc.core.Contexts.Context
55
import dotty.tools.dotc.core.Flags._
66

7+
import scala.annotation.internal.sharable
8+
import scala.annotation.switch
9+
710
object Scala with
811

912
object Symbols with
@@ -28,13 +31,13 @@ object Scala with
2831
else
2932
symbol.name.show
3033

31-
32-
private val locals = raw"local(\d+)"
34+
@sharable
35+
private val locals = raw"local(\d+)".r
3336

3437
object LocalSymbol with
3538
def unapply(symbolInfo: SymbolInformation): Option[Int] =
3639
symbolInfo.symbol match
37-
case locals.r(ints) =>
40+
case locals(ints) =>
3841
val bi = BigInt(ints)
3942
if bi.isValidInt then Some(bi.toInt) else None
4043
case _ => None
@@ -48,14 +51,16 @@ object Scala with
4851
def isEmptyPackage: Boolean =
4952
symbol == Symbols.EmptyPackage
5053
def isGlobal: Boolean =
51-
!symbol.isNoSymbol && !symbol.isMulti && (symbol.last match {
54+
!symbol.isNoSymbol
55+
&& !symbol.isMulti
56+
&& { (symbol.last: @switch) match
5257
case '.' | '#' | '/' | ')' | ']' => true
5358
case _ => false
54-
})
59+
}
5560
def isLocal: Boolean =
56-
symbol.matches(locals)
61+
locals matches symbol
5762
def isMulti: Boolean =
58-
symbol.startsWith(";")
63+
symbol startsWith ";"
5964
def isTerm: Boolean =
6065
!symbol.isNoSymbol && !symbol.isMulti && symbol.last == '.'
6166
def isType: Boolean =

compiler/src/dotty/tools/dotc/semanticdb/Schema.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ object Schema {
1515
case 0 => LEGACY
1616
case 3 => SEMANTICDB3
1717
case 4 => SEMANTICDB4
18-
case __other => Unrecognized(__other)
18+
case id => Unrecognized(id)
1919
}
2020

2121
}

compiler/src/dotty/tools/dotc/semanticdb/SymbolInformation.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import scala.annotation.internal.sharable
55

66
object SymbolInformation {
77

8-
lazy val defaultInstance = SymbolInformation("", Language.UNKNOWN_LANGUAGE, SymbolInformation.Kind.UNKNOWN_KIND, 0, "")
8+
val defaultInstance = SymbolInformation("", Language.UNKNOWN_LANGUAGE, SymbolInformation.Kind.UNKNOWN_KIND, 0, "")
99

1010
sealed trait Kind(val value: Int) extends SemanticdbEnum derives Eql {
1111
def isUnknownKind: Boolean = this == Kind.UNKNOWN_KIND

compiler/src/dotty/tools/dotc/semanticdb/SymbolOccurrence.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ object SymbolOccurrence {
2121
case 0 => UNKNOWN_ROLE
2222
case 1 => REFERENCE
2323
case 2 => DEFINITION
24-
case __other => Unrecognized(__other)
24+
case id => Unrecognized(id)
2525
}
2626

2727
}
2828

29-
lazy val defaultInstance: SymbolOccurrence = SymbolOccurrence("", None, Role.UNKNOWN_ROLE)
29+
val defaultInstance: SymbolOccurrence = SymbolOccurrence("", None, Role.UNKNOWN_ROLE)
3030
}
3131

3232
final case class SymbolOccurrence(

compiler/src/dotty/tools/dotc/semanticdb/TextDocument.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import dotty.tools.dotc.semanticdb.internal._
44
import scala.annotation.internal.sharable
55

66
object TextDocument {
7-
lazy val defaultInstance: TextDocument = TextDocument(Schema.LEGACY, Language.UNKNOWN_LANGUAGE, "", "", "", Nil, Nil)
7+
val defaultInstance: TextDocument = TextDocument(Schema.LEGACY, Language.UNKNOWN_LANGUAGE, "", "", "", Nil, Nil)
88
}
99

1010
final case class TextDocument(

compiler/src/dotty/tools/dotc/semanticdb/TextDocuments.scala

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ object TextDocuments {
1010
def parseFrom(in: SemanticdbInputStream): TextDocuments = {
1111
defaultInstance.mergeFrom(in)
1212
}
13-
lazy val defaultInstance: TextDocuments = TextDocuments(Nil)
13+
val defaultInstance: TextDocuments = TextDocuments(Nil)
1414
}
1515
final case class TextDocuments(documents: Seq[TextDocument]) extends SemanticdbMessage[TextDocuments] derives Eql {
1616
@sharable
@@ -53,8 +53,6 @@ final case class TextDocuments(documents: Seq[TextDocument]) extends SemanticdbM
5353
case tag => _input__.skipField(tag)
5454
}
5555
}
56-
TextDocuments(
57-
documents = __documents.result()
58-
)
56+
TextDocuments(documents = __documents.result())
5957
}
6058
}

0 commit comments

Comments
 (0)