Skip to content

Commit 58fe948

Browse files
Merge pull request #4264 from dotty-staging/opt/misc
Small optimizations
2 parents 2174d04 + 21e7e71 commit 58fe948

File tree

6 files changed

+21
-11
lines changed

6 files changed

+21
-11
lines changed

compiler/src/dotty/tools/dotc/ast/Trees.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -771,7 +771,7 @@ object Trees {
771771
def flatten[T >: Untyped](trees: List[Tree[T]]): List[Tree[T]] = {
772772
var buf: ListBuffer[Tree[T]] = null
773773
var xs = trees
774-
while (xs.nonEmpty) {
774+
while (!xs.isEmpty) {
775775
xs.head match {
776776
case Thicket(elems) =>
777777
if (buf == null) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ trait Hashable {
6464
var h = seed
6565
var xs = tps
6666
var len = arity
67-
while (xs.nonEmpty) {
67+
while (!xs.isEmpty) {
6868
val elemHash = typeHash(bs, xs.head)
6969
if (elemHash == NotCached) return NotCached
7070
h = hashing.mix(h, elemHash)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ case class Signature(paramsSig: List[TypeName], resSig: TypeName) {
4545
final def consistentParams(that: Signature): Boolean = {
4646
@tailrec def loop(names1: List[TypeName], names2: List[TypeName]): Boolean =
4747
if (names1.isEmpty) names2.isEmpty
48-
else names2.nonEmpty && consistent(names1.head, names2.head) && loop(names1.tail, names2.tail)
48+
else !names2.isEmpty && consistent(names1.head, names2.head) && loop(names1.tail, names2.tail)
4949
loop(this.paramsSig, that.paramsSig)
5050
}
5151

compiler/src/dotty/tools/dotc/parsing/Scanners.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,13 +249,13 @@ object Scanners {
249249
/** Are we directly in a string interpolation expression?
250250
*/
251251
private def inStringInterpolation =
252-
sepRegions.nonEmpty && sepRegions.head == STRINGLIT
252+
!sepRegions.isEmpty && sepRegions.head == STRINGLIT
253253

254254
/** Are we directly in a multiline string interpolation expression?
255255
* @pre inStringInterpolation
256256
*/
257257
private def inMultiLineInterpolation =
258-
inStringInterpolation && sepRegions.tail.nonEmpty && sepRegions.tail.head == STRINGPART
258+
inStringInterpolation && !sepRegions.tail.isEmpty && sepRegions.tail.head == STRINGPART
259259

260260
/** read next token and return last offset
261261
*/

compiler/src/dotty/tools/dotc/transform/SuperAccessors.scala

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,6 @@ class SuperAccessors(thisPhase: DenotTransformer) {
299299
*/
300300
private def needsProtectedAccessor(sym: Symbol, pos: Position)(implicit ctx: Context): Boolean = {
301301
val clazz = currentClass
302-
val host = hostForAccessorOf(sym, clazz)
303302
def accessibleThroughSubclassing =
304303
validCurrentClass && clazz.classInfo.selfType.derivesFrom(sym.owner) && !clazz.is(Trait)
305304

@@ -311,7 +310,13 @@ class SuperAccessors(thisPhase: DenotTransformer) {
311310
&& (sym.enclosingPackageClass != currentClass.enclosingPackageClass)
312311
&& (sym.enclosingPackageClass == sym.accessBoundary(sym.enclosingPackageClass))
313312
)
313+
314+
if (!isCandidate)
315+
return false
316+
317+
val host = hostForAccessorOf(sym, clazz)
314318
val hostSelfType = host.classInfo.selfType
319+
315320
def isSelfType = !(host.appliedRef <:< hostSelfType) && {
316321
if (hostSelfType.typeSymbol.is(JavaDefined))
317322
ctx.restrictionError(
@@ -326,7 +331,7 @@ class SuperAccessors(thisPhase: DenotTransformer) {
326331
)
327332
true
328333
}
329-
isCandidate && !host.is(Package) && !isSelfType && !isJavaProtected
334+
!host.is(Package) && !isSelfType && !isJavaProtected
330335
}
331336

332337
/** Return the innermost enclosing class C of referencingClass for which either

compiler/src/dotty/tools/dotc/typer/Namer.scala

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,12 +1137,17 @@ class Namer { typer: Typer =>
11371137
}
11381138

11391139
def cookedRhsType = deskolemize(dealiasIfUnit(widenRhs(rhsType)))
1140-
lazy val lhsType = fullyDefinedType(cookedRhsType, "right-hand side", mdef.pos)
1140+
def lhsType = fullyDefinedType(cookedRhsType, "right-hand side", mdef.pos)
11411141
//if (sym.name.toString == "y") println(i"rhs = $rhsType, cooked = $cookedRhsType")
1142-
if (inherited.exists)
1143-
if (sym.is(Final, butNot = Method) && lhsType.isInstanceOf[ConstantType])
1144-
lhsType // keep constant types that fill in for a non-constant (to be revised when inline has landed).
1142+
if (inherited.exists) {
1143+
if (sym.is(Final, butNot = Method)) {
1144+
val tp = lhsType
1145+
if (tp.isInstanceOf[ConstantType])
1146+
tp // keep constant types that fill in for a non-constant (to be revised when inline has landed).
1147+
else inherited
1148+
}
11451149
else inherited
1150+
}
11461151
else {
11471152
if (sym is Implicit)
11481153
mdef match {

0 commit comments

Comments
 (0)