From 40f0514f177c05d6171cc122a2ce30e9e6cfe6af Mon Sep 17 00:00:00 2001 From: Johannes Rudolph Date: Thu, 23 Mar 2017 18:58:50 +0100 Subject: 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. --- src/library/scala/collection/mutable/ListBuffer.scala | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src') 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 = -- cgit v1.2.3