menumanager: reuse perfectly fine Matcher instances (#1275)
This commit is contained in:
@@ -24,8 +24,11 @@
|
||||
*/
|
||||
package net.runelite.api;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
/**
|
||||
@@ -83,4 +86,18 @@ public class MenuEntry
|
||||
src.isForceLeftClick()
|
||||
);
|
||||
}
|
||||
|
||||
private static final Matcher TAG_REGEXP = Pattern.compile("<[^>]*>").matcher("");
|
||||
|
||||
@Getter(lazy = true)
|
||||
private final String standardizedOption = standardize(option);
|
||||
@Getter(lazy = true)
|
||||
private final String standardizedTarget = standardize(LEVEL_MATCHER.reset(target).replaceAll(""));
|
||||
|
||||
public String standardize(String string)
|
||||
{
|
||||
return TAG_REGEXP.reset(string).replaceAll("").replace('\u00A0', ' ').trim();
|
||||
}
|
||||
|
||||
private static final Matcher LEVEL_MATCHER = Pattern.compile("\\(level-[0-9]*\\)").matcher("");
|
||||
}
|
||||
|
||||
@@ -28,7 +28,6 @@ import javax.annotation.Nonnull;
|
||||
import joptsimple.internal.Strings;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import net.runelite.api.MenuEntry;
|
||||
import static net.runelite.client.menus.MenuManager.LEVEL_PATTERN;
|
||||
import net.runelite.client.util.Text;
|
||||
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@@ -52,7 +51,7 @@ public class BaseComparableEntry extends AbstractComparableEntry
|
||||
|
||||
public boolean matches(@Nonnull MenuEntry entry)
|
||||
{
|
||||
String opt = Text.standardize(entry.getOption());
|
||||
String opt = entry.getStandardizedOption();
|
||||
|
||||
if (strictOption && !opt.equals(option) || !strictOption && !opt.contains(option))
|
||||
{
|
||||
@@ -61,7 +60,7 @@ public class BaseComparableEntry extends AbstractComparableEntry
|
||||
|
||||
if (strictTarget || !Strings.isNullOrEmpty(target))
|
||||
{
|
||||
String tgt = Text.standardize(LEVEL_PATTERN.matcher(entry.getTarget()).replaceAll(""));
|
||||
String tgt = entry.getStandardizedTarget();
|
||||
|
||||
if (strictTarget && !tgt.equals(target) || !strictTarget && !tgt.contains(target))
|
||||
{
|
||||
|
||||
@@ -40,7 +40,6 @@ import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.inject.Inject;
|
||||
@@ -75,7 +74,6 @@ public class MenuManager
|
||||
*/
|
||||
private static final int IDX_LOWER = 4;
|
||||
private static final int IDX_UPPER = 8;
|
||||
static final Pattern LEVEL_PATTERN = Pattern.compile("\\(level-[0-9]*\\)");
|
||||
|
||||
private final Client client;
|
||||
private final EventBus eventBus;
|
||||
|
||||
@@ -30,6 +30,7 @@ import com.google.common.base.Joiner;
|
||||
import com.google.common.base.Splitter;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import org.apache.commons.text.WordUtils;
|
||||
|
||||
@@ -38,7 +39,7 @@ import org.apache.commons.text.WordUtils;
|
||||
*/
|
||||
public class Text
|
||||
{
|
||||
private static final Pattern TAG_REGEXP = Pattern.compile("<[^>]*>");
|
||||
private static final Matcher TAG_REGEXP = Pattern.compile("<[^>]*>").matcher("");
|
||||
private static final Splitter COMMA_SPLITTER = Splitter
|
||||
.on(",")
|
||||
.omitEmptyStrings()
|
||||
@@ -78,7 +79,7 @@ public class Text
|
||||
*/
|
||||
public static String removeTags(String str)
|
||||
{
|
||||
return TAG_REGEXP.matcher(str).replaceAll("");
|
||||
return TAG_REGEXP.reset(str).replaceAll("");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user