mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Effects processing optimization
GitOrigin-RevId: a9e91bb6cc0eaabd5cf9a654c195e76fbbeb5536
This commit is contained in:
committed by
intellij-monorepo-bot
parent
0318ee20b9
commit
fb7cb90bb2
+22
-16
@@ -8,8 +8,10 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
import static com.intellij.openapi.editor.markup.EffectType.*;
|
||||
@@ -109,14 +111,6 @@ public class TextAttributesEffectsBuilder {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list of descriptors of current effects
|
||||
*/
|
||||
@NotNull
|
||||
List<EffectDescriptor> getDescriptorsList() {
|
||||
return myEffectsMap.isEmpty() ? ContainerUtil.emptyList() : new ArrayList<>(myEffectsMap.values());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return map of {@link EffectType} => {@link Color} representation of builder state
|
||||
*/
|
||||
@@ -138,22 +132,34 @@ public class TextAttributesEffectsBuilder {
|
||||
* Applies effects from the current state to the target attributes
|
||||
*
|
||||
* @param targetAttributes passed targetAttributes
|
||||
* @apiNote this method is not a thread safe, builder can't be modified in some other thread when applying to something
|
||||
*/
|
||||
@NotNull
|
||||
public TextAttributes applyTo(@NotNull final TextAttributes targetAttributes) {
|
||||
List<EffectDescriptor> allEffects = getDescriptorsList();
|
||||
if (allEffects.isEmpty()) {
|
||||
Iterator<EffectDescriptor> effectsIterator = myEffectsMap.values().iterator();
|
||||
if (!effectsIterator.hasNext()) {
|
||||
targetAttributes.setEffectColor(null);
|
||||
targetAttributes.setEffectType(BOXED);
|
||||
targetAttributes.setAdditionalEffects(Collections.emptyMap());
|
||||
}
|
||||
else {
|
||||
Map<EffectType, Color> effectsMap = new HashMap<>();
|
||||
EffectDescriptor mainEffectDescriptor = allEffects.remove(0);
|
||||
EffectDescriptor mainEffectDescriptor = effectsIterator.next();
|
||||
targetAttributes.setEffectType(mainEffectDescriptor.effectType);
|
||||
targetAttributes.setEffectColor(mainEffectDescriptor.effectColor);
|
||||
allEffects.forEach(it -> effectsMap.put(it.effectType, it.effectColor));
|
||||
targetAttributes.setAdditionalEffects(effectsMap);
|
||||
|
||||
int effectsLeft = myEffectsMap.size() - 1;
|
||||
if (effectsLeft == 0) {
|
||||
targetAttributes.setAdditionalEffects(Collections.emptyMap());
|
||||
}
|
||||
else if (effectsLeft == 1) {
|
||||
EffectDescriptor additionalEffect = effectsIterator.next();
|
||||
targetAttributes.setAdditionalEffects(Collections.singletonMap(additionalEffect.effectType, additionalEffect.effectColor));
|
||||
}
|
||||
else {
|
||||
Map<EffectType, Color> effectsMap = new HashMap<>(effectsLeft);
|
||||
effectsIterator.forEachRemaining(it -> effectsMap.put(it.effectType, it.effectColor));
|
||||
targetAttributes.setAdditionalEffects(effectsMap);
|
||||
}
|
||||
}
|
||||
return targetAttributes;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user