mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-09 07:22:11 +00:00
ICU-8476 optimize Normalizer2.normalize(): Do not construct a new String if the src is a String and is already normalized
X-SVN-Rev: 32562
This commit is contained in:
parent
b042e33ee1
commit
dd29ba28aa
1 changed files with 11 additions and 1 deletions
|
@ -204,7 +204,17 @@ public abstract class Normalizer2 {
|
|||
* @stable ICU 4.4
|
||||
*/
|
||||
public String normalize(CharSequence src) {
|
||||
return normalize(src, new StringBuilder()).toString();
|
||||
if(src instanceof String) {
|
||||
// Fastpath: Do not construct a new String if the src is a String
|
||||
// and is already normalized.
|
||||
int spanLength=spanQuickCheckYes(src);
|
||||
if(spanLength==src.length()) {
|
||||
return (String)src;
|
||||
}
|
||||
StringBuilder sb=new StringBuilder(src.length()).append(src, 0, spanLength);
|
||||
return normalizeSecondAndAppend(sb, src.subSequence(spanLength, src.length())).toString();
|
||||
}
|
||||
return normalize(src, new StringBuilder(src.length())).toString();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Reference in a new issue