From 5c49bd049ca711bda64da924ad46adc98b66d4ef Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Wed, 20 May 2015 20:12:37 +0300 Subject: [PATCH] getRelativePath optimisation, load factor tune, deleted code for removal --- .../openapi/vfs/impl/ZipEntryMap.java | 45 +++++++++---------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/platform/core-impl/src/com/intellij/openapi/vfs/impl/ZipEntryMap.java b/platform/core-impl/src/com/intellij/openapi/vfs/impl/ZipEntryMap.java index 3502f1973bdc..90097a2bec41 100644 --- a/platform/core-impl/src/com/intellij/openapi/vfs/impl/ZipEntryMap.java +++ b/platform/core-impl/src/com/intellij/openapi/vfs/impl/ZipEntryMap.java @@ -27,10 +27,9 @@ import java.util.*; /** * Map of relativePath => ArchiveHandler.EntryInfo optimised for memory: * - it does not store keys (may be recovered from the ArchiveHandler.EntryInfo) + * - does not support removal */ class ZipEntryMap extends AbstractMap { - private static final ArchiveHandler.EntryInfo REMOVED = new ArchiveHandler.EntryInfo(null, "", false, 0, 0); - private ArchiveHandler.EntryInfo[] entries; private int size; @@ -64,7 +63,7 @@ class ZipEntryMap extends AbstractMap { @Override public ArchiveHandler.EntryInfo put(String relativePath, ArchiveHandler.EntryInfo value) { - if (size >= 0.8 * entries.length) { + if (size >= 0.65 * entries.length) { rehash(); } @@ -84,7 +83,7 @@ class ZipEntryMap extends AbstractMap { int i = index; while (true) { entry = entries[i]; - if (entry == null || entry == REMOVED || isTheOne(entry, relativePath)) { + if (entry == null || isTheOne(entry, relativePath)) { entries[i] = value; break; } @@ -92,14 +91,14 @@ class ZipEntryMap extends AbstractMap { i = 0; } } - return entry == REMOVED ? null : entry; + return entry; } - private static boolean isTheOne(@NotNull ArchiveHandler.EntryInfo entry, @NotNull String relativePath) { + private static boolean isTheOne(@NotNull ArchiveHandler.EntryInfo entry, @NotNull CharSequence relativePath) { int endIndex = relativePath.length(); for (ArchiveHandler.EntryInfo e = entry; e != null; e = e.parent) { CharSequence shortName = e.shortName; - if (!CharArrayUtil.regionMatches(relativePath,endIndex-shortName.length(), relativePath.length(), shortName)) { + if (!CharArrayUtil.regionMatches(relativePath, endIndex - shortName.length(), relativePath.length(), shortName)) { return false; } @@ -132,20 +131,25 @@ class ZipEntryMap extends AbstractMap { @NotNull private static String getRelativePath(@NotNull ArchiveHandler.EntryInfo entry) { - if (entry.parent == null) { - return entry.shortName.toString(); + StringBuilder result = new StringBuilder(entry.shortName.length() + 10); + for (ArchiveHandler.EntryInfo e = entry; e != null; e = e.parent) { + if (result.length() != 0 && e.shortName.length() != 0) { + result.append('/'); + } + appendReversed(result, e.shortName); + } + return result.reverse().toString(); + } + + private static void appendReversed(@NotNull StringBuilder builder, @NotNull CharSequence sequence) { + for (int i=sequence.length()-1; i>=0 ;i--) { + builder.append(sequence.charAt(i)); } - String parentPath = getRelativePath(entry.parent); - return (parentPath.isEmpty() ? "" : parentPath + "/") + entry.shortName; } @Override public ArchiveHandler.EntryInfo remove(@NotNull Object key) { - ArchiveHandler.EntryInfo old = put((String)key, REMOVED); - if (old != null) { - size--; - } - return old; + throw new UnsupportedOperationException(); } @Override @@ -202,18 +206,13 @@ class ZipEntryMap extends AbstractMap { @Override public final boolean remove(Object o) { - if (o instanceof Map.Entry) { - Map.Entry e = (Map.Entry)o; - Object key = e.getKey(); - return contains(o) && ZipEntryMap.this.remove(key) != null; - } - return false; + throw new UnsupportedOperationException(); } } @NotNull @Override public Collection values() { - return ContainerUtil.mapNotNull(entries, Function.ID); + return ContainerUtil.filter(Condition.NOT_NULL, entries); } }