summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohannes Rudolph <johannes.rudolph@gmail.com>2017-03-23 18:58:50 +0100
committerJohannes Rudolph <johannes.rudolph@gmail.com>2017-03-27 12:12:55 +0200
commit40f0514f177c05d6171cc122a2ce30e9e6cfe6af (patch)
tree74d1e89681c5b0a5b01d0e94d5102bb322878dd3 /src
parentf2c6005f3def940db3897f94b8ba4f0fe2fbd8f4 (diff)
downloadscala-40f0514f177c05d6171cc122a2ce30e9e6cfe6af.tar.gz
scala-40f0514f177c05d6171cc122a2ce30e9e6cfe6af.tar.bz2
scala-40f0514f177c05d6171cc122a2ce30e9e6cfe6af.zip
Implement ListBuffer.isEmpty / nonEmpty efficiently
Uses the extra length information to provide more efficient implementations. Evaluating these methods turns up with about 5-6% of akka-http message parsing.
Diffstat (limited to 'src')
-rw-r--r--src/library/scala/collection/mutable/ListBuffer.scala4
1 files changed, 4 insertions, 0 deletions
diff --git a/src/library/scala/collection/mutable/ListBuffer.scala b/src/library/scala/collection/mutable/ListBuffer.scala
index 3bb7004184..aa79e972d5 100644
--- a/src/library/scala/collection/mutable/ListBuffer.scala
+++ b/src/library/scala/collection/mutable/ListBuffer.scala
@@ -119,6 +119,10 @@ final class ListBuffer[A]
// Don't use the inherited size, which forwards to a List and is O(n).
override def size = length
+ // Override with efficient implementations using the extra size information available to ListBuffer.
+ override def isEmpty: Boolean = len == 0
+ override def nonEmpty: Boolean = len > 0
+
// Implementations of abstract methods in Buffer
override def apply(n: Int): A =