mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Bug 565553 - Improve performance of build command parsers with large number of files
Optimize MSVCBuildCommandParser.unescapeString. Instead of running a Matcher/replaceAll every time, check first if the string contains the characters to unescape first. Finding a substring in a string is much faster than matching a pattern so this saves quite a bit of time on large MSVC projects since many options will not have the characters needed to be unescaped. Change-Id: If2ad7892c29374458d5de446d4492ce3ba576c9c Signed-off-by: Marc-Andre Laperle <malaperle@gmail.com>
This commit is contained in:
parent
68c9b53de0
commit
a9b67d0828
1 changed files with 11 additions and 2 deletions
|
@ -26,11 +26,20 @@ import org.eclipse.cdt.managedbuilder.language.settings.providers.AbstractBuildC
|
|||
*/
|
||||
public class MSVCBuildCommandParser extends AbstractBuildCommandParser implements ILanguageSettingsEditableProvider {
|
||||
|
||||
private static final String DOUBLE_BACKSLASH = "\\\\"; //$NON-NLS-1$
|
||||
private static final Pattern DOUBLE_BACKSLASH_PATTERN = Pattern.compile(Pattern.quote(DOUBLE_BACKSLASH));
|
||||
private static final String BACKSLASH_REPLACEMENT_STRING = "\\\\"; //$NON-NLS-1$
|
||||
private static final String BACKSLASH_QUOTE = "\\\""; //$NON-NLS-1$
|
||||
private static final Pattern BACKSLASH_QUOTE_PATTERN = Pattern.compile(Pattern.quote(BACKSLASH_QUOTE));
|
||||
private static final String QUOTE_REPLACEMENT_STRING = "\""; //$NON-NLS-1$
|
||||
|
||||
private static String unescapeString(String value) {
|
||||
// There are probably many other things to unescape but these are the most
|
||||
// common.
|
||||
value = value.replaceAll("\\\\\\\\", "\\\\"); //$NON-NLS-1$//$NON-NLS-2$
|
||||
value = value.replaceAll("\\\\\"", "\""); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
if (value.contains(DOUBLE_BACKSLASH))
|
||||
value = DOUBLE_BACKSLASH_PATTERN.matcher(value).replaceAll(BACKSLASH_REPLACEMENT_STRING);
|
||||
if (value.contains(BACKSLASH_QUOTE))
|
||||
value = BACKSLASH_QUOTE_PATTERN.matcher(value).replaceAll(QUOTE_REPLACEMENT_STRING);
|
||||
return value;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue