Index: src/runtime/runtime-i18n.cc |
diff --git a/src/runtime/runtime-i18n.cc b/src/runtime/runtime-i18n.cc |
index 8f05809c50c7c87007fb27d2b18d93b6299edd60..bafd9ee3411108fec897363924088b76fed0dc82 100644 |
--- a/src/runtime/runtime-i18n.cc |
+++ b/src/runtime/runtime-i18n.cc |
@@ -753,6 +753,7 @@ RUNTIME_FUNCTION(Runtime_BreakIteratorBreakType) { |
} |
namespace { |
+#if 0 |
inline void LocaleConvertCaseHelper(icu::UnicodeString* s, bool is_to_upper, |
const icu::Locale& locale) { |
if (is_to_upper) |
@@ -770,6 +771,7 @@ void ConvertCaseWithTransliterator(icu::UnicodeString* input, |
if (U_FAILURE(status)) return; |
translit->transliterate(*input); |
} |
+#endif |
MUST_USE_RESULT Object* LocaleConvertCase(Handle<String> s, Isolate* isolate, |
bool is_to_upper, int locale_id) { |
@@ -779,42 +781,53 @@ MUST_USE_RESULT Object* LocaleConvertCase(Handle<String> s, Isolate* isolate, |
RUNTIME_ASSERT(locale_id >= -1 && |
locale_id < static_cast<int>(arraysize(conversion_locales))); |
int32_t length = s->length(); |
- icu::UnicodeString converted; |
+ base::SmartArrayPointer<uc16> sap; |
+ const UChar* src; |
+ Handle<SeqTwoByteString> result = |
+ isolate->factory()->NewRawTwoByteString(length).ToHandleChecked(); |
{ |
DisallowHeapAllocation no_gc; |
DCHECK(s->IsFlat()); |
String::FlatContent flat = s->GetFlatContent(); |
- |
- const UChar* src; |
if (flat.IsOneByte()) { |
- base::SmartArrayPointer<uc16> sap = s->ToWideCString(); |
+ sap = s->ToWideCString(); |
src = reinterpret_cast<const UChar*>(sap.get()); |
- converted = icu::UnicodeString(src, length); |
} else { |
src = reinterpret_cast<const UChar*>(flat.ToUC16Vector().start()); |
- converted = icu::UnicodeString(src, length); |
} |
- } |
- if (locale_id == -1) { |
- LocaleConvertCaseHelper(&converted, is_to_upper, icu::Locale::getRoot()); |
- } else if (V8_UNLIKELY(locale_id == 1 && is_to_upper)) { |
- // TODO(jshin): Once http://bugs.icu-project.org/trac/ticket/10582 is |
- // fixed, remove this special-casing for uppercasing in Greek(el) locale. |
- // This is ~500 times slower than using the case conversion API. |
- ConvertCaseWithTransliterator(&converted, "el-Upper"); |
- } else { |
- LocaleConvertCaseHelper(&converted, is_to_upper, |
- icu::Locale(conversion_locales[locale_id])); |
+ if (V8_LIKELY(locale_id != 1 || !is_to_upper)) { |
+ typedef int32_t (*case_conversion_fn)( |
+ UChar * dest, int32_t destCapacity, const UChar* src, |
+ int32_t srcLength, const char* locale, UErrorCode* pErrorCode); |
+ case_conversion_fn fn = is_to_upper ? u_strToUpper : u_strToLower; |
+ |
+ int32_t target_length = length; |
+ const char* locale = locale_id == -1 ? "" : conversion_locales[locale_id]; |
+ UErrorCode error; |
+ do { |
+ error = U_ZERO_ERROR; |
+ target_length = fn(reinterpret_cast<UChar*>(result->GetChars()), |
+ target_length, src, length, locale, &error); |
+ result->synchronized_set_length(target_length); |
jungshik at Google
2016/04/14 07:46:31
|set_length| is called over |result| ( which is Se
|
+ } while (error == U_BUFFER_OVERFLOW_ERROR); |
+ return U_SUCCESS(error) ? *result : *s; |
+ } |
} |
- Handle<String> result; |
+ return *s; |
+#if 0 |
+ // For Greek Uppercasing |
+ icu::UnicodeString converted(false, src, length); |
+ ConvertCaseWithTransliterator(&converted, "el-Upper"); |
+ Handle<String> greek_result; |
ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
- isolate, result, |
+ isolate, greek_result, |
isolate->factory()->NewStringFromTwoByte(Vector<const uint16_t>( |
reinterpret_cast<const uint16_t*>(converted.getBuffer()), |
converted.length()))); |
- return *result; |
+ return *greek_result; |
+#endif |
} |
inline bool IsASCIIUpper(uint16_t ch) { return ch >= 'A' && ch <= 'Z'; } |