From 9fe3734f15c822d6efc5d0e07d2a9dfd41632d7c Mon Sep 17 00:00:00 2001 From: Dean McNamee Date: Tue, 15 Jan 2013 19:35:52 +0100 Subject: [PATCH] TypedArrays: Improve dataview perf without endian param V8 seems to be particularly slow converting an undefined value to false in BooleanValue. Revert this when we upgrade to V8 3.17, or whenever the fix discussed in http://code.google.com/p/v8/issues/detail?id=2487 lands in V8. --- src/v8_typed_array.cc | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/v8_typed_array.cc b/src/v8_typed_array.cc index be9f480da..bccd1f68c 100644 --- a/src/v8_typed_array.cc +++ b/src/v8_typed_array.cc @@ -673,7 +673,10 @@ class DataView { return ThrowError("Wrong number of arguments."); unsigned int index = args[0]->Uint32Value(); - bool little_endian = args[1]->BooleanValue(); + // NOTE(deanm): args[1]->BooleanValue when the argument was not passed in + // gives us the right answer, but seems to be very slow. This seems to be + // the cost of calling BooleanValue() on undefined. + bool little_endian = args.Length() > 1 ? args[1]->BooleanValue() : false; // TODO(deanm): All of these things should be cacheable. int element_size = v8_typed_array::SizeOfArrayElementForType( args.This()->GetIndexedPropertiesExternalArrayDataType()); @@ -708,7 +711,10 @@ class DataView { return ThrowError("Wrong number of arguments."); unsigned int index = args[0]->Int32Value(); - bool little_endian = args[2]->BooleanValue(); + // NOTE(deanm): args[1]->BooleanValue when the argument was not passed in + // gives us the right answer, but seems to be very slow. This seems to be + // the cost of calling BooleanValue() on undefined. + bool little_endian = args.Length() > 1 ? args[1]->BooleanValue() : false; // TODO(deanm): All of these things should be cacheable. int element_size = v8_typed_array::SizeOfArrayElementForType( args.This()->GetIndexedPropertiesExternalArrayDataType());