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

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

Issue 2381843002: Add Smi::Zero and replace all Smi::FromInt(0) calls (Closed)
Patch Set: Mark Smi::kZero as V8_EXPORT_PRIVATE Created 4 years, 2 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
« no previous file with comments | « src/runtime/runtime-regexp.cc ('k') | src/runtime/runtime-typedarray.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 #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/regexp/jsregexp-inl.h" 8 #include "src/regexp/jsregexp-inl.h"
9 #include "src/string-builder.h" 9 #include "src/string-builder.h"
10 #include "src/string-search.h" 10 #include "src/string-search.h"
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 case ComparisonResult::kLessThan: 249 case ComparisonResult::kLessThan:
250 return Smi::FromInt(LESS); 250 return Smi::FromInt(LESS);
251 case ComparisonResult::kEqual: 251 case ComparisonResult::kEqual:
252 return Smi::FromInt(EQUAL); 252 return Smi::FromInt(EQUAL);
253 case ComparisonResult::kGreaterThan: 253 case ComparisonResult::kGreaterThan:
254 return Smi::FromInt(GREATER); 254 return Smi::FromInt(GREATER);
255 case ComparisonResult::kUndefined: 255 case ComparisonResult::kUndefined:
256 break; 256 break;
257 } 257 }
258 UNREACHABLE(); 258 UNREACHABLE();
259 return Smi::FromInt(0); 259 return Smi::kZero;
260 } 260 }
261 261
262 262
263 RUNTIME_FUNCTION(Runtime_StringBuilderConcat) { 263 RUNTIME_FUNCTION(Runtime_StringBuilderConcat) {
264 HandleScope scope(isolate); 264 HandleScope scope(isolate);
265 DCHECK(args.length() == 3); 265 DCHECK(args.length() == 3);
266 CONVERT_ARG_HANDLE_CHECKED(JSArray, array, 0); 266 CONVERT_ARG_HANDLE_CHECKED(JSArray, array, 0);
267 int32_t array_length; 267 int32_t array_length;
268 if (!args[1]->ToInt32(&array_length)) { 268 if (!args[1]->ToInt32(&array_length)) {
269 THROW_NEW_ERROR_RETURN_FAILURE(isolate, NewInvalidStringLengthError()); 269 THROW_NEW_ERROR_RETURN_FAILURE(isolate, NewInvalidStringLengthError());
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
566 FixedArray* one_byte_cache = heap->single_character_string_cache(); 566 FixedArray* one_byte_cache = heap->single_character_string_cache();
567 Object* undefined = heap->undefined_value(); 567 Object* undefined = heap->undefined_value();
568 int i; 568 int i;
569 WriteBarrierMode mode = elements->GetWriteBarrierMode(no_gc); 569 WriteBarrierMode mode = elements->GetWriteBarrierMode(no_gc);
570 for (i = 0; i < length; ++i) { 570 for (i = 0; i < length; ++i) {
571 Object* value = one_byte_cache->get(chars[i]); 571 Object* value = one_byte_cache->get(chars[i]);
572 if (value == undefined) break; 572 if (value == undefined) break;
573 elements->set(i, value, mode); 573 elements->set(i, value, mode);
574 } 574 }
575 if (i < length) { 575 if (i < length) {
576 DCHECK(Smi::FromInt(0) == 0); 576 DCHECK(Smi::kZero == 0);
577 memset(elements->data_start() + i, 0, kPointerSize * (length - i)); 577 memset(elements->data_start() + i, 0, kPointerSize * (length - i));
578 } 578 }
579 #ifdef DEBUG 579 #ifdef DEBUG
580 for (int j = 0; j < length; ++j) { 580 for (int j = 0; j < length; ++j) {
581 Object* element = elements->get(j); 581 Object* element = elements->get(j);
582 DCHECK(element == Smi::FromInt(0) || 582 DCHECK(element == Smi::kZero ||
583 (element->IsString() && String::cast(element)->LooksValid())); 583 (element->IsString() && String::cast(element)->LooksValid()));
584 } 584 }
585 #endif 585 #endif
586 return i; 586 return i;
587 } 587 }
588 588
589 589
590 // Converts a String to JSArray. 590 // Converts a String to JSArray.
591 // For example, "foo" => ["f", "o", "o"]. 591 // For example, "foo" => ["f", "o", "o"].
592 RUNTIME_FUNCTION(Runtime_StringToArray) { 592 RUNTIME_FUNCTION(Runtime_StringToArray) {
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
935 switch (String::Compare(x, y)) { 935 switch (String::Compare(x, y)) {
936 case ComparisonResult::kLessThan: 936 case ComparisonResult::kLessThan:
937 return isolate->heap()->true_value(); 937 return isolate->heap()->true_value();
938 case ComparisonResult::kEqual: 938 case ComparisonResult::kEqual:
939 case ComparisonResult::kGreaterThan: 939 case ComparisonResult::kGreaterThan:
940 return isolate->heap()->false_value(); 940 return isolate->heap()->false_value();
941 case ComparisonResult::kUndefined: 941 case ComparisonResult::kUndefined:
942 break; 942 break;
943 } 943 }
944 UNREACHABLE(); 944 UNREACHABLE();
945 return Smi::FromInt(0); 945 return Smi::kZero;
946 } 946 }
947 947
948 RUNTIME_FUNCTION(Runtime_StringLessThanOrEqual) { 948 RUNTIME_FUNCTION(Runtime_StringLessThanOrEqual) {
949 HandleScope handle_scope(isolate); 949 HandleScope handle_scope(isolate);
950 DCHECK_EQ(2, args.length()); 950 DCHECK_EQ(2, args.length());
951 CONVERT_ARG_HANDLE_CHECKED(String, x, 0); 951 CONVERT_ARG_HANDLE_CHECKED(String, x, 0);
952 CONVERT_ARG_HANDLE_CHECKED(String, y, 1); 952 CONVERT_ARG_HANDLE_CHECKED(String, y, 1);
953 switch (String::Compare(x, y)) { 953 switch (String::Compare(x, y)) {
954 case ComparisonResult::kEqual: 954 case ComparisonResult::kEqual:
955 case ComparisonResult::kLessThan: 955 case ComparisonResult::kLessThan:
956 return isolate->heap()->true_value(); 956 return isolate->heap()->true_value();
957 case ComparisonResult::kGreaterThan: 957 case ComparisonResult::kGreaterThan:
958 return isolate->heap()->false_value(); 958 return isolate->heap()->false_value();
959 case ComparisonResult::kUndefined: 959 case ComparisonResult::kUndefined:
960 break; 960 break;
961 } 961 }
962 UNREACHABLE(); 962 UNREACHABLE();
963 return Smi::FromInt(0); 963 return Smi::kZero;
964 } 964 }
965 965
966 RUNTIME_FUNCTION(Runtime_StringGreaterThan) { 966 RUNTIME_FUNCTION(Runtime_StringGreaterThan) {
967 HandleScope handle_scope(isolate); 967 HandleScope handle_scope(isolate);
968 DCHECK_EQ(2, args.length()); 968 DCHECK_EQ(2, args.length());
969 CONVERT_ARG_HANDLE_CHECKED(String, x, 0); 969 CONVERT_ARG_HANDLE_CHECKED(String, x, 0);
970 CONVERT_ARG_HANDLE_CHECKED(String, y, 1); 970 CONVERT_ARG_HANDLE_CHECKED(String, y, 1);
971 switch (String::Compare(x, y)) { 971 switch (String::Compare(x, y)) {
972 case ComparisonResult::kGreaterThan: 972 case ComparisonResult::kGreaterThan:
973 return isolate->heap()->true_value(); 973 return isolate->heap()->true_value();
974 case ComparisonResult::kEqual: 974 case ComparisonResult::kEqual:
975 case ComparisonResult::kLessThan: 975 case ComparisonResult::kLessThan:
976 return isolate->heap()->false_value(); 976 return isolate->heap()->false_value();
977 case ComparisonResult::kUndefined: 977 case ComparisonResult::kUndefined:
978 break; 978 break;
979 } 979 }
980 UNREACHABLE(); 980 UNREACHABLE();
981 return Smi::FromInt(0); 981 return Smi::kZero;
982 } 982 }
983 983
984 RUNTIME_FUNCTION(Runtime_StringGreaterThanOrEqual) { 984 RUNTIME_FUNCTION(Runtime_StringGreaterThanOrEqual) {
985 HandleScope handle_scope(isolate); 985 HandleScope handle_scope(isolate);
986 DCHECK_EQ(2, args.length()); 986 DCHECK_EQ(2, args.length());
987 CONVERT_ARG_HANDLE_CHECKED(String, x, 0); 987 CONVERT_ARG_HANDLE_CHECKED(String, x, 0);
988 CONVERT_ARG_HANDLE_CHECKED(String, y, 1); 988 CONVERT_ARG_HANDLE_CHECKED(String, y, 1);
989 switch (String::Compare(x, y)) { 989 switch (String::Compare(x, y)) {
990 case ComparisonResult::kEqual: 990 case ComparisonResult::kEqual:
991 case ComparisonResult::kGreaterThan: 991 case ComparisonResult::kGreaterThan:
992 return isolate->heap()->true_value(); 992 return isolate->heap()->true_value();
993 case ComparisonResult::kLessThan: 993 case ComparisonResult::kLessThan:
994 return isolate->heap()->false_value(); 994 return isolate->heap()->false_value();
995 case ComparisonResult::kUndefined: 995 case ComparisonResult::kUndefined:
996 break; 996 break;
997 } 997 }
998 UNREACHABLE(); 998 UNREACHABLE();
999 return Smi::FromInt(0); 999 return Smi::kZero;
1000 } 1000 }
1001 1001
1002 RUNTIME_FUNCTION(Runtime_StringEqual) { 1002 RUNTIME_FUNCTION(Runtime_StringEqual) {
1003 HandleScope handle_scope(isolate); 1003 HandleScope handle_scope(isolate);
1004 DCHECK_EQ(2, args.length()); 1004 DCHECK_EQ(2, args.length());
1005 CONVERT_ARG_HANDLE_CHECKED(String, x, 0); 1005 CONVERT_ARG_HANDLE_CHECKED(String, x, 0);
1006 CONVERT_ARG_HANDLE_CHECKED(String, y, 1); 1006 CONVERT_ARG_HANDLE_CHECKED(String, y, 1);
1007 return isolate->heap()->ToBoolean(String::Equals(x, y)); 1007 return isolate->heap()->ToBoolean(String::Equals(x, y));
1008 } 1008 }
1009 1009
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1046 SealHandleScope shs(isolate); 1046 SealHandleScope shs(isolate);
1047 DCHECK(args.length() == 2); 1047 DCHECK(args.length() == 2);
1048 if (!args[0]->IsString()) return isolate->heap()->undefined_value(); 1048 if (!args[0]->IsString()) return isolate->heap()->undefined_value();
1049 if (!args[1]->IsNumber()) return isolate->heap()->undefined_value(); 1049 if (!args[1]->IsNumber()) return isolate->heap()->undefined_value();
1050 if (std::isinf(args.number_at(1))) return isolate->heap()->nan_value(); 1050 if (std::isinf(args.number_at(1))) return isolate->heap()->nan_value();
1051 return __RT_impl_Runtime_StringCharCodeAtRT(args, isolate); 1051 return __RT_impl_Runtime_StringCharCodeAtRT(args, isolate);
1052 } 1052 }
1053 1053
1054 } // namespace internal 1054 } // namespace internal
1055 } // namespace v8 1055 } // namespace v8
OLDNEW
« no previous file with comments | « src/runtime/runtime-regexp.cc ('k') | src/runtime/runtime-typedarray.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698