8000 SI-10177 Override lazy operations to preserve TrieMap's semantics by retronym · Pull Request #5687 · scala/scala · GitHub
[go: up one dir, main page]

Skip to content

SI-10177 Override lazy operations to preserve TrieMap's semantics #5687

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

Merged
merged 1 commit into from
Feb 16, 2017

Conversation

retronym
Copy link
Member
@retronym retronym commented Feb 9, 2017

Calling .iterator on a TrieMap gives a read-only snapshot. This then
extends to most inherited implementations written in terms of .iterator.

However, some inherited methods, such as .values, either defer the call
to .iterator or call it more than once. This results in subsequent
mutations to the original map being visible

I reviewed the inherited implementations from MapLike and found we
needed overrides of values, keySet, filterKeys, and mapValues.
Like iterator, these now create a read-only snapshot.

Review by @axel22

@scala-jenkins scala-jenkins added this to the 2.12.2 milestone Feb 9, 2017
@@ -912,6 +913,18 @@ extends scala.collection.concurrent.Map[K, V]
}
}
}
def fail[K, B](self: TrieMap[K, V]): Option[V] = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me overall, but I failed to understand what fail is for. And why does it have a B type parameter?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, that was me just hand-inlining some code to add to the bug report. Wasn't intended to be included here, will remove.

Calling .iterator on a TrieMap gives a read-only snapshot. This then
extends to most inherited implementations written in terms of .iterator.

However, some inherited methods, such as .values, either defer the call
to .iterator or call it more than once. This results in subsequent
mutations to the original map being visible

I reviewed the inherited implementations from MapLike and found we
needed overrides of `values`, `keySet`, `filterKeys`, and `mapValues`.
Like `iterator`, these now create a read-only snapshot.
@axel22
Copy link
Contributor
axel22 commented Feb 10, 2017

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0