Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance
Java decentralizedintranet-searchintranet-search-enginep2pp2p-networkprivacyprivacy-protectionsearch-enginesearchenginewebweb-search-enginewebsearchwebseearch-engine
less computation within synchronized blocks
orbiter2d3c98b742de
diff --git a/source/net/yacy/kelondro/blob/MapView.java b/source/net/yacy/kelondro/blob/MapView.javaindex 1323184c9..4ae58c080 100644--- a/source/net/yacy/kelondro/blob/MapView.java+++ b/source/net/yacy/kelondro/blob/MapView.java@@ -142,11 +142,13 @@ public class MapView {assert key.length() > 0;assert newMap != null;key = normalizeKey(key);+ byte[] keyb = key.getBytes("UTF-8");String s = map2string(newMap, "W" + DateFormatter.formatShortSecond() + " ");assert s != null;+ byte[] sb = s.getBytes("UTF-8");synchronized (this) {// write entry- if (blob != null) blob.put(key.getBytes("UTF-8"), s.getBytes("UTF-8"));+ if (blob != null) blob.put(keyb, sb);// write map to cacheif (cache != null) cache.put(key, newMap);@@ -162,13 +164,14 @@ public class MapView {// update elementCountif (key == null) return;key = normalizeKey(key);+ byte[] keyb = key.getBytes("UTF-8");synchronized (this) {// remove from cachecache.remove(key);// remove from file- blob.remove(key.getBytes());+ blob.remove(keyb);}}@@ -182,9 +185,10 @@ public class MapView {assert key != null;if (cache == null) return false; // case may appear during shutdownkey = normalizeKey(key);- boolean h = false;+ byte[] keyb = key.getBytes("UTF-8");+ boolean h;synchronized (this) {- h = this.cache.containsKey(key) || this.blob.has(key.getBytes());+ h = this.cache.containsKey(key) || this.blob.has(keyb);}return h;}@@ -212,23 +216,34 @@ public class MapView {assert key != null;if (cache == null) return null; // case may appear during shutdownkey = normalizeKey(key);+ byte[] keyb = key.getBytes("UTF-8");- synchronized (this) {- Map<String, String> map = cache.get(key);- if (map != null) return map;-- // read object- final byte[] b = blob.get(key.getBytes());- if (b == null) return null;- map = bytes2map(b);+ Map<String, String> map;+ if (storeCache) {+ synchronized (this) {+ map = cache.get(key);+ if (map != null) return map;- if (storeCache) {+ // read object+ final byte[] b = blob.get(keyb);+ if (b == null) return null;+ map = bytes2map(b);+// write map to cachecache.put(key, map);}-+// return valuereturn map;+ } else {+ byte[] b;+ synchronized (this) {+ map = cache.get(key);+ if (map != null) return map;+ b = blob.get(keyb);+ }+ if (b == null) return null;+ return bytes2map(b);}}