From 677604fb8439a39e1f97343026c64928afcb121a Mon Sep 17 00:00:00 2001 From: XenoAmess Date: Sun, 14 Jun 2020 21:46:53 +0800 Subject: [PATCH] [LANG-1557] Change a Pattern to a static final field, for not letting it compile each time the function invoked. (#542) * Pattern_to_static_ * move the constants to head of the file. * Simplify private comment. Co-authored-by: Gary Gregory --- src/main/java/org/apache/commons/lang3/StringUtils.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/apache/commons/lang3/StringUtils.java b/src/main/java/org/apache/commons/lang3/StringUtils.java index 7dc928619..507cba02e 100644 --- a/src/main/java/org/apache/commons/lang3/StringUtils.java +++ b/src/main/java/org/apache/commons/lang3/StringUtils.java @@ -179,6 +179,11 @@ public class StringUtils { */ private static final int PAD_LIMIT = 8192; + /** + * Pattern used in {@link #stripAccents(String)}. + */ + private static final Pattern STRIP_ACCENTS_PATTERN = Pattern.compile("\\p{InCombiningDiacriticalMarks}+"); //$NON-NLS-1$ + // Abbreviating //----------------------------------------------------------------------- /** @@ -8215,11 +8220,10 @@ public class StringUtils { if (input == null) { return null; } - final Pattern pattern = Pattern.compile("\\p{InCombiningDiacriticalMarks}+"); //$NON-NLS-1$ final StringBuilder decomposed = new StringBuilder(Normalizer.normalize(input, Normalizer.Form.NFD)); convertRemainingAccentCharacters(decomposed); // Note that this doesn't correctly remove ligatures... - return pattern.matcher(decomposed).replaceAll(EMPTY); + return STRIP_ACCENTS_PATTERN.matcher(decomposed).replaceAll(EMPTY); } // StripAll