Skip to content

Commit

Permalink
[Performance] Add check to speed up function
Browse files Browse the repository at this point in the history
  • Loading branch information
NEZNAMY committed Sep 13, 2024
1 parent ae03436 commit 225f30a
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions shared/src/main/java/me/neznamy/tab/shared/Property.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ public class Property {

/** Last known value after parsing non-relational placeholders */
private String lastReplacedValue;

/** Flag tracking whether last replaced value may contain relational placeholders or not */
private boolean mayContainRelPlaceholders;

/** Source defining value of the text, displayed in debug command */
@Nullable private String source;
Expand Down Expand Up @@ -272,6 +275,7 @@ public boolean update() {
string = EnumChatFormat.color(string);
if (!lastReplacedValue.equals(string)) {
lastReplacedValue = string;
mayContainRelPlaceholders = lastReplacedValue.indexOf('%') != -1;
if (name != null) {
TAB.getInstance().getPlaceholderManager().getTabExpansion().setPropertyValue(owner, name, lastReplacedValue);
}
Expand All @@ -297,6 +301,7 @@ public boolean update() {
* @return format for the viewer
*/
public @NotNull String getFormat(@NotNull TabPlayer viewer) {
if (!mayContainRelPlaceholders) return lastReplacedValue;
String format = lastReplacedValue;
// Direct placeholders
for (String identifier : relPlaceholders) {
Expand Down

0 comments on commit 225f30a

Please sign in to comment.