Skip to content

Commit

Permalink
#510 Opening multiple projects in a new window makes IDEA plug-in unr…
Browse files Browse the repository at this point in the history
…esponsive, fixed tests
  • Loading branch information
hsz committed Jan 11, 2018
1 parent e90a610 commit 25d4755
Showing 1 changed file with 7 additions and 25 deletions.
32 changes: 7 additions & 25 deletions src/mobi/hsz/idea/gitignore/util/Glob.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.lang.ref.WeakReference;
import java.util.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand All @@ -52,7 +54,7 @@ public class Glob {
private static final ConcurrentMap<String, String> GLOBS_CACHE = ContainerUtil.newConcurrentMap();

/** Cache map that holds compiled regex. */
private static final ConcurrentMap<String, WeakPattern> PATTERNS_CACHE = ContainerUtil.newConcurrentMap();
private static final ConcurrentMap<String, Pattern> PATTERNS_CACHE = ContainerUtil.newConcurrentMap();

/** Private constructor to prevent creating {@link Glob} instance. */
private Glob() {
Expand Down Expand Up @@ -196,9 +198,9 @@ public static Pattern createPattern(@NotNull String rule,
final String regex = syntax.equals(IgnoreBundle.Syntax.GLOB) ? createRegex(rule, acceptChildren) : rule;
try {
if (!PATTERNS_CACHE.containsKey(regex)) {
PATTERNS_CACHE.put(regex, new WeakPattern(Pattern.compile(regex)));
PATTERNS_CACHE.put(regex, Pattern.compile(regex));
}
return PATTERNS_CACHE.get(regex).get();
return PATTERNS_CACHE.get(regex);
} catch (PatternSyntaxException e) {
return null;
}
Expand Down Expand Up @@ -391,24 +393,4 @@ public static void clearCache() {
GLOBS_CACHE.clear();
PATTERNS_CACHE.clear();
}

/** Weak reference to {@link Pattern}. */
private static final class WeakPattern extends WeakReference<Pattern> {
private int myHashCode;

WeakPattern(@NotNull Pattern referent) {
super(referent);
myHashCode = System.identityHashCode(referent);
}

@Override
public boolean equals(Object o) {
return this == o || (o instanceof WeakPattern && ((WeakPattern) o).get() == get());
}

@Override
public int hashCode() {
return myHashCode;
}
}
}

0 comments on commit 25d4755

Please sign in to comment.