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

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

Issue 1350113002: [runtime] Replace COMPARE/COMPARE_STRONG with proper Object::Compare. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 3 months 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 #include "src/runtime/runtime-utils.h" 5 #include "src/runtime/runtime-utils.h"
6 6
7 #include "src/arguments.h" 7 #include "src/arguments.h"
8 #include "src/conversions-inl.h" 8 #include "src/conversions-inl.h"
9 #include "src/isolate-inl.h" 9 #include "src/isolate-inl.h"
10 #include "src/regexp/jsregexp-inl.h" 10 #include "src/regexp/jsregexp-inl.h"
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 CONVERT_NUMBER_CHECKED(uint32_t, code, Uint32, args[0]); 412 CONVERT_NUMBER_CHECKED(uint32_t, code, Uint32, args[0]);
413 code &= 0xffff; 413 code &= 0xffff;
414 return *isolate->factory()->LookupSingleCharacterStringFromCode(code); 414 return *isolate->factory()->LookupSingleCharacterStringFromCode(code);
415 } 415 }
416 return isolate->heap()->empty_string(); 416 return isolate->heap()->empty_string();
417 } 417 }
418 418
419 419
420 RUNTIME_FUNCTION(Runtime_StringCompare) { 420 RUNTIME_FUNCTION(Runtime_StringCompare) {
421 HandleScope handle_scope(isolate); 421 HandleScope handle_scope(isolate);
422 DCHECK(args.length() == 2); 422 DCHECK_EQ(2, args.length());
423
424 CONVERT_ARG_HANDLE_CHECKED(String, x, 0); 423 CONVERT_ARG_HANDLE_CHECKED(String, x, 0);
425 CONVERT_ARG_HANDLE_CHECKED(String, y, 1); 424 CONVERT_ARG_HANDLE_CHECKED(String, y, 1);
426
427 isolate->counters()->string_compare_runtime()->Increment(); 425 isolate->counters()->string_compare_runtime()->Increment();
428 426 switch (String::Compare(x, y)) {
429 // A few fast case tests before we flatten. 427 case ComparisonResult::kLessThan:
430 if (x.is_identical_to(y)) return Smi::FromInt(EQUAL); 428 return Smi::FromInt(LESS);
431 if (y->length() == 0) { 429 case ComparisonResult::kEqual:
432 if (x->length() == 0) return Smi::FromInt(EQUAL); 430 return Smi::FromInt(EQUAL);
433 return Smi::FromInt(GREATER); 431 case ComparisonResult::kGreaterThan:
434 } else if (x->length() == 0) { 432 return Smi::FromInt(GREATER);
435 return Smi::FromInt(LESS); 433 case ComparisonResult::kUndefined:
434 break;
436 } 435 }
437 436 UNREACHABLE();
438 int d = x->Get(0) - y->Get(0); 437 return Smi::FromInt(0);
439 if (d < 0)
440 return Smi::FromInt(LESS);
441 else if (d > 0)
442 return Smi::FromInt(GREATER);
443
444 // Slow case.
445 x = String::Flatten(x);
446 y = String::Flatten(y);
447
448 DisallowHeapAllocation no_gc;
449 Object* equal_prefix_result = Smi::FromInt(EQUAL);
450 int prefix_length = x->length();
451 if (y->length() < prefix_length) {
452 prefix_length = y->length();
453 equal_prefix_result = Smi::FromInt(GREATER);
454 } else if (y->length() > prefix_length) {
455 equal_prefix_result = Smi::FromInt(LESS);
456 }
457 int r;
458 String::FlatContent x_content = x->GetFlatContent();
459 String::FlatContent y_content = y->GetFlatContent();
460 if (x_content.IsOneByte()) {
461 Vector<const uint8_t> x_chars = x_content.ToOneByteVector();
462 if (y_content.IsOneByte()) {
463 Vector<const uint8_t> y_chars = y_content.ToOneByteVector();
464 r = CompareChars(x_chars.start(), y_chars.start(), prefix_length);
465 } else {
466 Vector<const uc16> y_chars = y_content.ToUC16Vector();
467 r = CompareChars(x_chars.start(), y_chars.start(), prefix_length);
468 }
469 } else {
470 Vector<const uc16> x_chars = x_content.ToUC16Vector();
471 if (y_content.IsOneByte()) {
472 Vector<const uint8_t> y_chars = y_content.ToOneByteVector();
473 r = CompareChars(x_chars.start(), y_chars.start(), prefix_length);
474 } else {
475 Vector<const uc16> y_chars = y_content.ToUC16Vector();
476 r = CompareChars(x_chars.start(), y_chars.start(), prefix_length);
477 }
478 }
479 Object* result;
480 if (r == 0) {
481 result = equal_prefix_result;
482 } else {
483 result = (r < 0) ? Smi::FromInt(LESS) : Smi::FromInt(GREATER);
484 }
485 return result;
486 } 438 }
487 439
488 440
489 RUNTIME_FUNCTION(Runtime_StringBuilderConcat) { 441 RUNTIME_FUNCTION(Runtime_StringBuilderConcat) {
490 HandleScope scope(isolate); 442 HandleScope scope(isolate);
491 DCHECK(args.length() == 3); 443 DCHECK(args.length() == 3);
492 CONVERT_ARG_HANDLE_CHECKED(JSArray, array, 0); 444 CONVERT_ARG_HANDLE_CHECKED(JSArray, array, 0);
493 int32_t array_length; 445 int32_t array_length;
494 if (!args[1]->ToInt32(&array_length)) { 446 if (!args[1]->ToInt32(&array_length)) {
495 THROW_NEW_ERROR_RETURN_FAILURE(isolate, NewInvalidStringLengthError()); 447 THROW_NEW_ERROR_RETURN_FAILURE(isolate, NewInvalidStringLengthError());
(...skipping 827 matching lines...) Expand 10 before | Expand all | Expand 10 after
1323 1275
1324 1276
1325 RUNTIME_FUNCTION(Runtime_StringGetLength) { 1277 RUNTIME_FUNCTION(Runtime_StringGetLength) {
1326 HandleScope scope(isolate); 1278 HandleScope scope(isolate);
1327 DCHECK(args.length() == 1); 1279 DCHECK(args.length() == 1);
1328 CONVERT_ARG_HANDLE_CHECKED(String, s, 0); 1280 CONVERT_ARG_HANDLE_CHECKED(String, s, 0);
1329 return Smi::FromInt(s->length()); 1281 return Smi::FromInt(s->length());
1330 } 1282 }
1331 } // namespace internal 1283 } // namespace internal
1332 } // namespace v8 1284 } // namespace v8
OLDNEW
« src/objects.cc ('K') | « src/runtime/runtime-object.cc ('k') | src/x64/code-stubs-x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698