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

Side by Side Diff: src/runtime.cc

Issue 249593002: Fix C++ type of Factory::NewFixedDoubleArray. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Added some comments Created 6 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « src/factory.cc ('k') | test/mjsunit/regress/regress-empty-fixed-double-array.js » ('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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 10466 matching lines...) Expand 10 before | Expand all | Expand 10 after
10477 } else { 10477 } else {
10478 estimate_nof_elements += element_estimate; 10478 estimate_nof_elements += element_estimate;
10479 } 10479 }
10480 } 10480 }
10481 10481
10482 // If estimated number of elements is more than half of length, a 10482 // If estimated number of elements is more than half of length, a
10483 // fixed array (fast case) is more time and space-efficient than a 10483 // fixed array (fast case) is more time and space-efficient than a
10484 // dictionary. 10484 // dictionary.
10485 bool fast_case = (estimate_nof_elements * 2) >= estimate_result_length; 10485 bool fast_case = (estimate_nof_elements * 2) >= estimate_result_length;
10486 10486
10487 Handle<FixedArray> storage; 10487 if (fast_case && kind == FAST_DOUBLE_ELEMENTS) {
10488 if (fast_case) { 10488 Handle<FixedArrayBase> storage =
10489 if (kind == FAST_DOUBLE_ELEMENTS) { 10489 isolate->factory()->NewFixedDoubleArray(estimate_result_length);
10490 int j = 0;
10491 if (estimate_result_length > 0) {
10490 Handle<FixedDoubleArray> double_storage = 10492 Handle<FixedDoubleArray> double_storage =
10491 isolate->factory()->NewFixedDoubleArray(estimate_result_length); 10493 Handle<FixedDoubleArray>::cast(storage);
10492 int j = 0;
10493 bool failure = false; 10494 bool failure = false;
10494 for (int i = 0; i < argument_count; i++) { 10495 for (int i = 0; i < argument_count; i++) {
10495 Handle<Object> obj(elements->get(i), isolate); 10496 Handle<Object> obj(elements->get(i), isolate);
10496 if (obj->IsSmi()) { 10497 if (obj->IsSmi()) {
10497 double_storage->set(j, Smi::cast(*obj)->value()); 10498 double_storage->set(j, Smi::cast(*obj)->value());
10498 j++; 10499 j++;
10499 } else if (obj->IsNumber()) { 10500 } else if (obj->IsNumber()) {
10500 double_storage->set(j, obj->Number()); 10501 double_storage->set(j, obj->Number());
10501 j++; 10502 j++;
10502 } else { 10503 } else {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
10538 } 10539 }
10539 case FAST_HOLEY_ELEMENTS: 10540 case FAST_HOLEY_ELEMENTS:
10540 ASSERT_EQ(0, length); 10541 ASSERT_EQ(0, length);
10541 break; 10542 break;
10542 default: 10543 default:
10543 UNREACHABLE(); 10544 UNREACHABLE();
10544 } 10545 }
10545 } 10546 }
10546 if (failure) break; 10547 if (failure) break;
10547 } 10548 }
10548 Handle<JSArray> array = isolate->factory()->NewJSArray(0);
10549 Smi* length = Smi::FromInt(j);
10550 Handle<Map> map;
10551 map = JSObject::GetElementsTransitionMap(array, kind);
10552 array->set_map(*map);
10553 array->set_length(length);
10554 array->set_elements(*double_storage);
10555 return *array;
10556 } 10549 }
10550 Handle<JSArray> array = isolate->factory()->NewJSArray(0);
10551 Smi* length = Smi::FromInt(j);
10552 Handle<Map> map;
10553 map = JSObject::GetElementsTransitionMap(array, kind);
10554 array->set_map(*map);
10555 array->set_length(length);
10556 array->set_elements(*storage);
10557 return *array;
10558 }
10559
10560 Handle<FixedArray> storage;
10561 if (fast_case) {
10557 // The backing storage array must have non-existing elements to preserve 10562 // The backing storage array must have non-existing elements to preserve
10558 // holes across concat operations. 10563 // holes across concat operations.
10559 storage = isolate->factory()->NewFixedArrayWithHoles( 10564 storage = isolate->factory()->NewFixedArrayWithHoles(
10560 estimate_result_length); 10565 estimate_result_length);
10561 } else { 10566 } else {
10562 // TODO(126): move 25% pre-allocation logic into Dictionary::Allocate 10567 // TODO(126): move 25% pre-allocation logic into Dictionary::Allocate
10563 uint32_t at_least_space_for = estimate_nof_elements + 10568 uint32_t at_least_space_for = estimate_nof_elements +
10564 (estimate_nof_elements >> 2); 10569 (estimate_nof_elements >> 2);
10565 storage = Handle<FixedArray>::cast( 10570 storage = Handle<FixedArray>::cast(
10566 isolate->factory()->NewSeededNumberDictionary(at_least_space_for)); 10571 isolate->factory()->NewSeededNumberDictionary(at_least_space_for));
(...skipping 4552 matching lines...) Expand 10 before | Expand all | Expand 10 after
15119 } 15124 }
15120 return NULL; 15125 return NULL;
15121 } 15126 }
15122 15127
15123 15128
15124 const Runtime::Function* Runtime::FunctionForId(Runtime::FunctionId id) { 15129 const Runtime::Function* Runtime::FunctionForId(Runtime::FunctionId id) {
15125 return &(kIntrinsicFunctions[static_cast<int>(id)]); 15130 return &(kIntrinsicFunctions[static_cast<int>(id)]);
15126 } 15131 }
15127 15132
15128 } } // namespace v8::internal 15133 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/factory.cc ('k') | test/mjsunit/regress/regress-empty-fixed-double-array.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698