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

ConcurrentHashSet is redundant with ConcurrentHashMap#newKeySet() #4851

Closed
magicprinc opened this issue Sep 11, 2023 · 13 comments
Closed

ConcurrentHashSet is redundant with ConcurrentHashMap#newKeySet() #4851

magicprinc opened this issue Sep 11, 2023 · 13 comments

Comments

@magicprinc
Copy link
Contributor

magicprinc commented Sep 11, 2023

It seems that io.vertx.core.impl.ConcurrentHashSet is a copy of JDK's Collections.newSetFromMap.
The Best Code is No Code At All.
It is probably a good idea to review and replace this class with two utility methods:

public static <E> Set<E> concurrentHashSet (){
  return Collections.newSetFromMap(new ConcurrentHashMap<>());
}

public static <E> Set<E> concurrentHashSet (int initialSize){
  return Collections.newSetFromMap(new ConcurrentHashMap<>(initialSize));
}

PR: #4852

@magicprinc magicprinc added the bug label Sep 11, 2023
@He-Pin
Copy link
Contributor

He-Pin commented Sep 11, 2023

Better to use ConcurrentHashMap.newKeySet

@tsegismont
Copy link
Contributor

You're welcome to contribute a PR for this, as well as in the impacted projects:

@magicprinc
Copy link
Contributor Author

I would like to, but I still have failed tests when I build vert.x-core locally on my Windows10/JDK17.
So I am not ready yet... :-(

BTW, I would enjoy if you find my other PR useful:
#4844
#4847
#4850

They have more benefits than ConcurrentHashSet removial.

magicprinc added a commit to magicprinc/vert.x that referenced this issue Sep 11, 2023
@He-Pin
Copy link
Contributor

He-Pin commented Sep 11, 2023

If you don't mind, i can do this too:), @magicprinc ,a nice find!

@magicprinc
Copy link
Contributor Author

@tsegismont
Anyway. Without tests :-)
#4852

@He-Pin Could you test it? And add test for concurrentHashSet implementations too?

@tsegismont tsegismont changed the title ConcurrentHashSet → Collections.newSetFromMap(new ConcurrentHashMap<>([size])) ConcurrentHashSet is redundant with ConcurrentHashMap#newKeySet() Sep 11, 2023
@tsegismont tsegismont added this to the 5.0.0 milestone Sep 11, 2023
@magicprinc
Copy link
Contributor Author

magicprinc commented Sep 12, 2023

@tsegismont
Copy link
Contributor

@magicprinc there's one more usage in vertx-mqtt, can you please take care of it before we merge this PR?

@magicprinc
Copy link
Contributor Author

@tsegismont I am sorry, but I can't find it. Could you name a class with it?
/
no_CHS

@magicprinc
Copy link
Contributor Author

magicprinc commented Sep 14, 2023

GitHub search shows 2 files, and both are fixed in my PR
vert-x3/vertx-mqtt#243

@magicprinc
Copy link
Contributor Author

magicprinc commented Sep 14, 2023

@tsegismont They are both fixed in PR vert-x3/vertx-mqtt#243
Have you seen this PR?

@tsegismont
Copy link
Contributor

tsegismont commented Sep 14, 2023 via email

tsegismont pushed a commit that referenced this issue Sep 14, 2023
* #4851 ConcurrentHashSet→Utils.concurrentHashSet

* core review

* core review 2

Utils.concurrentHashSet() → ConcurrentHashMap.newKeySet()

* Remove unused Utils imports

* DELETE private unused reportFailure and reportResult
@tsegismont
Copy link
Contributor

Closed by #4852

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

No branches or pull requests

3 participants