Skip to content

Commit ecf3fa6

Browse files
authored
Merge pull request scala#5802 from jrudolph/jr/w/ListBuffer-isEmpty-nonEmpty
Implement ListBuffer.isEmpty / nonEmpty / head efficiently
2 parents f5ce29b + 40f0514 commit ecf3fa6

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)