koca2000 / NoteBlockAPI

https://www.spigotmc.org/resources/noteblockapi.19287/
GNU Lesser General Public License v3.0
119 stars 40 forks source link

Minor Map tweaks in `NoteBlockAPI` #31

Closed JarvisCraft closed 5 years ago

JarvisCraft commented 5 years ago

https://github.com/koca2000/NoteBlockAPI/blob/92b6a733ee116e5e5c382b303e23eeaf582f30f3/src/main/java/com/xxmicloxx/NoteBlockAPI/NoteBlockAPI.java#L32 Might be replaced with ConcurrentHashMap https://github.com/koca2000/NoteBlockAPI/blob/92b6a733ee116e5e5c382b303e23eeaf582f30f3/src/main/java/com/xxmicloxx/NoteBlockAPI/NoteBlockAPI.java#L54 Might be replaced with Map#contains or result of Map#get may be cached not to be called twice

koca2000 commented 5 years ago

Hi! Thank you for your suggestions.

As I don't assume that there will not be accessed by many concurrent threads, I do not think that change to ConcurrentHashMap would be useful.

Map#contains has the exact same code as Map#get. I agree that it's result can be cached.

JarvisCraft commented 5 years ago

The reason I suggest usage of ConcurrentHashMap is that at current you use Collections.synchronizedMap which, even in 1-threaded environment is slower due to synchronization of each of its operations.

JarvisCraft commented 5 years ago

<3