Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1241)

Side by Side Diff: src/runtime/runtime-i18n.cc

Issue 2549773002: Internalize strings in-place (Closed)
Patch Set: forgot one Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 5
6 #ifdef V8_I18N_SUPPORT 6 #ifdef V8_I18N_SUPPORT
7 #include "src/runtime/runtime-utils.h" 7 #include "src/runtime/runtime-utils.h"
8 8
9 #include <memory> 9 #include <memory>
10 10
(...skipping 930 matching lines...) Expand 10 before | Expand all | Expand 10 after
941 namespace { 941 namespace {
942 MUST_USE_RESULT Object* LocaleConvertCase(Handle<String> s, Isolate* isolate, 942 MUST_USE_RESULT Object* LocaleConvertCase(Handle<String> s, Isolate* isolate,
943 bool is_to_upper, const char* lang) { 943 bool is_to_upper, const char* lang) {
944 auto case_converter = is_to_upper ? u_strToUpper : u_strToLower; 944 auto case_converter = is_to_upper ? u_strToUpper : u_strToLower;
945 int32_t src_length = s->length(); 945 int32_t src_length = s->length();
946 int32_t dest_length = src_length; 946 int32_t dest_length = src_length;
947 UErrorCode status; 947 UErrorCode status;
948 Handle<SeqTwoByteString> result; 948 Handle<SeqTwoByteString> result;
949 std::unique_ptr<uc16[]> sap; 949 std::unique_ptr<uc16[]> sap;
950 950
951 if (dest_length == 0) return isolate->heap()->empty_string();
952
951 // This is not a real loop. It'll be executed only once (no overflow) or 953 // This is not a real loop. It'll be executed only once (no overflow) or
952 // twice (overflow). 954 // twice (overflow).
953 for (int i = 0; i < 2; ++i) { 955 for (int i = 0; i < 2; ++i) {
954 // Case conversion can increase the string length (e.g. sharp-S => SS) so 956 // Case conversion can increase the string length (e.g. sharp-S => SS) so
955 // that we have to handle RangeError exceptions here. 957 // that we have to handle RangeError exceptions here.
956 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( 958 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
957 isolate, result, isolate->factory()->NewRawTwoByteString(dest_length)); 959 isolate, result, isolate->factory()->NewRawTwoByteString(dest_length));
958 DisallowHeapAllocation no_gc; 960 DisallowHeapAllocation no_gc;
959 String::FlatContent flat = s->GetFlatContent(); 961 String::FlatContent flat = s->GetFlatContent();
960 const UChar* src = GetUCharBufferFromFlat(flat, &sap, src_length); 962 const UChar* src = GetUCharBufferFromFlat(flat, &sap, src_length);
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
1152 DCHECK_EQ(args.length(), 1); 1154 DCHECK_EQ(args.length(), 1);
1153 CONVERT_ARG_HANDLE_CHECKED(String, s, 0); 1155 CONVERT_ARG_HANDLE_CHECKED(String, s, 0);
1154 1156
1155 // This function could be optimized for no-op cases the way lowercase 1157 // This function could be optimized for no-op cases the way lowercase
1156 // counterpart is, but in empirical testing, few actual calls to upper() 1158 // counterpart is, but in empirical testing, few actual calls to upper()
1157 // are no-ops. So, it wouldn't be worth the extra time for pre-scanning. 1159 // are no-ops. So, it wouldn't be worth the extra time for pre-scanning.
1158 1160
1159 int32_t length = s->length(); 1161 int32_t length = s->length();
1160 s = String::Flatten(s); 1162 s = String::Flatten(s);
1161 1163
1162 if (s->HasOnlyOneByteChars()) { 1164 if (s->HasOnlyOneByteChars() && length > 0) {
1163 Handle<SeqOneByteString> result; 1165 Handle<SeqOneByteString> result;
1164 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( 1166 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
1165 isolate, result, isolate->factory()->NewRawOneByteString(length)); 1167 isolate, result, isolate->factory()->NewRawOneByteString(length));
1166 1168
1167 int sharp_s_count; 1169 int sharp_s_count;
1168 bool is_result_single_byte; 1170 bool is_result_single_byte;
1169 { 1171 {
1170 DisallowHeapAllocation no_gc; 1172 DisallowHeapAllocation no_gc;
1171 String::FlatContent flat = s->GetFlatContent(); 1173 String::FlatContent flat = s->GetFlatContent();
1172 // If it was ok to slow down ASCII-only input slightly, ToUpperFastASCII 1174 // If it was ok to slow down ASCII-only input slightly, ToUpperFastASCII
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
1247 Handle<FixedArray> date_cache_version = 1249 Handle<FixedArray> date_cache_version =
1248 Handle<FixedArray>::cast(isolate->eternal_handles()->GetSingleton( 1250 Handle<FixedArray>::cast(isolate->eternal_handles()->GetSingleton(
1249 EternalHandles::DATE_CACHE_VERSION)); 1251 EternalHandles::DATE_CACHE_VERSION));
1250 return date_cache_version->get(0); 1252 return date_cache_version->get(0);
1251 } 1253 }
1252 1254
1253 } // namespace internal 1255 } // namespace internal
1254 } // namespace v8 1256 } // namespace v8
1255 1257
1256 #endif // V8_I18N_SUPPORT 1258 #endif // V8_I18N_SUPPORT
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698