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

Add Java 8 Map shortcut methods #26

Open
maxim5 opened this issue Aug 25, 2021 · 6 comments
Open

Add Java 8 Map shortcut methods #26

maxim5 opened this issue Aug 25, 2021 · 6 comments
Milestone

Comments

@maxim5
Copy link

maxim5 commented Aug 25, 2021

  • putIfAbsent
  • computeIfAbsent
  • computeIfPresent
  • etc.
@dweiss
Copy link
Member

dweiss commented Aug 26, 2021

+1.

@dweiss
Copy link
Member

dweiss commented Dec 15, 2021

I moved putIfAbsent to KTypeVTypeMap. The signature is slightly different than in java Maps though - it returns a boolean (indicating whether they key existed or not). This keeps it consistent with a method that existed in both map implementations (otherwise the API would break).

Adding other utility methods would mean we need all variants of predicates/ functions, etc. And once you allow closure arguments... well, it stops being a high-performance thing... ;)

I do find those methods useful too so maybe we should change/ break the API in the future and just depart from the old model. I'll leave this issue open.

@dweiss dweiss added this to the 0.9.1 milestone Dec 15, 2021
@maxim5
Copy link
Author

maxim5 commented Dec 27, 2021

Thanks!

And once you allow closure arguments... well, it stops being a high-performance thing... ;)

Well, that's not true. In a lot of cases, those trivial closures are inlined in modern Java:
https://blogs.oracle.com/javamagazine/post/behind-the-scenes-how-do-lambda-expressions-really-work-in-java

And that's, by the way, one of the things that could improve forEach methods performance. Interfaces like
IntIntProcedure and IntIntPredicate have the same lambda signature, which makes the use of lambda there more cumbersome and so less compiled byte-code efficient.

@dweiss
Copy link
Member

dweiss commented Dec 28, 2021

I know how lambdas are implemented. They really require a good few reiterations in c2 to be efficient though. Anyway, it's not the point. I agree it could be done, but there's never enough time unless you have a pressing need. If you do - please provide a patch, we'll gladly consider.

@QIvan
Copy link

QIvan commented Aug 23, 2022

hi! Just checking if there has been any work on this front before thinking about a contribution. Please share if there has.
thanks.

@dweiss
Copy link
Member

dweiss commented Aug 24, 2022

Well, it is open. There is a still-holding relevant comment above though:

Adding other utility methods would mean we need all variants of predicates/ functions, etc. And once you allow closure arguments... well, it stops being a high-performance thing... ;)

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

No branches or pull requests

3 participants