Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: faster processing of large file #543

Merged
merged 12 commits into from
Jun 9, 2023
Merged
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
2 changes: 1 addition & 1 deletion org.eclipse.tm4e.core/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Bundle-Name: %pluginName
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Bundle-SymbolicName: org.eclipse.tm4e.core
Bundle-Version: 0.5.4.qualifier
Bundle-Version: 0.5.5.qualifier
Require-Bundle: org.apache.batik.css;bundle-version="1.9.1";resolution:=optional,
org.apache.batik.util;bundle-version="1.9.1";resolution:=optional,
com.google.gson;bundle-version="2.9.0",
Expand Down
2 changes: 1 addition & 1 deletion org.eclipse.tm4e.core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<artifactId>org.eclipse.tm4e.core</artifactId>
<packaging>eclipse-plugin</packaging>
<version>0.5.4-SNAPSHOT</version>
<version>0.5.5-SNAPSHOT</version>

<profiles>
<profile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
import org.eclipse.tm4e.core.internal.grammar.tokenattrs.EncodedTokenAttributes;
import org.eclipse.tm4e.core.internal.theme.FontStyle;
import org.eclipse.tm4e.core.internal.theme.StyleAttributes;

import com.google.common.base.Splitter;
import org.eclipse.tm4e.core.internal.utils.StringUtils;

/**
* @see <a href=
Expand All @@ -37,8 +36,6 @@ public final class AttributedScopeStack {
record Frame(int encodedTokenAttributes, List<String> scopeNames) {
}

private static final Splitter BY_SPACE_SPLITTER = Splitter.on(' ');

@Nullable
static AttributedScopeStack fromExtension(final @Nullable AttributedScopeStack namesScopeList,
final List<AttributedScopeStack.Frame> contentNameScopesList) {
Expand Down Expand Up @@ -160,7 +157,7 @@ AttributedScopeStack pushAttributed(final @Nullable String scopePath, final Gram
return _pushAttributed(this, scopePath, grammar);
}

final var scopes = BY_SPACE_SPLITTER.split(scopePath);
final var scopes = StringUtils.splitToArray(scopePath, ' ');
var result = this;
for (final var scope : scopes) {
result = _pushAttributed(result, scope, grammar);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
* "https://github.com/microsoft/vscode-textmate/blob/88baacf1a6637c5ec08dce18cea518d935fcf0a0/src/grammar/grammar.ts#L898">
* github.com/microsoft/vscode-textmate/blob/main/src/grammar/grammar.ts</a>
*/
public class BalancedBracketSelectors {
public final class BalancedBracketSelectors {
private final Matcher<List<String>>[] balancedBracketScopes;
private final Matcher<List<String>>[] unbalancedBracketScopes;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import org.eclipse.tm4e.core.internal.types.IRawCaptures;
import org.eclipse.tm4e.core.internal.types.IRawRule;

public class RawCaptures extends HashMap<String, IRawRule> implements IRawCaptures, PropertySettable<IRawRule> {
public final class RawCaptures extends HashMap<String, IRawRule> implements IRawCaptures, PropertySettable<IRawRule> {

private static final long serialVersionUID = 1L;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import org.eclipse.tm4e.core.internal.types.IRawRepository;
import org.eclipse.tm4e.core.internal.types.IRawRule;

public class RawGrammar extends HashMap<String, @Nullable Object> implements IRawGrammar, PropertySettable<Object> {
public final class RawGrammar extends HashMap<String, @Nullable Object> implements IRawGrammar, PropertySettable<Object> {

private static final String FILE_TYPES = "fileTypes";
private static final String FIRST_LINE_MATCH = "firstLineMatch";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import org.eclipse.tm4e.core.internal.types.IRawRepository;
import org.eclipse.tm4e.core.internal.types.IRawRule;

public class RawRepository extends HashMap<String, IRawRule> implements IRawRepository, PropertySettable<IRawRule> {
public final class RawRepository extends HashMap<String, IRawRule> implements IRawRepository, PropertySettable<IRawRule> {

private static final long serialVersionUID = 1L;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
* "https://github.com/microsoft/vscode-textmate/blob/88baacf1a6637c5ec08dce18cea518d935fcf0a0/src/theme.ts#L101">
* github.com/microsoft/vscode-textmate/blob/main/src/theme.ts</a>
*/
public class ScopeStack {
public final class ScopeStack {

@Nullable
static ScopeStack push(@Nullable ScopeStack path, final List<String> scopeNames) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
* "https://github.com/microsoft/vscode-textmate/blob/88baacf1a6637c5ec08dce18cea518d935fcf0a0/src/grammar/grammarDependencies.ts#L59">
* github.com/microsoft/vscode-textmate/blob/main/src/grammar/grammarDependencies.ts</a>
*/
public class ScopeDependencyProcessor {
public final class ScopeDependencyProcessor {

private static class ExternalReferenceCollector {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@

import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.tm4e.core.internal.grammar.ScopeStack;
import org.eclipse.tm4e.core.internal.utils.StringUtils;

import com.google.common.base.Splitter;
import com.google.common.collect.Lists;

/**
Expand All @@ -36,9 +36,6 @@
*/
public final class Theme {

private static final Splitter BY_COMMA_SPLITTER = Splitter.on(',');
private static final Splitter BY_SPACE_SPLITTER = Splitter.on(' ');

public static Theme createFromRawTheme(@Nullable final IRawTheme source, @Nullable final List<String> colorMap) {
return createFromParsedTheme(parseTheme(source), colorMap);
}
Expand Down Expand Up @@ -147,7 +144,7 @@ public static List<ParsedThemeRule> parseTheme(@Nullable final IRawTheme source)
// remove trailing commas
_scope = _scope.replaceAll(",+$", "");

scopes = BY_COMMA_SPLITTER.splitToList(_scope);
scopes = StringUtils.splitToList(_scope, ',');
} else if (settingScope instanceof List) {
@SuppressWarnings("unchecked")
final var settingScopes = (List<String>) settingScope;
Expand All @@ -161,7 +158,7 @@ public static List<ParsedThemeRule> parseTheme(@Nullable final IRawTheme source)
if (settingsFontStyle instanceof final String style) {
fontStyle = FontStyle.None;

final var segments = BY_SPACE_SPLITTER.split(style);
final var segments = StringUtils.splitToArray(style, ' ');
for (final var segment : segments) {
switch (segment) {
case "italic":
Expand Down Expand Up @@ -197,7 +194,7 @@ && isValidHexColor(stringSettingsBackground)) {
for (int j = 0, lenJ = scopes.size(); j < lenJ; j++) {
final var _scope = scopes.get(j).trim();

final var segments = BY_SPACE_SPLITTER.splitToList(_scope);
final var segments = StringUtils.splitToList(_scope, ' ');

final var scope = getLastElement(segments);
List<String> parentScopes = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import org.w3c.dom.css.RGBColor;
import org.w3c.dom.css.Rect;

abstract class CSSValueImpl implements CSSPrimitiveValue {
abstract class AbstractCSSValue implements CSSPrimitiveValue { // FIXME rename

// W3C CSSValue API methods

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@

public abstract class AbstractCombinatorCondition implements CombinatorCondition, ExtendedCondition {

private final Condition firstCondition;
private final Condition secondCondition;
protected final ExtendedCondition firstCondition;
protected final ExtendedCondition secondCondition;

/**
* Creates a new CombinatorCondition object.
*/
protected AbstractCombinatorCondition(final Condition c1, final Condition c2) {
protected AbstractCombinatorCondition(final ExtendedCondition c1, final ExtendedCondition c2) {
firstCondition = c1;
secondCondition = c2;
}
Expand All @@ -39,7 +39,6 @@ public Condition getSecondCondition() {

@Override
public int getSpecificity() {
return ((ExtendedCondition) getFirstCondition()).getSpecificity()
+ ((ExtendedCondition) getSecondCondition()).getSpecificity();
return firstCondition.getSpecificity() + secondCondition.getSpecificity();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,12 @@
*/
package org.eclipse.tm4e.core.internal.theme.css;

import org.w3c.css.sac.Condition;

final class CSSAndCondition extends AbstractCombinatorCondition {

/**
* Creates a new CombinatorCondition object.
*/
CSSAndCondition(final Condition c1, final Condition c2) {
CSSAndCondition(final ExtendedCondition c1, final ExtendedCondition c2) {
super(c1, c2);
}

Expand All @@ -29,13 +27,11 @@ public short getConditionType() {

@Override
public int nbMatch(final String... names) {
return ((ExtendedCondition) getFirstCondition()).nbMatch(names)
+ ((ExtendedCondition) getSecondCondition()).nbMatch(names);
return firstCondition.nbMatch(names) + secondCondition.nbMatch(names);
}

@Override
public int nbClass() {
return ((ExtendedCondition) getFirstCondition()).nbClass()
+ ((ExtendedCondition) getSecondCondition()).nbClass();
return firstCondition.nbClass() + secondCondition.nbClass();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public AttributeCondition createAttributeCondition(final String localName, final

@Override
public CombinatorCondition createAndCondition(final Condition first, final Condition second) throws CSSException {
return new CSSAndCondition(first, second);
return new CSSAndCondition((ExtendedCondition) first, (ExtendedCondition) second);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,11 @@

final class CSSConditionalSelector implements ConditionalSelector, ExtendedSelector {

/**
* The simple selector.
*/
private final SimpleSelector simpleSelector;
private final ExtendedSelector selector;
private final ExtendedCondition condition;

/**
* The condition.
*/
private final Condition condition;

/**
* Creates a new ConditionalSelector object.
*/
CSSConditionalSelector(final SimpleSelector simpleSelector, final Condition condition) {
this.simpleSelector = simpleSelector;
CSSConditionalSelector(final ExtendedSelector simpleSelector, final ExtendedCondition condition) {
this.selector = simpleSelector;
this.condition = condition;
}

Expand All @@ -47,25 +37,21 @@ public Condition getCondition() {

@Override
public SimpleSelector getSimpleSelector() {
return simpleSelector;
return selector;
}

@Override
public int getSpecificity() {
return ((ExtendedSelector) getSimpleSelector()).getSpecificity()
+ ((ExtendedCondition) getCondition()).getSpecificity();
return selector.getSpecificity() + condition.getSpecificity();
}

@Override
public int nbMatch(final String... names) {
return ((ExtendedSelector) getSimpleSelector()).nbMatch(names)
+ ((ExtendedCondition) getCondition()).nbMatch(names);
return selector.nbMatch(names) + condition.nbMatch(names);
}

@Override
public int nbClass() {
return ((ExtendedSelector) getSimpleSelector()).nbClass()
+ ((ExtendedCondition) getCondition()).nbClass();
return selector.nbClass() + condition.nbClass();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public CharacterDataSelector createCommentSelector(final String arg0) throws CSS
@Override
public ConditionalSelector createConditionalSelector(final SimpleSelector selector, final Condition condition)
throws CSSException {
return new CSSConditionalSelector(selector, condition);
return new CSSConditionalSelector((ExtendedSelector) selector, (ExtendedCondition) condition);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
*/
package org.eclipse.tm4e.core.internal.theme.css;

interface ExtendedCondition {
import org.w3c.css.sac.Condition;

interface ExtendedCondition extends Condition {

/**
* Returns the specificity of this condition.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
*/
package org.eclipse.tm4e.core.internal.theme.css;

import org.w3c.css.sac.Selector;
import org.w3c.css.sac.SimpleSelector;

public interface ExtendedSelector extends Selector {
public interface ExtendedSelector extends SimpleSelector {

/**
* Returns the specificity of this selector.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import org.w3c.dom.DOMException;
import org.w3c.dom.css.CSSValue;

final class Measure extends CSSValueImpl {
final class Measure extends AbstractCSSValue {

private final LexicalUnit value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import org.w3c.dom.css.CSSPrimitiveValue;
import org.w3c.dom.css.RGBColor;

final class RGBColorImpl extends CSSValueImpl implements RGBColor {
final class RGBColorImpl extends AbstractCSSValue implements RGBColor {

private final CSSPrimitiveValue red;
private final CSSPrimitiveValue green;
Expand Down
Loading