diff --git a/org.eclipse.search/new search/org/eclipse/search/ui/text/FileTextSearchScope.java b/org.eclipse.search/new search/org/eclipse/search/ui/text/FileTextSearchScope.java index 94affc8f0b4..afdaed46cc5 100644 --- a/org.eclipse.search/new search/org/eclipse/search/ui/text/FileTextSearchScope.java +++ b/org.eclipse.search/new search/org/eclipse/search/ui/text/FileTextSearchScope.java @@ -127,8 +127,8 @@ public static FileTextSearchScope newSearchScope(IWorkingSet[] workingSets, Stri private final String fDescription; private final IResource[] fRootElements; private final String[] fFileNamePatterns; - private final Matcher fPositiveFileNameMatcher; - private final Matcher fNegativeFileNameMatcher; + private final ThreadLocal fPositiveFileNameMatcher; + private final ThreadLocal fNegativeFileNameMatcher; private boolean fVisitDerived; private IWorkingSet[] fWorkingSets; @@ -139,8 +139,8 @@ private FileTextSearchScope(String description, IResource[] resources, IWorkingS fFileNamePatterns= fileNamePatterns; fVisitDerived= visitDerived; fWorkingSets= workingSets; - fPositiveFileNameMatcher= createMatcher(fileNamePatterns, false); - fNegativeFileNameMatcher= createMatcher(fileNamePatterns, true); + fPositiveFileNameMatcher = ThreadLocal.withInitial(() -> createMatcher(fileNamePatterns, false)); + fNegativeFileNameMatcher = ThreadLocal.withInitial(() -> createMatcher(fileNamePatterns, true)); } /** @@ -223,10 +223,12 @@ public boolean contains(IResourceProxy proxy) { } private boolean matchesFileName(String fileName) { - if (fPositiveFileNameMatcher != null && !fPositiveFileNameMatcher.reset(fileName).matches()) { + Matcher positiveFileNameMatcher = fPositiveFileNameMatcher.get(); + if (positiveFileNameMatcher != null && !positiveFileNameMatcher.reset(fileName).matches()) { return false; } - if (fNegativeFileNameMatcher != null && fNegativeFileNameMatcher.reset(fileName).matches()) { + Matcher negativeFileNameMatcher = fNegativeFileNameMatcher.get(); + if (negativeFileNameMatcher != null && negativeFileNameMatcher.reset(fileName).matches()) { return false; } return true;