Skip to content

Commit 7db31cd

Browse files
committed
Bring back (un)merge for Symbolics for better performance
1 parent d456102 commit 7db31cd

File tree

6 files changed

+50
-6
lines changed

6 files changed

+50
-6
lines changed

src/main/java/ink/glowing/text/Parser.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,7 @@ private Parser(@NotNull String textStr, @NotNull Context context) {
162162
SymbolicStyle symbolic = context.findSymbolicStyle(styleCh);
163163
if (symbolic == null) continue;
164164
appendPrevious(builder, lastAppend, index, context);
165-
context.lastStyle(symbolic.resets()
166-
? symbolic.base()
167-
: context.lastStyle().merge(symbolic.base())
168-
);
165+
context.lastStyle(symbolic.merge(context.lastStyle()));
169166
lastAppend = (++index) + 1;
170167
}
171168
}

src/main/java/ink/glowing/text/Stringifier.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,10 @@ private static void appendComponent(
115115
}
116116

117117
private static @NotNull TreeSet<SymbolicStyle> pullSymbolics(@NotNull Style style, @NotNull InkyMessage inkyMessage) {
118-
// TODO StyleBuilder?
119118
TreeSet<SymbolicStyle> found = new TreeSet<>();
120119
for (var symb : inkyMessage.symbolics().values()) {
121120
if (symb.isApplied(style)) {
122-
style = style.unmerge(symb.base());
121+
style = symb.unmerge(style);
123122
found.add(symb);
124123
if (style.isEmpty()) return found;
125124
}
@@ -167,6 +166,16 @@ public boolean isApplied(@NotNull Style at) {
167166
return cleanStyle;
168167
}
169168

169+
@Override
170+
public @NotNull Style merge(@NotNull Style other) {
171+
return cleanStyle;
172+
}
173+
174+
@Override
175+
public @NotNull Style unmerge(@NotNull Style other) {
176+
return other.color(null);
177+
}
178+
170179
@Override
171180
public @NotNull String asFormatted() {
172181
return "&" + color.asHexString();

src/main/java/ink/glowing/text/symbolic/ChainedSymbolicDecoration.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,16 @@ public boolean isApplied(@NotNull Style at) {
4141
return cleanStyle;
4242
}
4343

44+
@Override
45+
public @NotNull Style merge(@NotNull Style other) {
46+
return other.decoration(decoration, TextDecoration.State.TRUE);
47+
}
48+
49+
@Override
50+
public @NotNull Style unmerge(@NotNull Style other) {
51+
return other.decoration(decoration, TextDecoration.State.NOT_SET);
52+
}
53+
4454
@Override
4555
public boolean equals(Object o) {
4656
if (this == o) return true;

src/main/java/ink/glowing/text/symbolic/ResettingSymbolicColor.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,16 @@ public boolean isApplied(@NotNull Style at) {
3939
return cleanStyle;
4040
}
4141

42+
@Override
43+
public @NotNull Style merge(@NotNull Style other) {
44+
return cleanStyle;
45+
}
46+
47+
@Override
48+
public @NotNull Style unmerge(@NotNull Style other) {
49+
return other.color(null);
50+
}
51+
4252
@Override
4353
public boolean equals(Object o) {
4454
if (this == o) return true;

src/main/java/ink/glowing/text/symbolic/SimpleSymbolicReset.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@ public boolean equals(Object obj) {
2828
return obj instanceof SimpleSymbolicReset(char otherSymbol) && otherSymbol == symbol;
2929
}
3030

31+
@Override
32+
public @NotNull Style merge(@NotNull Style other) {
33+
return Style.empty();
34+
}
35+
36+
@Override
37+
public @NotNull Style unmerge(@NotNull Style other) {
38+
return other;
39+
}
40+
3141
@Override
3242
public int hashCode() {
3343
return Objects.hash(symbol);

src/main/java/ink/glowing/text/symbolic/SymbolicStyle.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ public interface SymbolicStyle extends Ink, Comparable<SymbolicStyle>, SymbolicS
1515

1616
@NotNull Style base();
1717

18+
default @NotNull Style merge(@NotNull Style other) {
19+
return resets() ? base() : other.merge(base());
20+
}
21+
22+
default @NotNull Style unmerge(@NotNull Style other) {
23+
return other.unmerge(base());
24+
}
25+
1826
@Override
1927
default @Nullable SymbolicStyle findSymbolicStyle(char symbol) {
2028
return symbol() == symbol ? this : null;

0 commit comments

Comments
 (0)