From bb5cc12bbdfc43543d2553170406cb8c94f0a543 Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Wed, 5 Sep 2012 17:57:05 +0400 Subject: [PATCH] performance --- .../openapi/editor/markup/TextAttributes.java | 19 +++++++++++++++++-- .../openapi/editor/impl/IterationState.java | 17 +++++------------ 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/platform/core-api/src/com/intellij/openapi/editor/markup/TextAttributes.java b/platform/core-api/src/com/intellij/openapi/editor/markup/TextAttributes.java index a4c91b9525fe..461bcf70473d 100644 --- a/platform/core-api/src/com/intellij/openapi/editor/markup/TextAttributes.java +++ b/platform/core-api/src/com/intellij/openapi/editor/markup/TextAttributes.java @@ -75,10 +75,12 @@ public class TextAttributes implements JDOMExternalizable, Cloneable { private static final int EFFECT_BOLD_LINE = 4; private static final int EFFECT_BOLD_DOTTED_LINE = 5; + @Override public Object clone() throws CloneNotSupportedException { return super.clone(); } + @Override public void readExternal(Element element) throws InvalidDataException { DefaultJDOMExternalizer.readExternal(this, element); if (FONT_TYPE < 0 || FONT_TYPE > 3) { @@ -87,6 +89,7 @@ public class TextAttributes implements JDOMExternalizable, Cloneable { } } + @Override public void writeExternal(Element element) throws WriteExternalException { DefaultJDOMExternalizer.writeExternal(this, element); } @@ -138,11 +141,20 @@ public class TextAttributes implements JDOMExternalizable, Cloneable { private AttributesFlyweight myAttrs; public TextAttributes() { - myAttrs = AttributesFlyweight.create(null, null, Font.PLAIN, null, EffectType.BOXED, null); + this(null, null, null, EffectType.BOXED, Font.PLAIN); } public TextAttributes(Color foregroundColor, Color backgroundColor, Color effectColor, EffectType effectType, @JdkConstants.FontStyle int fontType) { - myAttrs = AttributesFlyweight.create(foregroundColor, backgroundColor, fontType, effectColor, effectType, null); + setAttributes(foregroundColor, backgroundColor, effectColor, null, effectType, fontType); + } + + public void setAttributes(Color foregroundColor, + Color backgroundColor, + Color effectColor, + Color errorStripeColor, + EffectType effectType, + @JdkConstants.FontStyle int fontType) { + myAttrs = AttributesFlyweight.create(foregroundColor, backgroundColor, fontType, effectColor, effectType, errorStripeColor); } public boolean isEmpty(){ @@ -212,6 +224,7 @@ public class TextAttributes implements JDOMExternalizable, Cloneable { myAttrs = myAttrs.withFontType(type); } + @Override public TextAttributes clone() { TextAttributes cloned = new TextAttributes(); cloned.myAttrs = myAttrs; @@ -230,6 +243,7 @@ public class TextAttributes implements JDOMExternalizable, Cloneable { return myAttrs.hashCode(); } + @Override public void readExternal(Element element) throws InvalidDataException { Externalizable ext = new Externalizable(); ext.readExternal(element); @@ -241,6 +255,7 @@ public class TextAttributes implements JDOMExternalizable, Cloneable { ext.ERROR_STRIPE_COLOR); } + @Override public void writeExternal(Element element) throws WriteExternalException { Externalizable ext = new Externalizable(); diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/IterationState.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/IterationState.java index 39d4b554ede4..d1169db10e98 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/IterationState.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/IterationState.java @@ -36,7 +36,6 @@ import java.util.Iterator; import java.util.List; public final class IterationState { - private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.editor.impl.IterationState"); private static final Comparator HIGHLIGHTER_COMPARATOR = new Comparator() { @@ -90,7 +89,7 @@ public final class IterationState { private final int mySelectionStart; private final int mySelectionEnd; - private final List myCurrentHighlighters; + private final List myCurrentHighlighters = new ArrayList(); private final FoldingModelEx myFoldingModel; @@ -103,7 +102,7 @@ public final class IterationState { private final Color myDefaultForeground; private final int myCaretRowStart; private final int myCaretRowEnd; - private final List myCachedAttributesList; + private final List myCachedAttributesList = new ArrayList(5); private final DocumentEx myDocument; private final EditorEx myEditor; private final Color myReadOnlyColor; @@ -113,7 +112,7 @@ public final class IterationState { */ public IterationState(@NotNull EditorEx editor, int start, int end, boolean useCaretAndSelection) { ApplicationManager.getApplication().assertReadAccessAllowed(); - myDocument = (DocumentEx)editor.getDocument(); + myDocument = editor.getDocument(); myStartOffset = start; myEnd = end; @@ -139,9 +138,6 @@ public final class IterationState { myCaretRowStart = caretModel.getVisualLineStart(); myCaretRowEnd = caretModel.getVisualLineEnd(); - myCachedAttributesList = new ArrayList(5); - - myCurrentHighlighters = new ArrayList(); MarkupModelEx editorMarkup = (MarkupModelEx)editor.getMarkupModel(); myView = new HighlighterSweep(editorMarkup, start, myEnd); @@ -467,11 +463,7 @@ public final class IterationState { if (back == null) back = myDefaultBackground; if (effectType == null) effectType = EffectType.BOXED; - myMergedAttributes.setForegroundColor(fore); - myMergedAttributes.setBackgroundColor(back); - myMergedAttributes.setFontType(fontType); - myMergedAttributes.setEffectColor(effect); - myMergedAttributes.setEffectType(effectType); + myMergedAttributes.setAttributes(fore, back, effect, null, effectType, fontType); } @Nullable @@ -492,6 +484,7 @@ public final class IterationState { return myEndOffset; } + @NotNull public TextAttributes getMergedAttributes() { return myMergedAttributes; }