Skip to content

Commit

Permalink
perf: cache CSSTokenProvider#getToken return values
Browse files Browse the repository at this point in the history
  • Loading branch information
sebthom committed Jun 9, 2023
1 parent db9d597 commit ea6810f
Showing 1 changed file with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.jface.text.TextAttribute;
Expand Down Expand Up @@ -46,6 +47,7 @@ public List<IStyle> getStyles() {
}

private final Map<IStyle, @Nullable IToken> tokenMaps = new HashMap<>();
private final Map<String, @Nullable IToken> getTokenReturnValueCache = new ConcurrentHashMap<>();

private final CSSParser parser;

Expand Down Expand Up @@ -86,11 +88,11 @@ public IToken getToken(@Nullable final String type) {
if (type == null)
return null;

final IStyle style = parser.getBestStyle(StringUtils.splitToArray(type, '.'));
if (style == null)
return null;

return tokenMaps.get(style);
return getTokenReturnValueCache.computeIfAbsent(type,
t -> {
IStyle style = parser.getBestStyle(StringUtils.splitToArray(type, '.'));
return style == null ? null : tokenMaps.get(style);
});
}

@Nullable
Expand Down

0 comments on commit ea6810f

Please sign in to comment.