diff --git a/java/java-tests/testData/fileStructure/filtering/Camel.tree b/java/java-tests/testData/fileStructure/filtering/Camel.tree index d7d2caba8a22..5a8e44f56e8a 100644 --- a/java/java-tests/testData/fileStructure/filtering/Camel.tree +++ b/java/java-tests/testData/fileStructure/filtering/Camel.tree @@ -1,5 +1,5 @@ -Camel.java -Camel - [doSomethingWithMyHead(): void] + doSomethingWithMyHead(): void getSomeArtHeader(): void - getSomeHead(): void \ No newline at end of file + [getSomeHead(): void] \ No newline at end of file diff --git a/platform/platform-impl/src/com/intellij/ui/SpeedSearchComparator.java b/platform/platform-impl/src/com/intellij/ui/SpeedSearchComparator.java index c5da44384d6e..c8d885829583 100644 --- a/platform/platform-impl/src/com/intellij/ui/SpeedSearchComparator.java +++ b/platform/platform-impl/src/com/intellij/ui/SpeedSearchComparator.java @@ -43,8 +43,16 @@ public class SpeedSearchComparator { myShouldMatchCamelCase = shouldMatchCamelCase; } + public int matchingDegree(String pattern, String text) { + return obtainMatcher(pattern).matchingDegree(text); + } + @Nullable public Iterable matchingFragments(String pattern, String text) { + return obtainMatcher(pattern).matchingFragments(text); + } + + private MinusculeMatcher obtainMatcher(String pattern) { if (myRecentSearchText == null || !myRecentSearchText.equals(pattern)) { myRecentSearchText = pattern; if (myShouldMatchCamelCase) { @@ -55,7 +63,7 @@ public class SpeedSearchComparator { } myMinusculeMatcher = new MinusculeMatcher(pattern, NameUtil.MatchingCaseSensitivity.NONE); } - return myMinusculeMatcher.matchingFragments(text); + return myMinusculeMatcher; } public String getRecentSearchText() { diff --git a/platform/platform-impl/src/com/intellij/ui/SpeedSearchObjectWithWeight.java b/platform/platform-impl/src/com/intellij/ui/SpeedSearchObjectWithWeight.java index dd682c76d310..e0328a59f1d8 100644 --- a/platform/platform-impl/src/com/intellij/ui/SpeedSearchObjectWithWeight.java +++ b/platform/platform-impl/src/com/intellij/ui/SpeedSearchObjectWithWeight.java @@ -15,52 +15,25 @@ */ package com.intellij.ui; -import com.intellij.openapi.util.TextRange; - -import java.util.*; +import java.util.ArrayList; +import java.util.List; +import java.util.ListIterator; /** * @author Konstantin Bulenkov */ public class SpeedSearchObjectWithWeight { - private static final Comparator TEXT_RANGE_COMPARATOR = new Comparator() { - @Override - public int compare(TextRange o1, TextRange o2) { - if (o1.getStartOffset() == o2.getStartOffset()) { - return o2.getEndOffset() - o1.getEndOffset(); //longer is better - } - return o1.getStartOffset() - o2.getStartOffset(); - } - }; - public final Object node; - final List weights = new ArrayList(); + public final int weight; SpeedSearchObjectWithWeight(Object element, String pattern, SpeedSearchBase speedSearch) { this.node = element; - final String text = speedSearch.getElementText(element); - if (text != null) { - final Iterable ranges = speedSearch.getComparator().matchingFragments(pattern, text); - if (ranges != null) { - for (TextRange range : ranges) { - weights.add(range); - } - } - } - Collections.sort(weights, TEXT_RANGE_COMPARATOR); + String text = speedSearch.getElementText(element); + this.weight = text == null ? Integer.MIN_VALUE : speedSearch.getComparator().matchingDegree(pattern, text); } public int compareWith(SpeedSearchObjectWithWeight obj) { - final List w = obj.weights; - for (int i = 0; i < weights.size(); i++) { - if (i >= w.size()) return 1; - final int result = TEXT_RANGE_COMPARATOR.compare(weights.get(i), w.get(i)); - if (result != 0) { - return result; - } - } - - return 0; + return weight == obj.weight ? 0 : weight < obj.weight ? 1 : -1; } public static List findElement(String s, SpeedSearchBase speedSearch) { @@ -70,7 +43,7 @@ public class SpeedSearchObjectWithWeight { final ListIterator it = speedSearch.getElementIterator(0); while (it.hasNext()) { final SpeedSearchObjectWithWeight o = new SpeedSearchObjectWithWeight(it.next(), s, speedSearch); - if (!o.weights.isEmpty()) { + if (o.weight != Integer.MIN_VALUE) { elements.add(o); } }