Skip to content

Commit 40f0514

Browse files
committed
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.
1 parent f2c6005 commit 40f0514

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/library/scala/collection/mutable/ListBuffer.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,10 @@ final class ListBuffer[A]
119119
// Don't use the inherited size, which forwards to a List and is O(n).
120120
override def size = length
121121

122+
// Override with efficient implementations using the extra size information available to ListBuffer.
123+
override def isEmpty: Boolean = len == 0
124+
override def nonEmpty: Boolean = len > 0
125+
122126
// Implementations of abstract methods in Buffer
123127

124128
override def apply(n: Int): A =

0 commit comments

Comments
 (0)