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

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

Issue 2493553002: Fix -Wsign-compare warnings in parser, scanner, regexp, runtime. (Closed)
Patch Set: Created 4 years, 1 month 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
« no previous file with comments | « src/regexp/regexp-parser.cc ('k') | src/runtime/runtime-regexp.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 1120 matching lines...) Expand 10 before | Expand all | Expand 10 after
1131 1131
1132 RUNTIME_FUNCTION(Runtime_StringToLowerCaseI18N) { 1132 RUNTIME_FUNCTION(Runtime_StringToLowerCaseI18N) {
1133 HandleScope scope(isolate); 1133 HandleScope scope(isolate);
1134 DCHECK_EQ(args.length(), 1); 1134 DCHECK_EQ(args.length(), 1);
1135 CONVERT_ARG_HANDLE_CHECKED(String, s, 0); 1135 CONVERT_ARG_HANDLE_CHECKED(String, s, 0);
1136 1136
1137 int length = s->length(); 1137 int length = s->length();
1138 s = String::Flatten(s); 1138 s = String::Flatten(s);
1139 // First scan the string for uppercase and non-ASCII characters: 1139 // First scan the string for uppercase and non-ASCII characters:
1140 if (s->HasOnlyOneByteChars()) { 1140 if (s->HasOnlyOneByteChars()) {
1141 unsigned first_index_to_lower = length; 1141 int first_index_to_lower = length;
1142 for (int index = 0; index < length; ++index) { 1142 for (int index = 0; index < length; ++index) {
1143 // Blink specializes this path for one-byte strings, so it 1143 // Blink specializes this path for one-byte strings, so it
1144 // does not need to do a generic get, but can do the equivalent 1144 // does not need to do a generic get, but can do the equivalent
1145 // of SeqOneByteStringGet. 1145 // of SeqOneByteStringGet.
1146 uint16_t ch = s->Get(index); 1146 uint16_t ch = s->Get(index);
1147 if (V8_UNLIKELY(IsASCIIUpper(ch) || ch & ~0x7F)) { 1147 if (V8_UNLIKELY(IsASCIIUpper(ch) || ch & ~0x7F)) {
1148 first_index_to_lower = index; 1148 first_index_to_lower = index;
1149 break; 1149 break;
1150 } 1150 }
1151 } 1151 }
1152 1152
1153 // Nothing to do if the string is all ASCII with no uppercase. 1153 // Nothing to do if the string is all ASCII with no uppercase.
1154 if (first_index_to_lower == length) return *s; 1154 if (first_index_to_lower == length) return *s;
1155 1155
1156 // We depend here on the invariant that the length of a Latin1 1156 // We depend here on the invariant that the length of a Latin1
1157 // string is invariant under ToLowerCase, and the result always 1157 // string is invariant under ToLowerCase, and the result always
1158 // fits in the Latin1 range in the *root locale*. It does not hold 1158 // fits in the Latin1 range in the *root locale*. It does not hold
1159 // for ToUpperCase even in the root locale. 1159 // for ToUpperCase even in the root locale.
1160 Handle<SeqOneByteString> result; 1160 Handle<SeqOneByteString> result;
1161 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( 1161 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
1162 isolate, result, isolate->factory()->NewRawOneByteString(length)); 1162 isolate, result, isolate->factory()->NewRawOneByteString(length));
1163 1163
1164 DisallowHeapAllocation no_gc; 1164 DisallowHeapAllocation no_gc;
1165 String::FlatContent flat = s->GetFlatContent(); 1165 String::FlatContent flat = s->GetFlatContent();
1166 if (flat.IsOneByte()) { 1166 if (flat.IsOneByte()) {
1167 const uint8_t* src = flat.ToOneByteVector().start(); 1167 const uint8_t* src = flat.ToOneByteVector().start();
1168 CopyChars(result->GetChars(), src, first_index_to_lower); 1168 CopyChars(result->GetChars(), src,
1169 static_cast<size_t>(first_index_to_lower));
1169 for (int index = first_index_to_lower; index < length; ++index) { 1170 for (int index = first_index_to_lower; index < length; ++index) {
1170 uint16_t ch = static_cast<uint16_t>(src[index]); 1171 uint16_t ch = static_cast<uint16_t>(src[index]);
1171 result->SeqOneByteStringSet(index, ToLatin1Lower(ch)); 1172 result->SeqOneByteStringSet(index, ToLatin1Lower(ch));
1172 } 1173 }
1173 } else { 1174 } else {
1174 const uint16_t* src = flat.ToUC16Vector().start(); 1175 const uint16_t* src = flat.ToUC16Vector().start();
1175 CopyChars(result->GetChars(), src, first_index_to_lower); 1176 CopyChars(result->GetChars(), src,
1177 static_cast<size_t>(first_index_to_lower));
1176 for (int index = first_index_to_lower; index < length; ++index) { 1178 for (int index = first_index_to_lower; index < length; ++index) {
1177 uint16_t ch = src[index]; 1179 uint16_t ch = src[index];
1178 result->SeqOneByteStringSet(index, ToLatin1Lower(ch)); 1180 result->SeqOneByteStringSet(index, ToLatin1Lower(ch));
1179 } 1181 }
1180 } 1182 }
1181 1183
1182 return *result; 1184 return *result;
1183 } 1185 }
1184 1186
1185 // Blink had an additional case here for ASCII 2-byte strings, but 1187 // Blink had an additional case here for ASCII 2-byte strings, but
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
1290 Handle<FixedArray> date_cache_version = 1292 Handle<FixedArray> date_cache_version =
1291 Handle<FixedArray>::cast(isolate->eternal_handles()->GetSingleton( 1293 Handle<FixedArray>::cast(isolate->eternal_handles()->GetSingleton(
1292 EternalHandles::DATE_CACHE_VERSION)); 1294 EternalHandles::DATE_CACHE_VERSION));
1293 return date_cache_version->get(0); 1295 return date_cache_version->get(0);
1294 } 1296 }
1295 1297
1296 } // namespace internal 1298 } // namespace internal
1297 } // namespace v8 1299 } // namespace v8
1298 1300
1299 #endif // V8_I18N_SUPPORT 1301 #endif // V8_I18N_SUPPORT
OLDNEW
« no previous file with comments | « src/regexp/regexp-parser.cc ('k') | src/runtime/runtime-regexp.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698