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

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

Issue 1775403008: Replace PushIfAbsent by a Stack object (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 9 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.h ('k') | src/runtime/runtime-strings.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/conversions-inl.h" 8 #include "src/conversions-inl.h"
9 #include "src/elements.h" 9 #include "src/elements.h"
10 #include "src/factory.h" 10 #include "src/factory.h"
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 RUNTIME_FUNCTION(Runtime_TransitionElementsKind) { 81 RUNTIME_FUNCTION(Runtime_TransitionElementsKind) {
82 HandleScope scope(isolate); 82 HandleScope scope(isolate);
83 RUNTIME_ASSERT(args.length() == 2); 83 RUNTIME_ASSERT(args.length() == 2);
84 CONVERT_ARG_HANDLE_CHECKED(JSArray, array, 0); 84 CONVERT_ARG_HANDLE_CHECKED(JSArray, array, 0);
85 CONVERT_ARG_HANDLE_CHECKED(Map, map, 1); 85 CONVERT_ARG_HANDLE_CHECKED(Map, map, 1);
86 JSObject::TransitionElementsKind(array, map->elements_kind()); 86 JSObject::TransitionElementsKind(array, map->elements_kind());
87 return *array; 87 return *array;
88 } 88 }
89 89
90 90
91 // Push an object unto an array of objects if it is not already in the
92 // array. Returns true if the element was pushed on the stack and
93 // false otherwise.
94 RUNTIME_FUNCTION(Runtime_PushIfAbsent) {
95 HandleScope scope(isolate);
96 DCHECK(args.length() == 2);
97 CONVERT_ARG_HANDLE_CHECKED(JSArray, array, 0);
98 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, element, 1);
99 RUNTIME_ASSERT(array->HasFastSmiOrObjectElements());
100 int length = Smi::cast(array->length())->value();
101 FixedArray* elements = FixedArray::cast(array->elements());
102 for (int i = 0; i < length; i++) {
103 if (elements->get(i) == *element) return isolate->heap()->false_value();
104 }
105
106 // Strict not needed. Used for cycle detection in Array join implementation.
107 RETURN_FAILURE_ON_EXCEPTION(
108 isolate, JSObject::AddDataElement(array, length, element, NONE));
109 JSObject::ValidateElements(array);
110 return isolate->heap()->true_value();
111 }
112
113
114 // Moves all own elements of an object, that are below a limit, to positions 91 // Moves all own elements of an object, that are below a limit, to positions
115 // starting at zero. All undefined values are placed after non-undefined values, 92 // starting at zero. All undefined values are placed after non-undefined values,
116 // and are followed by non-existing element. Does not change the length 93 // and are followed by non-existing element. Does not change the length
117 // property. 94 // property.
118 // Returns the number of non-undefined elements collected. 95 // Returns the number of non-undefined elements collected.
119 // Returns -1 if hole removal is not supported by this method. 96 // Returns -1 if hole removal is not supported by this method.
120 RUNTIME_FUNCTION(Runtime_RemoveArrayHoles) { 97 RUNTIME_FUNCTION(Runtime_RemoveArrayHoles) {
121 HandleScope scope(isolate); 98 HandleScope scope(isolate);
122 DCHECK(args.length() == 2); 99 DCHECK(args.length() == 2);
123 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, object, 0); 100 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, object, 0);
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after
497 CONVERT_ARG_HANDLE_CHECKED(Object, original_array, 0); 474 CONVERT_ARG_HANDLE_CHECKED(Object, original_array, 0);
498 Handle<Object> constructor; 475 Handle<Object> constructor;
499 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( 476 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
500 isolate, constructor, 477 isolate, constructor,
501 Object::ArraySpeciesConstructor(isolate, original_array)); 478 Object::ArraySpeciesConstructor(isolate, original_array));
502 return *constructor; 479 return *constructor;
503 } 480 }
504 481
505 } // namespace internal 482 } // namespace internal
506 } // namespace v8 483 } // namespace v8
OLDNEW
« no previous file with comments | « src/runtime/runtime.h ('k') | src/runtime/runtime-strings.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698