CompletionResultSet/CamelHumpMatcher: reuse existing objects when possible instead of copying

This commit is contained in:
peter
2017-04-05 15:46:49 +02:00
parent 227b5db723
commit 0c879a72c5
2 changed files with 9 additions and 1 deletions
@@ -87,6 +87,10 @@ public class CamelHumpMatcher extends PrefixMatcher {
@Override
@NotNull
public PrefixMatcher cloneWithPrefix(@NotNull final String prefix) {
if (prefix.equals(myPrefix)) {
return this;
}
return new CamelHumpMatcher(prefix, myCaseSensitive);
}
@@ -143,6 +143,10 @@ public final class CompletionServiceImpl extends CompletionService {
@Override
@NotNull
public CompletionResultSet withPrefixMatcher(@NotNull final PrefixMatcher matcher) {
if (matcher.equals(getPrefixMatcher())) {
return this;
}
return new CompletionResultSetImpl(getConsumer(), myLengthOfTextBeforePosition, matcher, myContributor, myParameters, mySorter, this);
}
@@ -160,7 +164,7 @@ public final class CompletionServiceImpl extends CompletionService {
@Override
@NotNull
public CompletionResultSet withPrefixMatcher(@NotNull final String prefix) {
return withPrefixMatcher(new CamelHumpMatcher(prefix));
return withPrefixMatcher(getPrefixMatcher().cloneWithPrefix(prefix));
}
@NotNull