Skip to content

Commit

Permalink
perf[map]: get put remove by primitive way
Browse files Browse the repository at this point in the history
  • Loading branch information
jaysunxiao committed Sep 23, 2024
1 parent 082c2fa commit 628463d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,16 @@ public V get(Object key) {
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();
Expand All @@ -89,6 +93,10 @@ public V put(Long key, V value) {

@Override
public V remove(Object key) {
return remove(((Long) key).longValue());
}

public V remove(long key) {
lock.lock();
try {
var newMap = newCopyMap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,15 @@ public static void registerSingleThreadExecutor(Thread thread, Executor executor
}

public static Executor executorByThreadId(long threadId) {
var threadExecutor = threadExecutorMap.getPrimitive(threadId);
var threadExecutor = threadExecutorMap.get(threadId);
return threadExecutor == null ? null : threadExecutor.getValue();
}

/**
* 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();
}
Expand Down

0 comments on commit 628463d

Please sign in to comment.