summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/backend/WorklistAlgorithm.scala
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2010-12-20 23:34:20 +0000
committerPaul Phillips <paulp@improving.org>2010-12-20 23:34:20 +0000
commit3bfd81869ccffd0657a1b82eb483e0f26a283a46 (patch)
tree669c49e2d0d3302cb04b20dffe91c77292526306 /src/compiler/scala/tools/nsc/backend/WorklistAlgorithm.scala
parent3cfee5b1450a42c31a857c5dd10f68387d88e669 (diff)
downloadscala-3bfd81869ccffd0657a1b82eb483e0f26a283a46.tar.gz
scala-3bfd81869ccffd0657a1b82eb483e0f26a283a46.tar.bz2
scala-3bfd81869ccffd0657a1b82eb483e0f26a283a46.zip
This commit is about not calling .length or .si...
This commit is about not calling .length or .size on Lists. Sometimes it is unavoidable; not often. I created some methods for the compiler which should probably be in the collections, which do things like test if two sequences have the same length in a more efficient manner than calling length on each. Also, wouldn't it be wonderful to have some mechanism for finding these issues in a more automated way. Like say an annotation: LinearSeqLike { @badjuju("Calling length on linear seqs is O(n)") def length: Int = whee } Or since I imagine everyone thinks they're calling length with lists of 2 or 3, an optional runtime check which yelled if it sees you calling length on a 600 element list, or worse: var i = 0 while (i < myList.length) { // you don't want to see what this does f(myList(i)) ; i += 1; } Uniformity of interface without uniformity of behavior leaves us with traps. No review.
Diffstat (limited to 'src/compiler/scala/tools/nsc/backend/WorklistAlgorithm.scala')
-rw-r--r--src/compiler/scala/tools/nsc/backend/WorklistAlgorithm.scala4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/compiler/scala/tools/nsc/backend/WorklistAlgorithm.scala b/src/compiler/scala/tools/nsc/backend/WorklistAlgorithm.scala
index 27f5b27303..cc2c2b3517 100644
--- a/src/compiler/scala/tools/nsc/backend/WorklistAlgorithm.scala
+++ b/src/compiler/scala/tools/nsc/backend/WorklistAlgorithm.scala
@@ -40,8 +40,8 @@ trait WorklistAlgorithm {
def run(initWorklist: => Unit) = {
initWorklist
- while (!(worklist.length == 0))
- processElement(dequeue);
+ while (worklist.nonEmpty)
+ processElement(dequeue)
}
/**