mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
better spreading nameIds / caching strings using integer hash from http://burtleburtle.net/bob/hash/integer.html
with previous nameId % 16 striping sampling was like 7542400, 16103753, 1844054, 5237640, 6218814, 11005156, 3395732, 8183208, 1897660, 3119959, 2961691, 7768377, 2177568, 3889462, 6146853, 2765254, with new one 8207442, 6253680, 14184952, 4657166, 5186040, 25115754, 10426752, 15750418, 11239308, 5293340, 16883296, 16750920, 6545096, 23295592, 5969384, 4756022,
This commit is contained in:
@@ -57,12 +57,24 @@ public class FileNameCache {
|
||||
|
||||
Object rawName = convertToBytesIfAsciiString(name);
|
||||
IntObjectLinkedMap.MapEntry<Object> entry = new IntObjectLinkedMap.MapEntry<Object>(id, rawName);
|
||||
final int stripe = id % ourNameCache.length;
|
||||
final int stripe = calcStripeIdFromNameId(id);
|
||||
synchronized (ourNameCache[stripe]) {
|
||||
return ourNameCache[stripe].cacheEntry(entry);
|
||||
}
|
||||
}
|
||||
|
||||
private static int calcStripeIdFromNameId(int id) {
|
||||
int h = id;
|
||||
h -= (h<<6);
|
||||
h ^= (h>>17);
|
||||
h -= (h<<9);
|
||||
h ^= (h<<4);
|
||||
h -= (h<<3);
|
||||
h ^= (h<<10);
|
||||
h ^= (h>>15);
|
||||
return h % ourNameCache.length;
|
||||
}
|
||||
|
||||
private static Object convertToBytesIfAsciiString(@NotNull String name) {
|
||||
int length = name.length();
|
||||
if (length == 0) return EMPTY;
|
||||
@@ -80,7 +92,7 @@ public class FileNameCache {
|
||||
|
||||
@NotNull
|
||||
private static IntObjectLinkedMap.MapEntry<Object> getEntry(int id) {
|
||||
final int stripe = id % ourNameCache.length;
|
||||
final int stripe = calcStripeIdFromNameId(id);
|
||||
synchronized (ourNameCache[stripe]) {
|
||||
IntObjectLinkedMap.MapEntry<Object> entry = ourNameCache[stripe].getCachedEntry(id);
|
||||
if (entry != null) {
|
||||
|
||||
Reference in New Issue
Block a user