Skip to content

Commit 5570895

Browse files
committed
Micro-optimizations: Streamline isStatic, isStaticOwner and isRoot
1 parent eec815a commit 5570895

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

compiler/src/dotty/tools/dotc/core/SymDenotations.scala

+7-10
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ object SymDenotations {
115115
*/
116116
class SymDenotation private[SymDenotations] (
117117
symbol: Symbol,
118-
ownerIfExists: Symbol,
118+
final val maybeOwner: Symbol,
119119
final val name: Name,
120120
initFlags: FlagSet,
121121
initInfo: Type,
@@ -140,10 +140,7 @@ object SymDenotations {
140140
private[this] var myAnnotations: List[Annotation] = Nil
141141

142142
/** The owner of the symbol; overridden in NoDenotation */
143-
def owner: Symbol = ownerIfExists
144-
145-
/** Same as owner, except returns NoSymbol for NoSymbol */
146-
def maybeOwner: Symbol = if (exists) owner else NoSymbol
143+
def owner: Symbol = maybeOwner
147144

148145
/** The flag set */
149146
final def flags(implicit ctx: Context): FlagSet = { ensureCompleted(); myFlags }
@@ -178,9 +175,8 @@ object SymDenotations {
178175
else AfterLoadFlags)
179176

180177
/** Has this denotation one of the flags in `fs` set? */
181-
final def is(fs: FlagSet)(implicit ctx: Context) = {
178+
final def is(fs: FlagSet)(implicit ctx: Context) =
182179
(if (isCurrent(fs)) myFlags else flags) is fs
183-
}
184180

185181
/** Has this denotation one of the flags in `fs` set, whereas none of the flags
186182
* in `butNot` are set?
@@ -457,7 +453,7 @@ object SymDenotations {
457453

458454
/** Is this symbol the root class or its companion object? */
459455
final def isRoot: Boolean =
460-
(name.toTermName == nme.ROOT || name == nme.ROOTPKG) && (owner eq NoSymbol)
456+
(maybeOwner eq NoSymbol) && (name.toTermName == nme.ROOT || name == nme.ROOTPKG)
461457

462458
/** Is this symbol the empty package class or its companion object? */
463459
final def isEmptyPackage(implicit ctx: Context): Boolean =
@@ -562,11 +558,12 @@ object SymDenotations {
562558

563559
/** Is this denotation static (i.e. with no outer instance)? */
564560
final def isStatic(implicit ctx: Context) =
565-
(this is JavaStatic) || this.exists && owner.isStaticOwner || this.isRoot
561+
(if (maybeOwner eq NoSymbol) isRoot else maybeOwner.isStaticOwner) ||
562+
myFlags.is(JavaStatic)
566563

567564
/** Is this a package class or module class that defines static symbols? */
568565
final def isStaticOwner(implicit ctx: Context): Boolean =
569-
(this is PackageClass) || (this is ModuleClass) && isStatic
566+
myFlags.is(ModuleClass) && (myFlags.is(PackageClass) || isStatic)
570567

571568
/** Is this denotation defined in the same scope and compilation unit as that symbol? */
572569
final def isCoDefinedWith(that: Symbol)(implicit ctx: Context) =

0 commit comments

Comments
 (0)