Skip to content
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

Use java map i.s.o. scala map #1079

Closed
wants to merge 1 commit into from
Closed

Conversation

erikvanoosten
Copy link
Collaborator

As requested in #1073 (comment) this PR explores using a java HashMap directly.

Note that we still need to convert to scala map for doing the +1 on offsets, and we still need to convert to an immutable map for diagnostics.

This PR is probably a bit faster, but it does feel weird: constructing a Java map, converting it to Scala and then back to java.

@erikvanoosten
Copy link
Collaborator Author

BTW, note that this code is also changed by #1067.

commit.offsets.foreach { case (tp, offset) =>
acc += (tp -> acc.get(tp).map(_ max offset).getOrElse(offset))
acc.merge(tp, offset, _ max _)
Copy link
Member

Choose a reason for hiding this comment

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

For once Java provides a nicer operator than Scala 🙂

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Indeed! 😄
There is also:

acc.updateWith(tp) { current => current.map(_ max offset).orElse(Some(offset)) }

But definitely less nice.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You inspired me to write: scala/scala-library-next#164 😄

@erikvanoosten
Copy link
Collaborator Author

Closing as this is just a demonstration.

@guizmaii guizmaii deleted the merge-commits-extra branch October 28, 2023 07:43
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.

None yet

2 participants