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

Unified Diff: src/runtime/runtime-scopes.cc

Issue 1676883002: [runtime] Optimize and unify rest parameters. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: src/runtime/runtime-scopes.cc
diff --git a/src/runtime/runtime-scopes.cc b/src/runtime/runtime-scopes.cc
index 997e405bffa056efbe27d938928ca46892201417..0867f68b60eba2f098564ffb658787c19a29ced1 100644
--- a/src/runtime/runtime-scopes.cc
+++ b/src/runtime/runtime-scopes.cc
@@ -588,26 +588,6 @@ Handle<JSObject> NewStrictArguments(Isolate* isolate, Handle<JSFunction> callee,
}
-template <typename T>
-Handle<JSObject> NewRestArguments(Isolate* isolate, Handle<JSFunction> callee,
- T parameters, int argument_count,
- int start_index) {
- int num_elements = std::max(0, argument_count - start_index);
- Handle<JSObject> result = isolate->factory()->NewJSArray(
- FAST_ELEMENTS, num_elements, num_elements, Strength::WEAK,
- DONT_INITIALIZE_ARRAY_ELEMENTS);
- {
- DisallowHeapAllocation no_gc;
- FixedArray* elements = FixedArray::cast(result->elements());
- WriteBarrierMode mode = result->GetWriteBarrierMode(no_gc);
- for (int i = 0; i < num_elements; i++) {
- elements->set(i, parameters[i + start_index], mode);
- }
- }
- return result;
-}
-
-
class HandleArguments BASE_EMBEDDED {
public:
explicit HandleArguments(Handle<Object>* array) : array_(array) {}
@@ -658,19 +638,29 @@ RUNTIME_FUNCTION(Runtime_NewStrictArguments_Generic) {
}
-RUNTIME_FUNCTION(Runtime_NewRestArguments_Generic) {
+RUNTIME_FUNCTION(Runtime_NewRestParameter) {
HandleScope scope(isolate);
- DCHECK(args.length() == 2);
+ DCHECK_EQ(1, args.length());
CONVERT_ARG_HANDLE_CHECKED(JSFunction, callee, 0)
- CONVERT_SMI_ARG_CHECKED(start_index, 1);
+ int start_index = callee->shared()->internal_formal_parameter_count();
// This generic runtime function can also be used when the caller has been
// inlined, we use the slow but accurate {GetCallerArguments}.
int argument_count = 0;
base::SmartArrayPointer<Handle<Object>> arguments =
GetCallerArguments(isolate, &argument_count);
- HandleArguments argument_getter(arguments.get());
- return *NewRestArguments(isolate, callee, argument_getter, argument_count,
- start_index);
+ int num_elements = std::max(0, argument_count - start_index);
+ Handle<JSObject> result = isolate->factory()->NewJSArray(
+ FAST_ELEMENTS, num_elements, num_elements, Strength::WEAK,
+ DONT_INITIALIZE_ARRAY_ELEMENTS);
+ {
+ DisallowHeapAllocation no_gc;
+ FixedArray* elements = FixedArray::cast(result->elements());
+ WriteBarrierMode mode = result->GetWriteBarrierMode(no_gc);
+ for (int i = 0; i < num_elements; i++) {
+ elements->set(i, *arguments[i + start_index], mode);
+ }
+ }
+ return *result;
}
@@ -708,25 +698,6 @@ RUNTIME_FUNCTION(Runtime_NewStrictArguments) {
}
-RUNTIME_FUNCTION(Runtime_NewRestParam) {
- HandleScope scope(isolate);
- DCHECK(args.length() == 3);
- CONVERT_SMI_ARG_CHECKED(num_params, 0);
- Object** parameters = reinterpret_cast<Object**>(args[1]);
- CONVERT_SMI_ARG_CHECKED(rest_index, 2);
-#ifdef DEBUG
- // This runtime function does not materialize the correct arguments when the
- // caller has been inlined, better make sure we are not hitting that case.
- JavaScriptFrameIterator it(isolate);
- DCHECK(!it.frame()->HasInlinedFrames());
-#endif // DEBUG
- Handle<JSFunction> callee;
- ParameterArguments argument_getter(parameters);
- return *NewRestArguments(isolate, callee, argument_getter, num_params,
- rest_index);
-}
-
-
RUNTIME_FUNCTION(Runtime_NewClosure) {
HandleScope scope(isolate);
DCHECK_EQ(1, args.length());

Powered by Google App Engine
This is Rietveld 408576698