mirror of
https://github.com/tiennm99/zfoo.git
synced 2026-05-23 06:25:45 +00:00
perf[map]: get put remove by primitive way
This commit is contained in:
+9
-1
@@ -70,12 +70,16 @@ public class CopyOnWriteHashMapLongObject<V> implements Map<Long, V> {
|
||||
return map.get(key);
|
||||
}
|
||||
|
||||
public V getPrimitive(long key) {
|
||||
public V get(long key) {
|
||||
return map.get(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public V put(Long key, V value) {
|
||||
return put(key.longValue(), value);
|
||||
}
|
||||
|
||||
public V put(long key, V value) {
|
||||
lock.lock();
|
||||
try {
|
||||
var newMap = newCopyMap();
|
||||
@@ -89,6 +93,10 @@ public class CopyOnWriteHashMapLongObject<V> implements Map<Long, V> {
|
||||
|
||||
@Override
|
||||
public V remove(Object key) {
|
||||
return remove(((Long) key).longValue());
|
||||
}
|
||||
|
||||
public V remove(long key) {
|
||||
lock.lock();
|
||||
try {
|
||||
var newMap = newCopyMap();
|
||||
|
||||
@@ -117,7 +117,7 @@ public abstract class ThreadUtils {
|
||||
}
|
||||
|
||||
public static Executor executorByThreadId(long threadId) {
|
||||
var threadExecutor = threadExecutorMap.getPrimitive(threadId);
|
||||
var threadExecutor = threadExecutorMap.get(threadId);
|
||||
return threadExecutor == null ? null : threadExecutor.getValue();
|
||||
}
|
||||
|
||||
@@ -125,7 +125,7 @@ public abstract class ThreadUtils {
|
||||
* search for the corresponding thread by the thread id
|
||||
*/
|
||||
public static Thread findThread(long threadId) {
|
||||
var threadExecutor = threadExecutorMap.getPrimitive(threadId);
|
||||
var threadExecutor = threadExecutorMap.get(threadId);
|
||||
if (threadExecutor != null) {
|
||||
return threadExecutor.getKey();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user