Skip to content

Commit 8d83354

Browse files
committed
Avoid creating NumericalRange instances when not needed
1 parent 70eb2b9 commit 8d83354

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,21 +111,21 @@ class Definitions {
111111
val decls = newScope
112112
val arity = name.functionArity
113113
val paramNamePrefix = tpnme.scala_ ++ str.NAME_JOIN ++ name ++ str.EXPAND_SEPARATOR
114-
val argParams =
115-
for (i <- List.range(1, arity + 1)) yield
116-
enterTypeParam(cls, paramNamePrefix ++ "T" ++ i.toString, Contravariant, decls)
114+
val argParams = List.tabulate(arity) { i =>
115+
enterTypeParam(cls, paramNamePrefix ++ "T" ++ (i + 1).toString, Contravariant, decls).typeRef
116+
}
117117
val resParam = enterTypeParam(cls, paramNamePrefix ++ "R", Covariant, decls)
118118
val (methodType, parentTraits) =
119119
if (name.firstPart.startsWith(str.ImplicitFunction)) {
120120
val superTrait =
121-
FunctionType(arity).appliedTo(argParams.map(_.typeRef) ::: resParam.typeRef :: Nil)
121+
FunctionType(arity).appliedTo(argParams ::: resParam.typeRef :: Nil)
122122
(ImplicitMethodType, superTrait :: Nil)
123123
}
124124
else (MethodType, Nil)
125125
val applyMeth =
126126
decls.enter(
127127
newMethod(cls, nme.apply,
128-
methodType(argParams.map(_.typeRef), resParam.typeRef), Deferred))
128+
methodType(argParams, resParam.typeRef), Deferred))
129129
denot.info =
130130
ClassInfo(ScalaPackageClass.thisType, cls, ObjectType :: parentTraits, decls)
131131
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
690690
val MethodTpe(_, formals, restpe) = meth.info
691691
(formals, restpe)
692692
case _ =>
693-
(List.range(0, defaultArity) map alwaysWildcardType, WildcardType)
693+
(List.tabulate(defaultArity)(alwaysWildcardType), WildcardType)
694694
}
695695

696696
def typedFunction(tree: untpd.Function, pt: Type)(implicit ctx: Context) = track("typedFunction") {

compiler/src/dotty/tools/dotc/util/SourcePosition.scala

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,12 @@ extends interfaces.SourcePosition {
2626
source.content.slice(source.startOfLine(start), source.nextLine(end))
2727

2828
/** The lines of the position */
29-
def lines: List[Int] =
30-
List.range(source.offsetToLine(start), source.offsetToLine(end + 1)) match {
31-
case Nil => line :: Nil
32-
case xs => xs
33-
}
29+
def lines: List[Int] = {
30+
val startOffset = source.offsetToLine(start)
31+
val endOffest = source.offsetToLine(end + 1)
32+
if (startOffset >= endOffest) line :: Nil
33+
else List.tabulate(endOffest - startOffset)(i => i + startOffset)
34+
}
3435

3536
def lineOffsets: List[Int] =
3637
lines.map(source.lineToOffset(_))

0 commit comments

Comments
 (0)