Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feature(api): Skip style builder creation on merge
`mergeStyle` is called a lot, especially in TranslatableComponentRenderer, where there is no merging to be done. By skipping the creation of the builder if the merge is a no-op, we can save some allocations.
  • Loading branch information
kezz committed Apr 22, 2025
commit dc91d3c02e552c7e423f2ac355285a6aa5c6413c
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,13 @@ private void prepareChildren() {
@Override
@SuppressWarnings("unchecked")
public @NotNull B mergeStyle(final @NotNull Component that, final @NotNull Set<Style.Merge> merges) {
this.styleBuilder().merge(requireNonNull(that, "component").style(), merges);
final Style thatStyle = requireNonNull(that, "that").style();
if (thatStyle.isEmpty() && merges.isEmpty()) return (B) this;
if (!this.hasStyle()) {
this.style = thatStyle;
} else {
this.styleBuilder().merge(thatStyle, merges);
}
return (B) this;
}

Expand All @@ -313,6 +319,7 @@ private void prepareChildren() {
return this.styleBuilder;
}

@SuppressWarnings("BooleanMethodIsAlwaysInverted")
protected final boolean hasStyle() {
return this.styleBuilder != null || this.style != null;
}
Expand Down