-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Port Capture-checked Scala 2 collections #23769
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
ac2ffaa
40f875f
0e37625
00dc9d3
6372132
88ee08c
9070166
0c31c4a
fe0c8ca
f00abf8
2152a4d
7aca413
ce268f3
300ee39
426b0c7
498f156
c235ee2
2e2393a
20a38bb
83c3d01
117b9ab
3ac001a
ba6167f
db84885
b3f868a
9993dd6
71a45e3
919a59d
48044bc
a864d71
f161436
ba2c1b0
c4e076e
1165f3e
a01682f
778f86d
4f56818
ef53024
3a01da5
9d850c0
3a0999e
e31c1a2
0df11f9
5f26a75
c49e17b
25ce3ec
849254c
5dd6c81
4222eba
4b70944
1d6da4c
92b84db
b4db5d9
fbf47c4
618fa31
fc0b733
dbac08e
7d83add
6121ae2
6214347
468e05c
ebd6887
8f2fd14
c8dd681
9fd6bb1
f5f5b94
07547f4
cb2fd3b
ab8cde1
64c3cd0
7d99e9f
b94bf42
6540914
703cceb
783ea88
98e7b80
839c37e
ae7f589
5ef1606
4e8df36
0cf4715
8eb1a8e
6650110
7b18bce
fd0281e
c343eff
c6a8ba5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,7 +15,6 @@ package collection | |
|
|
||
| import scala.language.`2.13` | ||
| import language.experimental.captureChecking | ||
| import scala.annotation.unchecked.uncheckedVariance | ||
|
|
||
| import scala.annotation.nowarn | ||
| import scala.collection.generic.DefaultSerializable | ||
|
|
@@ -96,18 +95,6 @@ transparent trait StrictMapOps[K, +V, +CC[_, _] <: IterableOps[_, AnyConstr, _] | |
| // The original keySet implementation, with a lazy iterator over the keys, | ||
| // is only correct if we have a strict Map. | ||
| // We restore it here. | ||
| override def keySet: Set[K] = new LazyKeySet | ||
|
|
||
| /** The implementation class of the set returned by `keySet`, for pure maps. | ||
| */ | ||
| private class LazyKeySet extends AbstractSet[K] with DefaultSerializable { | ||
| def diff(that: Set[K]): Set[K] = LazyKeySet.this.fromSpecific(this.view.filterNot(that)) | ||
| def iterator: Iterator[K] = StrictMapOps.this.keysIterator | ||
| def contains(key: K): Boolean = StrictMapOps.this.contains(key) | ||
| override def size: Int = StrictMapOps.this.size | ||
| override def knownSize: Int = StrictMapOps.this.knownSize | ||
| override def isEmpty: Boolean = StrictMapOps.this.isEmpty | ||
| } | ||
| } | ||
|
|
||
| /** Base Map implementation type | ||
|
|
@@ -214,7 +201,15 @@ transparent trait MapOps[K, +V, +CC[_, _] <: IterableOps[_, AnyConstr, _], +C] | |
| * | ||
| * @return a set representing the keys contained by this map | ||
| */ | ||
| def keySet: Set[K] = new KeySet | ||
| def keySet: Set[K] = | ||
| // If we know one of the strict implementations inside this library, simply return LazyKeySet | ||
| import MapOps.LazyKeySet | ||
| this match | ||
| case s: SeqMap[K, V] => new LazyKeySet(s) | ||
| case s: SortedMap[K, V] => new LazyKeySet(s) | ||
| case s: immutable.MapOps[K, V, immutable.Map, immutable.Map[K, V]] => new LazyKeySet(s) | ||
| case s: mutable.MapOps[K, V, mutable.Map, mutable.Map[K, V]] => new LazyKeySet(s) | ||
| case _ => new KeySet | ||
|
|
||
| /** The implementation class of the set returned by `keySet`. | ||
| */ | ||
|
|
@@ -250,7 +245,7 @@ transparent trait MapOps[K, +V, +CC[_, _] <: IterableOps[_, AnyConstr, _], +C] | |
| * @return an [[Iterable]] collection of the keys contained by this map | ||
| */ | ||
| @deprecatedOverriding("This method should be an alias for keySet", since="2.13.13") | ||
| def keys: Iterable[K]^{this} = keySet | ||
| def keys: Iterable[K]^{this} = this.keySet | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Technically this should've been an alias for |
||
|
|
||
| /** Collects all values of this map in an iterable collection. | ||
| * | ||
|
|
@@ -436,6 +431,17 @@ object MapOps { | |
|
|
||
| } | ||
|
|
||
|
|
||
| /** The implementation class of the set returned by `keySet`, for pure maps. | ||
| */ | ||
| private class LazyKeySet[K, +V, +CC[_, _] <: IterableOps[_, AnyConstr, _], +C](mp: MapOps[K, V, CC, C]) extends AbstractSet[K] with DefaultSerializable { | ||
| def iterator: Iterator[K] = mp.keysIterator | ||
| def diff(that: Set[K]): Set[K] = LazyKeySet.this.fromSpecific(this.view.filterNot(that)) | ||
| def contains(key: K): Boolean = mp.contains(key) | ||
| override def size: Int = mp.size | ||
| override def knownSize: Int = mp.knownSize | ||
| override def isEmpty: Boolean = mp.isEmpty | ||
| } | ||
|
Comment on lines
+429
to
+436
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually is the old implementation of |
||
| } | ||
|
|
||
| /** | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.