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