mirror of https://github.com/sbt/sbt.git
Switch from Vector to List in Settings
Using List instead of vector makes the code a bit more readable. We don't need indexed access into the data structure so its unlikely that Vector was providing any performance benefit.
This commit is contained in:
parent
fdeb6be667
commit
d18cb83b3c
|
|
@ -36,7 +36,7 @@ private[sbt] object Settings {
|
||||||
val cleanScopes = new java.util.HashSet[Scope].asScala
|
val cleanScopes = new java.util.HashSet[Scope].asScala
|
||||||
transformed.flatMap {
|
transformed.flatMap {
|
||||||
case s if s.key.key == sbt.nio.Keys.fileInputs.key => inputPathSettings(s)
|
case s if s.key.key == sbt.nio.Keys.fileInputs.key => inputPathSettings(s)
|
||||||
case s => maybeAddOutputsAndFileStamps(s, fileOutputScopes, cleanScopes)
|
case s => s :: maybeAddOutputsAndFileStamps(s, fileOutputScopes, cleanScopes)
|
||||||
} ++ addCleanImpls(cleanScopes.toSeq)
|
} ++ addCleanImpls(cleanScopes.toSeq)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -57,27 +57,20 @@ private[sbt] object Settings {
|
||||||
setting: Def.Setting[_],
|
setting: Def.Setting[_],
|
||||||
fileOutputScopes: Set[Scope],
|
fileOutputScopes: Set[Scope],
|
||||||
cleanScopes: mutable.Set[Scope]
|
cleanScopes: mutable.Set[Scope]
|
||||||
): Seq[Def.Setting[_]] = {
|
): List[Def.Setting[_]] = {
|
||||||
setting.key.key match {
|
setting.key.key match {
|
||||||
case ak: AttributeKey[_] if taskClass.isAssignableFrom(ak.manifest.runtimeClass) =>
|
case ak: AttributeKey[_] if taskClass.isAssignableFrom(ak.manifest.runtimeClass) =>
|
||||||
def default: Seq[Def.Setting[_]] = {
|
def default: List[Def.Setting[_]] = {
|
||||||
val scope = setting.key.scope.copy(task = Select(ak))
|
val scope = setting.key.scope.copy(task = Select(ak))
|
||||||
if (fileOutputScopes.contains(scope)) {
|
if (fileOutputScopes.contains(scope)) {
|
||||||
val sk = setting.asInstanceOf[Def.Setting[Task[Any]]].key
|
val sk = setting.asInstanceOf[Def.Setting[Task[Any]]].key
|
||||||
val scopedKey = sk.scopedKey.copy(sk.scope in sk.key, Keys.dynamicFileOutputs.key)
|
val scopedKey = sk.scopedKey.copy(sk.scope in sk.key, Keys.dynamicFileOutputs.key)
|
||||||
cleanScopes.add(scope)
|
cleanScopes.add(scope)
|
||||||
Vector(
|
addTaskDefinition {
|
||||||
setting,
|
val init: Def.Initialize[Task[Seq[Path]]] = sk(_.map(_ => Nil))
|
||||||
addTaskDefinition {
|
Def.setting[Task[Seq[Path]]](scopedKey, init, setting.pos)
|
||||||
val init: Def.Initialize[Task[Seq[Path]]] = sk(_.map(_ => Nil))
|
} :: allOutputPathsImpl(scope) :: outputFileStampsImpl(scope) :: cleanImpl(scope) :: Nil
|
||||||
Def.setting[Task[Seq[Path]]](scopedKey, init, setting.pos)
|
} else Nil
|
||||||
}
|
|
||||||
) ++ Vector(
|
|
||||||
allOutputPathsImpl(scope),
|
|
||||||
outputFileStampsImpl(scope),
|
|
||||||
cleanImpl(scope)
|
|
||||||
)
|
|
||||||
} else setting :: Nil
|
|
||||||
}
|
}
|
||||||
ak.manifest.typeArguments match {
|
ak.manifest.typeArguments match {
|
||||||
case t :: Nil if seqClass.isAssignableFrom(t.runtimeClass) =>
|
case t :: Nil if seqClass.isAssignableFrom(t.runtimeClass) =>
|
||||||
|
|
@ -86,51 +79,39 @@ private[sbt] object Settings {
|
||||||
case f :: Nil if fileClass.isAssignableFrom(f.runtimeClass) =>
|
case f :: Nil if fileClass.isAssignableFrom(f.runtimeClass) =>
|
||||||
val sk = setting.asInstanceOf[Def.Setting[Task[Seq[File]]]].key
|
val sk = setting.asInstanceOf[Def.Setting[Task[Seq[File]]]].key
|
||||||
val scopedKey = sk.scopedKey.copy(sk.scope in sk.key, Keys.dynamicFileOutputs.key)
|
val scopedKey = sk.scopedKey.copy(sk.scope in sk.key, Keys.dynamicFileOutputs.key)
|
||||||
Vector(
|
addTaskDefinition {
|
||||||
setting,
|
val init: Def.Initialize[Task[Seq[Path]]] = sk(_.map(_.map(_.toPath)))
|
||||||
addTaskDefinition {
|
Def.setting[Task[Seq[Path]]](scopedKey, init, setting.pos)
|
||||||
val init: Def.Initialize[Task[Seq[Path]]] = sk(_.map(_.map(_.toPath)))
|
} :: outputsAndStamps(TaskKey(sk.key) in sk.scope, cleanScopes)
|
||||||
Def.setting[Task[Seq[Path]]](scopedKey, init, setting.pos)
|
|
||||||
}
|
|
||||||
) ++ outputsAndStamps(TaskKey(sk.key) in sk.scope, cleanScopes)
|
|
||||||
// Task[Seq[Path]]
|
// Task[Seq[Path]]
|
||||||
case p :: Nil if pathClass.isAssignableFrom(p.runtimeClass) =>
|
case p :: Nil if pathClass.isAssignableFrom(p.runtimeClass) =>
|
||||||
val sk = setting.asInstanceOf[Def.Setting[Task[Seq[Path]]]].key
|
val sk = setting.asInstanceOf[Def.Setting[Task[Seq[Path]]]].key
|
||||||
val scopedKey = sk.scopedKey.copy(sk.scope in sk.key, Keys.dynamicFileOutputs.key)
|
val scopedKey = sk.scopedKey.copy(sk.scope in sk.key, Keys.dynamicFileOutputs.key)
|
||||||
Vector(
|
addTaskDefinition {
|
||||||
setting,
|
val init: Def.Initialize[Task[Seq[Path]]] = sk(_.map(identity))
|
||||||
addTaskDefinition {
|
Def.setting[Task[Seq[Path]]](scopedKey, init, setting.pos)
|
||||||
val init: Def.Initialize[Task[Seq[Path]]] = sk(_.map(identity))
|
} :: outputsAndStamps(TaskKey(sk.key) in sk.scope, cleanScopes)
|
||||||
Def.setting[Task[Seq[Path]]](scopedKey, init, setting.pos)
|
|
||||||
}
|
|
||||||
) ++ outputsAndStamps(TaskKey(sk.key) in sk.scope, cleanScopes)
|
|
||||||
case _ => default
|
case _ => default
|
||||||
}
|
}
|
||||||
// Task[File]
|
// Task[File]
|
||||||
case t :: Nil if fileClass.isAssignableFrom(t.runtimeClass) =>
|
case t :: Nil if fileClass.isAssignableFrom(t.runtimeClass) =>
|
||||||
val sk = setting.asInstanceOf[Def.Setting[Task[File]]].key
|
val sk = setting.asInstanceOf[Def.Setting[Task[File]]].key
|
||||||
val scopedKey = sk.scopedKey.copy(sk.scope in sk.key, Keys.dynamicFileOutputs.key)
|
val scopedKey = sk.scopedKey.copy(sk.scope in sk.key, Keys.dynamicFileOutputs.key)
|
||||||
Vector(
|
addTaskDefinition {
|
||||||
setting,
|
val init: Def.Initialize[Task[Seq[Path]]] = sk(_.map(_.toPath :: Nil))
|
||||||
addTaskDefinition {
|
Def.setting[Task[Seq[Path]]](scopedKey, init, setting.pos)
|
||||||
val init: Def.Initialize[Task[Seq[Path]]] = sk(_.map(_.toPath :: Nil))
|
} :: outputsAndStamps(TaskKey(sk.key) in sk.scope, cleanScopes)
|
||||||
Def.setting[Task[Seq[Path]]](scopedKey, init, setting.pos)
|
|
||||||
}
|
|
||||||
) ++ outputsAndStamps(TaskKey(sk.key) in sk.scope, cleanScopes)
|
|
||||||
// Task[Path]
|
// Task[Path]
|
||||||
case t :: Nil if pathClass.isAssignableFrom(t.runtimeClass) =>
|
case t :: Nil if pathClass.isAssignableFrom(t.runtimeClass) =>
|
||||||
val sk = setting.asInstanceOf[Def.Setting[Task[Path]]].key
|
val sk = setting.asInstanceOf[Def.Setting[Task[Path]]].key
|
||||||
val scopedKey = sk.scopedKey.copy(sk.scope in sk.key, Keys.dynamicFileOutputs.key)
|
val scopedKey = sk.scopedKey.copy(sk.scope in sk.key, Keys.dynamicFileOutputs.key)
|
||||||
Vector(
|
addTaskDefinition {
|
||||||
setting,
|
val init: Def.Initialize[Task[Seq[Path]]] = sk(_.map(_ :: Nil))
|
||||||
addTaskDefinition {
|
Def.setting[Task[Seq[Path]]](scopedKey, init, setting.pos)
|
||||||
val init: Def.Initialize[Task[Seq[Path]]] = sk(_.map(_ :: Nil))
|
} :: outputsAndStamps(TaskKey(sk.key) in sk.scope, cleanScopes)
|
||||||
Def.setting[Task[Seq[Path]]](scopedKey, init, setting.pos)
|
|
||||||
}
|
|
||||||
) ++ outputsAndStamps(TaskKey(sk.key) in sk.scope, cleanScopes)
|
|
||||||
case _ => default
|
case _ => default
|
||||||
}
|
}
|
||||||
case _ => setting :: Nil
|
case _ => Nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private[sbt] val inject: Def.ScopedKey[_] => Seq[Def.Setting[_]] = scopedKey =>
|
private[sbt] val inject: Def.ScopedKey[_] => Seq[Def.Setting[_]] = scopedKey =>
|
||||||
|
|
@ -300,7 +281,7 @@ private[sbt] object Settings {
|
||||||
* @param taskKey the task for which we add a custom clean implementation
|
* @param taskKey the task for which we add a custom clean implementation
|
||||||
* @return a task specificic clean implementation
|
* @return a task specificic clean implementation
|
||||||
*/
|
*/
|
||||||
private[sbt] def cleanImpl[T: JsonFormat: ToSeqPath](taskKey: TaskKey[T]): Seq[Def.Setting[_]] = {
|
private[sbt] def cleanImpl[T: JsonFormat: ToSeqPath](taskKey: TaskKey[T]): Def.Setting[_] = {
|
||||||
val taskScope = taskKey.scope in taskKey.key
|
val taskScope = taskKey.scope in taskKey.key
|
||||||
addTaskDefinition(sbt.Keys.clean in taskScope := Def.taskDyn {
|
addTaskDefinition(sbt.Keys.clean in taskScope := Def.taskDyn {
|
||||||
// the clean file task needs to run first because the previous cache gets blown away
|
// the clean file task needs to run first because the previous cache gets blown away
|
||||||
|
|
@ -343,10 +324,10 @@ private[sbt] object Settings {
|
||||||
private[this] def outputsAndStamps[T: JsonFormat: ToSeqPath](
|
private[this] def outputsAndStamps[T: JsonFormat: ToSeqPath](
|
||||||
taskKey: TaskKey[T],
|
taskKey: TaskKey[T],
|
||||||
cleanScopes: mutable.Set[Scope]
|
cleanScopes: mutable.Set[Scope]
|
||||||
): Seq[Def.Setting[_]] = {
|
): List[Def.Setting[_]] = {
|
||||||
val scope = taskKey.scope in taskKey.key
|
val scope = taskKey.scope in taskKey.key
|
||||||
cleanScopes.add(scope)
|
cleanScopes.add(scope)
|
||||||
Vector(allOutputPathsImpl(scope), outputFileStampsImpl(scope)) ++ cleanImpl(taskKey)
|
allOutputPathsImpl(scope) :: outputFileStampsImpl(scope) :: cleanImpl(taskKey) :: Nil
|
||||||
}
|
}
|
||||||
private[this] def allOutputPathsImpl(scope: Scope): Def.Setting[_] =
|
private[this] def allOutputPathsImpl(scope: Scope): Def.Setting[_] =
|
||||||
addTaskDefinition(allOutputFiles in scope := {
|
addTaskDefinition(allOutputFiles in scope := {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue