Skip to content

Commit ecf8e5c

Browse files
authored
Improve sizeCompare doc (#25696)
Fixes scala/bug#11783 Not sure that collection implementers are confused, but the extant wording is confusing, per the ticket. Not sure this attempt to improve the words is not tiresome. The original uncertainty was: "Does it mean to say cheap or not cheap?" An alternative fix would simply delete the confusing text. Curious folk may consult the open source code.
2 parents c39a78e + 04a035c commit ecf8e5c

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

library/src/scala/collection/Iterable.scala

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -264,9 +264,12 @@ transparent trait IterableOps[+A, +CC[_], +C] extends Any with IterableOnce[A] w
264264
* x > 0 if this.size > otherSize
265265
* ```
266266
*
267-
* The method as implemented here does not call `size` directly; its running time
268-
* is `O(size min otherSize)` instead of `O(size)`. The method should be overridden
269-
* if computing `size` is cheap and `knownSize` returns `-1`.
267+
* The default implementation does not call `size`, which may be arbitrarily expensive.
268+
* It will use `knownSize` if nonnegative.
269+
* Otherwise, it will iterate to compute an element count,
270+
* with complexity `O(size min otherSize)`.
271+
* This method should be overridden if computing `size` is cheap and `knownSize` returns `-1`.
272+
* In that case, the custom implementation should just compare `size` and `otherSize` directly.
270273
*
271274
* @see [[sizeIs]]
272275
*/

0 commit comments

Comments
 (0)