From bc2578b7887f38e8106a1d4c2ce000618c19bb23 Mon Sep 17 00:00:00 2001 From: KHobbits Date: Mon, 13 Feb 2012 19:40:33 +0000 Subject: [PATCH] Caching regex return in user cleanup. (Pushing this for testing purposes). --- Essentials/src/com/earth2me/essentials/Util.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/Util.java b/Essentials/src/com/earth2me/essentials/Util.java index 65077a7fc..c6df66165 100644 --- a/Essentials/src/com/earth2me/essentials/Util.java +++ b/Essentials/src/com/earth2me/essentials/Util.java @@ -22,11 +22,17 @@ public class Util } private final static Logger logger = Logger.getLogger("Minecraft"); private final static Pattern INVALIDFILECHARS = Pattern.compile("[^a-z0-9]"); - private final static Pattern INVALIDCHARS = Pattern.compile("[^\t\n\r\u0020-\u007E\u0085\u00A0-\uD7FF\uE000-\uFFFC]");; + private final static Pattern INVALIDCHARS = Pattern.compile("[^\t\n\r\u0020-\u007E\u0085\u00A0-\uD7FF\uE000-\uFFFC]"); + private static Map sanitizedName = new HashMap(); public static String sanitizeFileName(final String name) { - return INVALIDFILECHARS.matcher(name.toLowerCase(Locale.ENGLISH)).replaceAll("_"); + if (sanitizedName.containsKey(name)) { + return sanitizedName.get(name); + } + final String newName = INVALIDFILECHARS.matcher(name.toLowerCase(Locale.ENGLISH)).replaceAll("_"); + sanitizedName.put(name, newName); + return newName; } public static String sanitizeString(final String string)