Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,14 @@ public void should_convert_regex_to_eclipse_search_pattern() throws Exception
// then
assertThat(eval.getAllCorrespondingFileEclipsePatterns()).containsExactly("Pre*File*Suf", "Pre*File", "File*Suf");
}

@Test
public void should_simplify_successive_quote_separators() throws Exception
{
// given
FileNameEvaluation eval = new FileNameEvaluation("Irrelevant", false, "PreFileSuf", asList("\\QPre\\E\\QFile\\E"), NO_PATTERNS);

// then
assertThat(eval.getAllCorrespondingFilePatterns()).containsExactly("\\QPreFile\\E");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.regex.Pattern;

import org.moreunit.core.util.StringConstants;

Expand All @@ -21,10 +20,6 @@
*/
public final class FileNameEvaluation
{
private static final Pattern QUOTE_SEPARATORS = Pattern.compile("(?:\\\\Q|\\\\E)");
private static final Pattern SUCCESSIVE_QUOTE_SEPARATORS = Pattern.compile("\\\\E\\\\Q");
private static final Pattern WILDCARDS = Pattern.compile("\\.\\*");

private final String evaluatedFileName;
private final boolean testFile;
private final Collection<String> otherCorrespondingFilePatterns;
Expand All @@ -45,7 +40,8 @@ private static Collection<String> simplify(Collection<String> patterns)
List<String> result = new ArrayList<String>();
for (String pattern : patterns)
{
result.add(SUCCESSIVE_QUOTE_SEPARATORS.matcher(pattern).replaceAll(""));
// Bolt performance optimization: use String.replace for simple literal replacements instead of regex matchers.
result.add(pattern.replace("\\E\\Q", ""));
}
return result;
}
Expand Down Expand Up @@ -83,7 +79,8 @@ public List<String> getAllCorrespondingFileEclipsePatterns()

private String convertWildcards(String str)
{
return WILDCARDS.matcher(str).replaceAll("*");
// Bolt performance optimization: use String.replace for literal replacements instead of regex Pattern compilation/evaluation.
return str.replace(".*", "*");
}

/**
Expand Down Expand Up @@ -126,7 +123,8 @@ public String getPreferredCorrespondingFileName()

private String removeQuotes(String str)
{
return QUOTE_SEPARATORS.matcher(str).replaceAll("");
// Bolt performance optimization: chained String.replace avoids Matcher allocations and is significantly faster than regex parsing for static literals.
return str.replace("\\Q", "").replace("\\E", "");
}

@Override
Expand Down
Loading