提交 64040855 authored 作者: noelgrandin@gmail.com's avatar noelgrandin@gmail.com

on ConcurrentHashMap, containsKey is faster than contains, since contains() is a…

on ConcurrentHashMap, containsKey is faster than contains, since contains() is a synonym for containsValue, and will iterate over the whole map
上级 769c0f94
...@@ -119,11 +119,11 @@ public class MVTable extends TableBase { ...@@ -119,11 +119,11 @@ public class MVTable extends TableBase {
if (lockExclusiveSession == session) { if (lockExclusiveSession == session) {
return true; return true;
} }
if (!exclusive && lockSharedSessions.contains(session)) { if (!exclusive && lockSharedSessions.containsKey(session)) {
return true; return true;
} }
synchronized (getLockSyncObject()) { synchronized (getLockSyncObject()) {
if (!exclusive && lockSharedSessions.contains(session)) { if (!exclusive && lockSharedSessions.containsKey(session)) {
return true; return true;
} }
session.setWaitForLock(this, Thread.currentThread()); session.setWaitForLock(this, Thread.currentThread());
...@@ -217,7 +217,7 @@ public class MVTable extends TableBase { ...@@ -217,7 +217,7 @@ public class MVTable extends TableBase {
lockExclusiveSession = session; lockExclusiveSession = session;
return true; return true;
} else if (lockSharedSessions.size() == 1 && } else if (lockSharedSessions.size() == 1 &&
lockSharedSessions.contains(session)) { lockSharedSessions.containsKey(session)) {
traceLock(session, exclusive, "add (upgraded) for "); traceLock(session, exclusive, "add (upgraded) for ");
lockExclusiveSession = session; lockExclusiveSession = session;
return true; return true;
...@@ -237,7 +237,7 @@ public class MVTable extends TableBase { ...@@ -237,7 +237,7 @@ public class MVTable extends TableBase {
return true; return true;
} }
} }
if (!lockSharedSessions.contains(session)) { if (!lockSharedSessions.containsKey(session)) {
traceLock(session, exclusive, "ok"); traceLock(session, exclusive, "ok");
session.addLock(this); session.addLock(this);
lockSharedSessions.put(session, session); lockSharedSessions.put(session, session);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论