-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Description
| Previous ID | SR-425 |
| Radar | None |
| Original Reporter | @lilyball |
| Type | Bug |
| Status | Closed |
| Resolution | Duplicate |
Additional Detail from JIRA
| Votes | 0 |
| Component/s | Standard Library |
| Labels | Bug |
| Assignee | None |
| Priority | Medium |
md5: 44131a346b66e07109ccf34858455fc1
duplicates:
- SR-428 Implement new performance terminology in documentation
Issue Description:
Indexable documents the startIndex property as having a Complexity of O(1), but LazyFilterCollection and FlattenCollection don't obey this rule. Accessing the startIndex on either collection runs the predicate up until it finds the first included element. And it does this every time you access startIndex. So that makes it O(N) at least (and a pathological predicate that captures a copy of the same underlying collection can make it arbitrarily expensive).
Luckily endIndex should be able to remain O(1) because collections can use a constant sentinel value instead of actually calculating anything (I haven't checked but I assume the lazy collection types already use a sentinel value for this).
There's two ways this can be fixed:
1. Modify LazyFilterCollection and FlattenCollection to aggressively calculate the index of the first element when they're created. But I think this would be surprising to have lazy collections run the predicate immediately, so I'd rather go with
2. Change the documentation of Indexable.startIndex to say it's O(1) in most cases, but potentially O(N) for lazy collections.