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

Unified Diff: src/runtime.cc

Issue 397593008: Keep new arrays allocated with 'new Array(N)' in fast mode (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fix slow test Created 6 years, 5 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
« no previous file with comments | « src/runtime.h ('k') | test/fuzz-natives/base.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/runtime.cc
diff --git a/src/runtime.cc b/src/runtime.cc
index 61e1069d0db35242be66e6f2031c9b098760b064..3d6d3e6cae19187c522a3d497ec4d33a7cf406f1 100644
--- a/src/runtime.cc
+++ b/src/runtime.cc
@@ -10576,7 +10576,30 @@ RUNTIME_FUNCTION(Runtime_GetArrayKeys) {
ASSERT(args.length() == 2);
CONVERT_ARG_HANDLE_CHECKED(JSObject, array, 0);
CONVERT_NUMBER_CHECKED(uint32_t, length, Uint32, args[1]);
- if (array->elements()->IsDictionary()) {
+
+ ElementsKind kind = array->GetElementsKind();
+ bool estimate_keys_as_length = IsFastPackedElementsKind(kind);
+ if (IsHoleyElementsKind(kind)) {
+ ElementsAccessor* accessor = array->GetElementsAccessor();
+ // If more than 10% of the array is holes, then calculate the key set, it's
+ // much faster than using the runtime to walk the prototype chain in the
+ // hole case.
+ int holes = 0;
+ int length = array->elements()->length();
+ for (int i = 0; i < length; ++i) {
+ if (!accessor->HasElement(array, array, i)) {
+ ++holes;
+ }
+ }
+ estimate_keys_as_length = holes < static_cast<int>(length / 10);
+ }
+
+ if (estimate_keys_as_length) {
+ RUNTIME_ASSERT(array->HasFastSmiOrObjectElements() ||
+ array->HasFastDoubleElements());
+ uint32_t actual_length = static_cast<uint32_t>(array->elements()->length());
+ return *isolate->factory()->NewNumberFromUint(Min(actual_length, length));
+ } else {
Handle<FixedArray> keys = isolate->factory()->empty_fixed_array();
for (PrototypeIterator iter(isolate, array,
PrototypeIterator::START_AT_RECEIVER);
@@ -10603,11 +10626,6 @@ RUNTIME_FUNCTION(Runtime_GetArrayKeys) {
if (NumberToUint32(keys->get(i)) >= length) keys->set_undefined(i);
}
return *isolate->factory()->NewJSArrayWithElements(keys);
- } else {
- RUNTIME_ASSERT(array->HasFastSmiOrObjectElements() ||
- array->HasFastDoubleElements());
- uint32_t actual_length = static_cast<uint32_t>(array->elements()->length());
- return *isolate->factory()->NewNumberFromUint(Min(actual_length, length));
}
}
@@ -14931,6 +14949,15 @@ RUNTIME_FUNCTION(Runtime_InternalArrayConstructor) {
}
+RUNTIME_FUNCTION(Runtime_NormalizeElements) {
+ HandleScope scope(isolate);
+ ASSERT(args.length() == 1);
+ CONVERT_ARG_HANDLE_CHECKED(JSObject, array, 0);
+ JSObject::NormalizeElements(array);
+ return *array;
+}
+
+
RUNTIME_FUNCTION(Runtime_MaxSmi) {
ASSERT(args.length() == 0);
return Smi::FromInt(Smi::kMaxValue);
« no previous file with comments | « src/runtime.h ('k') | test/fuzz-natives/base.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698