From f31dd2bea96bfd4c52827a1f6c6b06dd36479fa4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=A7=E9=98=94?= <1520622465@qq.com> Date: Fri, 3 Jan 2025 03:18:40 +0800 Subject: [PATCH] Add fast path check for closure.head and closure.tail --- .../java/me/clip/placeholderapi/replacer/CharsReplacer.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/me/clip/placeholderapi/replacer/CharsReplacer.java b/src/main/java/me/clip/placeholderapi/replacer/CharsReplacer.java index c5ad7b1..171359f 100644 --- a/src/main/java/me/clip/placeholderapi/replacer/CharsReplacer.java +++ b/src/main/java/me/clip/placeholderapi/replacer/CharsReplacer.java @@ -46,7 +46,8 @@ public final class CharsReplacer implements Replacer { @Override public String apply(@NotNull final String text, @Nullable final OfflinePlayer player, @NotNull final Function lookup) { - if (text.indexOf(closure.head) == -1) { // Fast path - return directly if no placeholders + // Fast path: If there's no closure.head or closure.tail, return the text immediately + if (text.indexOf(closure.head) == -1 || text.lastIndexOf(closure.tail) == -1 || text.lastIndexOf(closure.tail) < text.indexOf(closure.head)) { return text; }