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

Unified Diff: src/builtins.cc

Issue 1785403002: [runtime] split up loops with HandleScopes (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: adding loop var type 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/d8.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/builtins.cc
diff --git a/src/builtins.cc b/src/builtins.cc
index 2483d7447b0713c9bb35163b783d2024d8718a78..dd9fcd5c6ffd768530d5b0af4e32fc4efc96d551 100644
--- a/src/builtins.cc
+++ b/src/builtins.cc
@@ -773,20 +773,20 @@ class ArrayConcatVisitor {
Handle<SeededNumberDictionary> slow_storage(
SeededNumberDictionary::New(isolate_, current_storage->length()));
uint32_t current_length = static_cast<uint32_t>(current_storage->length());
- for (uint32_t i = 0; i < current_length; i++) {
- HandleScope loop_scope(isolate_);
- Handle<Object> element(current_storage->get(i), isolate_);
- if (!element->IsTheHole()) {
- // The object holding this backing store has just been allocated, so
- // it cannot yet be used as a prototype.
- Handle<SeededNumberDictionary> new_storage =
- SeededNumberDictionary::AtNumberPut(slow_storage, i, element,
- false);
- if (!new_storage.is_identical_to(slow_storage)) {
- slow_storage = loop_scope.CloseAndEscape(new_storage);
- }
- }
- }
+ FOR_WITH_HANDLE_SCOPE(
+ isolate_, uint32_t, i = 0, i, i < current_length, i++, {
+ Handle<Object> element(current_storage->get(i), isolate_);
+ if (!element->IsTheHole()) {
+ // The object holding this backing store has just been allocated, so
+ // it cannot yet be used as a prototype.
+ Handle<SeededNumberDictionary> new_storage =
+ SeededNumberDictionary::AtNumberPut(slow_storage, i, element,
+ false);
+ if (!new_storage.is_identical_to(slow_storage)) {
+ slow_storage = loop_scope.CloseAndEscape(new_storage);
+ }
+ }
+ });
clear_storage();
set_storage(*slow_storage);
set_fast_elements(false);
@@ -939,8 +939,7 @@ void CollectElementIndices(Handle<JSObject> object, uint32_t range,
Handle<SeededNumberDictionary> dict(
SeededNumberDictionary::cast(object->elements()));
uint32_t capacity = dict->Capacity();
- for (uint32_t j = 0; j < capacity; j++) {
- HandleScope loop_scope(isolate);
+ FOR_WITH_HANDLE_SCOPE(isolate, uint32_t, j = 0, j, j < capacity, j++, {
Handle<Object> k(dict->KeyAt(j), isolate);
if (dict->IsKey(*k)) {
DCHECK(k->IsNumber());
@@ -949,7 +948,7 @@ void CollectElementIndices(Handle<JSObject> object, uint32_t range,
indices->Add(index);
}
}
- }
+ });
break;
}
#define TYPED_ARRAY_CASE(Type, type, TYPE, ctype, size) case TYPE##_ELEMENTS:
@@ -1017,8 +1016,7 @@ void CollectElementIndices(Handle<JSObject> object, uint32_t range,
bool IterateElementsSlow(Isolate* isolate, Handle<JSReceiver> receiver,
uint32_t length, ArrayConcatVisitor* visitor) {
- for (uint32_t i = 0; i < length; ++i) {
- HandleScope loop_scope(isolate);
+ FOR_WITH_HANDLE_SCOPE(isolate, uint32_t, i = 0, i, i < length, ++i, {
Maybe<bool> maybe = JSReceiver::HasElement(receiver, i);
if (!maybe.IsJust()) return false;
if (maybe.FromJust()) {
@@ -1028,7 +1026,7 @@ bool IterateElementsSlow(Isolate* isolate, Handle<JSReceiver> receiver,
false);
if (!visitor->visit(i, element_value)) return false;
}
- }
+ });
visitor->increase_index_offset(length);
return true;
}
@@ -1082,8 +1080,7 @@ bool IterateElements(Isolate* isolate, Handle<JSReceiver> receiver,
Handle<FixedArray> elements(FixedArray::cast(array->elements()));
int fast_length = static_cast<int>(length);
DCHECK(fast_length <= elements->length());
- for (int j = 0; j < fast_length; j++) {
- HandleScope loop_scope(isolate);
+ FOR_WITH_HANDLE_SCOPE(isolate, int, j = 0, j, j < fast_length, j++, {
Handle<Object> element_value(elements->get(j), isolate);
if (!element_value->IsTheHole()) {
if (!visitor->visit(j, element_value)) return false;
@@ -1099,7 +1096,7 @@ bool IterateElements(Isolate* isolate, Handle<JSReceiver> receiver,
if (!visitor->visit(j, element_value)) return false;
}
}
- }
+ });
break;
}
case FAST_HOLEY_DOUBLE_ELEMENTS:
@@ -1116,8 +1113,7 @@ bool IterateElements(Isolate* isolate, Handle<JSReceiver> receiver,
FixedDoubleArray::cast(array->elements()));
int fast_length = static_cast<int>(length);
DCHECK(fast_length <= elements->length());
- for (int j = 0; j < fast_length; j++) {
- HandleScope loop_scope(isolate);
+ FOR_WITH_HANDLE_SCOPE(isolate, int, j = 0, j, j < fast_length, j++, {
if (!elements->is_the_hole(j)) {
double double_value = elements->get_scalar(j);
Handle<Object> element_value =
@@ -1136,7 +1132,7 @@ bool IterateElements(Isolate* isolate, Handle<JSReceiver> receiver,
if (!visitor->visit(j, element_value)) return false;
}
}
- }
+ });
break;
}
@@ -1155,10 +1151,8 @@ bool IterateElements(Isolate* isolate, Handle<JSReceiver> receiver,
// than length. This might introduce duplicates in the indices list.
CollectElementIndices(array, length, &indices);
indices.Sort(&compareUInt32);
- int j = 0;
int n = indices.length();
- while (j < n) {
- HandleScope loop_scope(isolate);
+ FOR_WITH_HANDLE_SCOPE(isolate, int, j = 0, j, j < n, j = j, {
Igor Sheludko 2016/03/14 08:36:16 I think something like (void)0 is better than j =
uint32_t index = indices[j];
Handle<Object> element;
ASSIGN_RETURN_ON_EXCEPTION_VALUE(
@@ -1169,19 +1163,19 @@ bool IterateElements(Isolate* isolate, Handle<JSReceiver> receiver,
do {
j++;
} while (j < n && indices[j] == index);
- }
+ });
break;
}
case FAST_SLOPPY_ARGUMENTS_ELEMENTS:
case SLOW_SLOPPY_ARGUMENTS_ELEMENTS: {
- for (uint32_t index = 0; index < length; index++) {
- HandleScope loop_scope(isolate);
- Handle<Object> element;
- ASSIGN_RETURN_ON_EXCEPTION_VALUE(
- isolate, element, JSReceiver::GetElement(isolate, array, index),
- false);
- if (!visitor->visit(index, element)) return false;
- }
+ FOR_WITH_HANDLE_SCOPE(
+ isolate, uint32_t, index = 0, index, index < length, index++, {
+ Handle<Object> element;
+ ASSIGN_RETURN_ON_EXCEPTION_VALUE(
+ isolate, element, JSReceiver::GetElement(isolate, array, index),
+ false);
+ if (!visitor->visit(index, element)) return false;
+ });
break;
}
case NO_ELEMENTS:
@@ -1236,8 +1230,7 @@ Object* Slow_ArrayConcat(Arguments* args, Handle<Object> species,
uint32_t estimate_result_length = 0;
uint32_t estimate_nof_elements = 0;
- for (int i = 0; i < argument_count; i++) {
- HandleScope loop_scope(isolate);
+ FOR_WITH_HANDLE_SCOPE(isolate, int, i = 0, i, i < argument_count, i++, {
Handle<Object> obj((*args)[i], isolate);
uint32_t length_estimate;
uint32_t element_estimate;
@@ -1272,7 +1265,7 @@ Object* Slow_ArrayConcat(Arguments* args, Handle<Object> species,
} else {
estimate_nof_elements += element_estimate;
}
- }
+ });
// If estimated number of elements is more than half of length, a
// fixed array (fast case) is more time and space-efficient than a
« no previous file with comments | « no previous file | src/d8.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698