@NotNull public static String getVFileName(int nameId) { IntObjectLinkedMap.MapEntry<Object> entry = getEntry(nameId); Object name = entry.value; if (name instanceof String) { //noinspection StringEquality return (String)name; } byte[] bytes = (byte[])name; int length = bytes.length; char[] chars = new char[length]; for (int i = 0; i < length; i++) { chars[i] = (char)bytes[i]; } return StringFactory.createShared(chars); }
static int compareNameTo(int nameId, @NotNull String name, boolean ignoreCase) { IntObjectLinkedMap.MapEntry<Object> entry = getEntry(nameId); Object rawName = entry.value; if (rawName instanceof String) { String thisName = getVFileName(nameId); return VirtualFileSystemEntry.compareNames(thisName, name, ignoreCase); } byte[] bytes = (byte[])rawName; int bytesLength = bytes.length; int d = bytesLength - name.length(); if (d != 0) return d; return compareBytes(bytes, 0, name, 0, bytesLength, ignoreCase); }
@NotNull private static IntObjectLinkedMap.MapEntry<CharSequence> cacheData(String name, int id, int stripe) { if (name == null) { ourNames.markCorrupted(); throw new RuntimeException("VFS name enumerator corrupted"); } CharSequence rawName = ByteArrayCharSequence.convertToBytesIfAsciiString(name); IntObjectLinkedMap.MapEntry<CharSequence> entry = new IntObjectLinkedMap.MapEntry<CharSequence>(id, rawName); IntSLRUCache<IntObjectLinkedMap.MapEntry<CharSequence>> cache = ourNameCache[stripe]; //noinspection SynchronizationOnLocalVariableOrMethodParameter synchronized (cache) { return cache.cacheEntry(entry); } }
@NotNull private static IntObjectLinkedMap.MapEntry<Object> cacheData(String name, int id) { if (name == null) { ourNames.markCorrupted(); throw new RuntimeException("VFS name enumerator corrupted"); } Object rawName = convertToBytesIfAsciiString(name); IntObjectLinkedMap.MapEntry<Object> entry = new IntObjectLinkedMap.MapEntry<Object>(id, rawName); final int stripe = id % ourNameCache.length; synchronized (ourNameCache[stripe]) { return ourNameCache[stripe].cacheEntry(entry); } }
@NotNull private static IntObjectLinkedMap.MapEntry<Object> getEntry(int id) { final int stripe = id % ourNameCache.length; synchronized (ourNameCache[stripe]) { IntObjectLinkedMap.MapEntry<Object> entry = ourNameCache[stripe].getCachedEntry(id); if (entry != null) { return entry; } } return cacheData(FSRecords.getNameByNameId(id), id); }
static char[] appendPathOnFileSystem(int nameId, @Nullable VirtualFileSystemEntry parent, int accumulatedPathLength, int[] positionRef) { IntObjectLinkedMap.MapEntry<Object> entry = getEntry(nameId); Object o = entry.value; int nameLength = o instanceof String ? ((String)o).length() : ((byte[])o).length; boolean appendSlash = SystemInfo.isWindows && parent == null && nameLength == 2 && (o instanceof String ? ((String)o).charAt(1) : (char)((byte[])o)[1]) == ':'; char[] chars; if (parent != null) { chars = parent.appendPathOnFileSystem(accumulatedPathLength + 1 + nameLength, positionRef); if (positionRef[0] > 0 && chars[positionRef[0] - 1] != '/') { chars[positionRef[0]++] = '/'; } } else { int rootPathLength = accumulatedPathLength + nameLength; if (appendSlash) ++rootPathLength; chars = new char[rootPathLength]; } if (o instanceof String) { positionRef[0] = VirtualFileSystemEntry.copyString(chars, positionRef[0], (String)o); } else { byte[] bytes = (byte[])o; int pos = positionRef[0]; //noinspection ForLoopReplaceableByForEach for (int i = 0, len = bytes.length; i < len; i++) { chars[pos++] = (char)bytes[i]; } positionRef[0] = pos; } if (appendSlash) { chars[positionRef[0]++] = '/'; } return chars; }
@Nonnull private static IntObjectLinkedMap.MapEntry<CharSequence> cacheData(String name, int id, int stripe) { if (name == null) { ourNames.markCorrupted(); throw new RuntimeException("VFS name enumerator corrupted"); } CharSequence rawName = ByteArrayCharSequence.convertToBytesIfAsciiString(name); IntObjectLinkedMap.MapEntry<CharSequence> entry = new IntObjectLinkedMap.MapEntry<CharSequence>(id, rawName); IntSLRUCache<IntObjectLinkedMap.MapEntry<CharSequence>> cache = ourNameCache[stripe]; //noinspection SynchronizationOnLocalVariableOrMethodParameter synchronized (cache) { return cache.cacheEntry(entry); } }
public IntSLRUCache(int protectedQueueSize, int probationalQueueSize) { myProtectedQueue = new IntObjectLinkedMap<Entry>(protectedQueueSize); myProbationalQueue = new IntObjectLinkedMap<Entry>(probationalQueueSize); }