Callers of ElementsAccessor::SetCapacityAndLength() handlified.
R=verwaest@chromium.org Review URL: https://codereview.chromium.org/210063004 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20229 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
parent
793d4cb0b6
commit
0d7bdc0fd6
@ -357,8 +357,7 @@ void ArrayLiteral::BuildConstantElements(Isolate* isolate) {
|
||||
// Allocate a fixed array to hold all the object literals.
|
||||
Handle<JSArray> array =
|
||||
isolate->factory()->NewJSArray(0, FAST_HOLEY_SMI_ELEMENTS);
|
||||
isolate->factory()->SetElementsCapacityAndLength(
|
||||
array, values()->length(), values()->length());
|
||||
JSArray::Expand(array, values()->length());
|
||||
|
||||
// Fill in the literals.
|
||||
bool is_simple = true;
|
||||
|
@ -766,14 +766,16 @@ class ElementsAccessorBase : public ElementsAccessor {
|
||||
Handle<Object> length,
|
||||
Handle<FixedArrayBase> backing_store);
|
||||
|
||||
MUST_USE_RESULT virtual MaybeObject* SetCapacityAndLength(
|
||||
JSArray* array,
|
||||
virtual void SetCapacityAndLength(
|
||||
Handle<JSArray> array,
|
||||
int capacity,
|
||||
int length) V8_FINAL V8_OVERRIDE {
|
||||
return ElementsAccessorSubclass::SetFastElementsCapacityAndLength(
|
||||
array,
|
||||
capacity,
|
||||
length);
|
||||
CALL_HEAP_FUNCTION_VOID(
|
||||
array->GetIsolate(),
|
||||
ElementsAccessorSubclass::SetFastElementsCapacityAndLength(
|
||||
*array,
|
||||
capacity,
|
||||
length));
|
||||
}
|
||||
|
||||
MUST_USE_RESULT static MaybeObject* SetFastElementsCapacityAndLength(
|
||||
|
@ -126,9 +126,10 @@ class ElementsAccessor {
|
||||
// elements. This method should only be called for array expansion OR by
|
||||
// runtime JavaScript code that use InternalArrays and don't care about
|
||||
// EcmaScript 5.1 semantics.
|
||||
MUST_USE_RESULT virtual MaybeObject* SetCapacityAndLength(JSArray* array,
|
||||
int capacity,
|
||||
int length) = 0;
|
||||
virtual void SetCapacityAndLength(
|
||||
Handle<JSArray> array,
|
||||
int capacity,
|
||||
int length) = 0;
|
||||
|
||||
// Deletes an element in an object, returning a new elements backing store.
|
||||
MUST_USE_RESULT virtual Handle<Object> Delete(
|
||||
|
@ -1489,16 +1489,6 @@ void Factory::NewJSArrayStorage(Handle<JSArray> array,
|
||||
}
|
||||
|
||||
|
||||
void Factory::SetElementsCapacityAndLength(Handle<JSArray> array,
|
||||
int capacity,
|
||||
int length) {
|
||||
ElementsAccessor* accessor = array->GetElementsAccessor();
|
||||
CALL_HEAP_FUNCTION_VOID(
|
||||
isolate(),
|
||||
accessor->SetCapacityAndLength(*array, capacity, length));
|
||||
}
|
||||
|
||||
|
||||
Handle<JSGeneratorObject> Factory::NewJSGeneratorObject(
|
||||
Handle<JSFunction> function) {
|
||||
ASSERT(function->shared()->is_generator());
|
||||
|
@ -387,10 +387,6 @@ class Factory {
|
||||
int capacity,
|
||||
ArrayStorageAllocationMode mode = DONT_INITIALIZE_ARRAY_ELEMENTS);
|
||||
|
||||
void SetElementsCapacityAndLength(Handle<JSArray> array,
|
||||
int capacity,
|
||||
int length);
|
||||
|
||||
Handle<JSGeneratorObject> NewJSGeneratorObject(Handle<JSFunction> function);
|
||||
|
||||
Handle<JSArrayBuffer> NewJSArrayBuffer();
|
||||
|
@ -393,13 +393,16 @@ BasicJsonStringifier::Result BasicJsonStringifier::StackPush(
|
||||
if (check.HasOverflowed()) return STACK_OVERFLOW;
|
||||
|
||||
int length = Smi::cast(stack_->length())->value();
|
||||
FixedArray* elements = FixedArray::cast(stack_->elements());
|
||||
for (int i = 0; i < length; i++) {
|
||||
if (elements->get(i) == *object) {
|
||||
return CIRCULAR;
|
||||
{
|
||||
DisallowHeapAllocation no_allocation;
|
||||
FixedArray* elements = FixedArray::cast(stack_->elements());
|
||||
for (int i = 0; i < length; i++) {
|
||||
if (elements->get(i) == *object) {
|
||||
return CIRCULAR;
|
||||
}
|
||||
}
|
||||
}
|
||||
stack_->EnsureSize(length + 1);
|
||||
JSArray::EnsureSize(stack_, length + 1);
|
||||
FixedArray::cast(stack_->elements())->set(length, *object);
|
||||
stack_->set_length(Smi::FromInt(length + 1));
|
||||
return SUCCESS;
|
||||
|
@ -691,7 +691,8 @@ Handle<JSArray> RegExpImpl::SetLastMatchInfo(Handle<JSArray> last_match_info,
|
||||
int32_t* match) {
|
||||
ASSERT(last_match_info->HasFastObjectElements());
|
||||
int capture_register_count = (capture_count + 1) * 2;
|
||||
last_match_info->EnsureSize(capture_register_count + kLastMatchOverhead);
|
||||
JSArray::EnsureSize(last_match_info,
|
||||
capture_register_count + kLastMatchOverhead);
|
||||
DisallowHeapAllocation no_allocation;
|
||||
FixedArray* array = FixedArray::cast(last_match_info->elements());
|
||||
if (match != NULL) {
|
||||
|
@ -6527,20 +6527,20 @@ void Map::ClearCodeCache(Heap* heap) {
|
||||
}
|
||||
|
||||
|
||||
void JSArray::EnsureSize(int required_size) {
|
||||
ASSERT(HasFastSmiOrObjectElements());
|
||||
FixedArray* elts = FixedArray::cast(elements());
|
||||
void JSArray::EnsureSize(Handle<JSArray> array, int required_size) {
|
||||
ASSERT(array->HasFastSmiOrObjectElements());
|
||||
Handle<FixedArray> elts = handle(FixedArray::cast(array->elements()));
|
||||
const int kArraySizeThatFitsComfortablyInNewSpace = 128;
|
||||
if (elts->length() < required_size) {
|
||||
// Doubling in size would be overkill, but leave some slack to avoid
|
||||
// constantly growing.
|
||||
Expand(required_size + (required_size >> 3));
|
||||
Expand(array, required_size + (required_size >> 3));
|
||||
// It's a performance benefit to keep a frequently used array in new-space.
|
||||
} else if (!GetHeap()->new_space()->Contains(elts) &&
|
||||
} else if (!array->GetHeap()->new_space()->Contains(*elts) &&
|
||||
required_size < kArraySizeThatFitsComfortablyInNewSpace) {
|
||||
// Expand will allocate a new backing store in new space even if the size
|
||||
// we asked for isn't larger than what we had before.
|
||||
Expand(required_size);
|
||||
Expand(array, required_size);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -11279,9 +11279,9 @@ void JSArray::Initialize(Handle<JSArray> array, int capacity, int length) {
|
||||
}
|
||||
|
||||
|
||||
void JSArray::Expand(int required_size) {
|
||||
GetIsolate()->factory()->SetElementsCapacityAndLength(
|
||||
Handle<JSArray>(this), required_size, required_size);
|
||||
void JSArray::Expand(Handle<JSArray> array, int required_size) {
|
||||
ElementsAccessor* accessor = array->GetElementsAccessor();
|
||||
accessor->SetCapacityAndLength(array, required_size, required_size);
|
||||
}
|
||||
|
||||
|
||||
|
@ -10028,9 +10028,15 @@ class JSArray: public JSObject {
|
||||
// Casting.
|
||||
static inline JSArray* cast(Object* obj);
|
||||
|
||||
// Uses handles. Ensures that the fixed array backing the JSArray has at
|
||||
// Ensures that the fixed array backing the JSArray has at
|
||||
// least the stated size.
|
||||
inline void EnsureSize(int minimum_size_of_backing_fixed_array);
|
||||
static inline void EnsureSize(Handle<JSArray> array,
|
||||
int minimum_size_of_backing_fixed_array);
|
||||
|
||||
// Expand the fixed array backing of a fast-case JSArray to at least
|
||||
// the requested size.
|
||||
static void Expand(Handle<JSArray> array,
|
||||
int minimum_size_of_backing_fixed_array);
|
||||
|
||||
// Dispatched behavior.
|
||||
DECLARE_PRINTER(JSArray)
|
||||
@ -10044,10 +10050,6 @@ class JSArray: public JSObject {
|
||||
static const int kSize = kLengthOffset + kPointerSize;
|
||||
|
||||
private:
|
||||
// Expand the fixed array backing of a fast-case JSArray to at least
|
||||
// the requested size.
|
||||
void Expand(int minimum_size_of_backing_fixed_array);
|
||||
|
||||
DISALLOW_IMPLICIT_CONSTRUCTORS(JSArray);
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user