summaryrefslogtreecommitdiff
path: root/platform/platform-impl/src/com/intellij/openapi/editor/impl/DefaultEditorTextRepresentationHelper.java
diff options
context:
space:
mode:
Diffstat (limited to 'platform/platform-impl/src/com/intellij/openapi/editor/impl/DefaultEditorTextRepresentationHelper.java')
-rw-r--r--platform/platform-impl/src/com/intellij/openapi/editor/impl/DefaultEditorTextRepresentationHelper.java34
1 files changed, 12 insertions, 22 deletions
diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/DefaultEditorTextRepresentationHelper.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/DefaultEditorTextRepresentationHelper.java
index 9b2e473a0da5..61415eb90ce4 100644
--- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/DefaultEditorTextRepresentationHelper.java
+++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/DefaultEditorTextRepresentationHelper.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2012 JetBrains s.r.o.
+ * Copyright 2000-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,14 +16,14 @@
package com.intellij.openapi.editor.impl;
import com.intellij.openapi.editor.Editor;
-import com.intellij.openapi.editor.colors.EditorColorsScheme;
import com.intellij.openapi.editor.ex.util.EditorUtil;
import gnu.trove.TObjectIntHashMap;
import org.intellij.lang.annotations.JdkConstants;
import org.jetbrains.annotations.NotNull;
/**
- * Not thread-safe.
+ * Not thread-safe. Performs caching of char widths, so cache reset must be invoked (via {@link #clearSymbolWidthCache()} method) when
+ * font settings are changed in editor.
*
* @author Denis Zhdanov
* @since Jul 27, 2010 4:06:27 PM
@@ -60,9 +60,6 @@ public class DefaultEditorTextRepresentationHelper implements EditorTextRepresen
public int charWidth(char c, int fontType) {
// Symbol width retrieval is detected to be a bottleneck, hence, we perform a caching here in assumption that every representation
// helper is editor-bound and cache size is not too big.
- EditorColorsScheme colorsScheme = myEditor.getColorsScheme();
- mySharedKey.fontName = colorsScheme.getEditorFontName();
- mySharedKey.fontSize = colorsScheme.getEditorFontSize();
mySharedKey.fontType = fontType;
mySharedKey.c = c;
@@ -83,9 +80,6 @@ public class DefaultEditorTextRepresentationHelper implements EditorTextRepresen
// Symbol width retrieval is detected to be a bottleneck, hence, we perform a caching here in assumption that every representation
// helper is editor-bound and cache size is not too big.
- EditorColorsScheme colorsScheme = myEditor.getColorsScheme();
- mySharedKey.fontName = colorsScheme.getEditorFontName();
- mySharedKey.fontSize = colorsScheme.getEditorFontSize();
mySharedKey.fontType = fontType;
for (int i = startToUse; i < end; i++) {
@@ -107,7 +101,7 @@ public class DefaultEditorTextRepresentationHelper implements EditorTextRepresen
return result;
}
Key key = mySharedKey.clone();
- FontInfo font = ComplementaryFontsRegistry.getFontAbleToDisplay(c, key.fontSize, key.fontType, key.fontName);
+ FontInfo font = ComplementaryFontsRegistry.getFontAbleToDisplay(c, key.fontType, myEditor.getColorsScheme().getFontPreferences());
result = font.charWidth(c);
if (mySymbolWidthCache.size() >= MAX_SYMBOLS_WIDTHS_CACHE_SIZE) {
// Don't expect to be here.
@@ -117,33 +111,31 @@ public class DefaultEditorTextRepresentationHelper implements EditorTextRepresen
return result;
}
+ public void clearSymbolWidthCache() {
+ mySymbolWidthCache.clear();
+ }
+
private static class Key {
- public String fontName;
- private int fontSize;
@JdkConstants.FontStyle private int fontType;
private char c;
private Key() {
- this(null, 0, 0, ' ');
+ this(0, ' ');
}
- Key(String fontName, int fontSize, @JdkConstants.FontStyle int fontType, char c) {
- this.fontName = fontName;
- this.fontSize = fontSize;
+ Key(@JdkConstants.FontStyle int fontType, char c) {
this.fontType = fontType;
this.c = c;
}
@Override
protected Key clone() {
- return new Key(fontName, fontSize, fontType, c);
+ return new Key(fontType, c);
}
@Override
public int hashCode() {
- int result = fontName != null ? fontName.hashCode() : 0;
- result = 31 * result + fontSize;
- result = 31 * result + fontType;
+ int result = fontType;
result = 31 * result + c;
return result;
}
@@ -155,10 +147,8 @@ public class DefaultEditorTextRepresentationHelper implements EditorTextRepresen
Key key = (Key)o;
- if (fontSize != key.fontSize) return false;
if (fontType != key.fontType) return false;
if (c != key.c) return false;
- if (fontName != null ? !fontName.equals(key.fontName) : key.fontName != null) return false;
return true;
}