Commit 015af31d authored by bak@chromium.org's avatar bak@chromium.org

- Optimized JSArray allocation in runtime system by using NewJSArrayWithElements.

Review URL: http://codereview.chromium.org/7013

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@479 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent dc32c82c
...@@ -283,10 +283,12 @@ Handle<Object> Factory::NewReferenceError(Handle<String> message) { ...@@ -283,10 +283,12 @@ Handle<Object> Factory::NewReferenceError(Handle<String> message) {
Handle<Object> Factory::NewError(const char* maker, const char* type, Handle<Object> Factory::NewError(const char* maker, const char* type,
Vector< Handle<Object> > args) { Vector< Handle<Object> > args) {
HandleScope scope; HandleScope scope;
Handle<JSArray> array = NewJSArray(args.length()); Handle<FixedArray> array = Factory::NewFixedArray(args.length());
for (int i = 0; i < args.length(); i++) for (int i = 0; i < args.length(); i++) {
SetElement(array, i, args[i]); array->set(i, *args[i]);
Handle<Object> result = NewError(maker, type, array); }
Handle<JSArray> object = Factory::NewJSArrayWithElements(array);
Handle<Object> result = NewError(maker, type, object);
return result.EscapeFrom(&scope); return result.EscapeFrom(&scope);
} }
......
...@@ -391,13 +391,8 @@ Handle<FixedArray> GetKeysInFixedArrayFor(Handle<JSObject> object) { ...@@ -391,13 +391,8 @@ Handle<FixedArray> GetKeysInFixedArrayFor(Handle<JSObject> object) {
Handle<JSArray> GetKeysFor(Handle<JSObject> object) { Handle<JSArray> GetKeysFor(Handle<JSObject> object) {
Counters::for_in.Increment(); Counters::for_in.Increment();
Handle<FixedArray> elements = GetKeysInFixedArrayFor(object);
Handle<FixedArray> content = GetKeysInFixedArrayFor(object); return Factory::NewJSArrayWithElements(elements);
// Allocate the JSArray with the result.
Handle<JSArray> obj = Factory::NewJSArray(content->length());
Handle<JSArray>::cast(obj)->SetContent(*content);
return Handle<JSArray>::cast(obj);
} }
......
...@@ -220,10 +220,11 @@ Handle<Object> RegExpImpl::AtomExec(Handle<JSRegExp> re, ...@@ -220,10 +220,11 @@ Handle<Object> RegExpImpl::AtomExec(Handle<JSRegExp> re,
LOG(RegExpExecEvent(re, start_index, subject)); LOG(RegExpExecEvent(re, start_index, subject));
int value = Runtime::StringMatch(subject, needle, start_index); int value = Runtime::StringMatch(subject, needle, start_index);
if (value == -1) return Factory::null_value(); if (value == -1) return Factory::null_value();
Handle<JSArray> result = Factory::NewJSArray(2);
SetElement(result, 0, Handle<Smi>(Smi::FromInt(value))); Handle<FixedArray> array = Factory::NewFixedArray(2);
SetElement(result, 1, Handle<Smi>(Smi::FromInt(value + needle->length()))); array->set(0, Smi::FromInt(value));
return result; array->set(1, Smi::FromInt(value + needle->length()));
return Factory::NewJSArrayWithElements(array);
} }
...@@ -244,14 +245,15 @@ Handle<Object> RegExpImpl::AtomExecGlobal(Handle<JSRegExp> re, ...@@ -244,14 +245,15 @@ Handle<Object> RegExpImpl::AtomExecGlobal(Handle<JSRegExp> re,
if (value == -1) break; if (value == -1) break;
HandleScope scope; HandleScope scope;
int end = value + needle_length; int end = value + needle_length;
Handle<JSArray> pair = Factory::NewJSArray(2);
SetElement(pair, 0, Handle<Smi>(Smi::FromInt(value))); Handle<FixedArray> array = Factory::NewFixedArray(2);
SetElement(pair, 1, Handle<Smi>(Smi::FromInt(end))); array->set(0, Smi::FromInt(value));
array->set(1, Smi::FromInt(end));
Handle<JSArray> pair = Factory::NewJSArrayWithElements(array);
SetElement(result, match_count, pair); SetElement(result, match_count, pair);
match_count++; match_count++;
index = end; index = end;
if (needle_length == 0) if (needle_length == 0) index++;
index++;
} }
return result; return result;
} }
...@@ -311,7 +313,6 @@ Handle<Object> RegExpImpl::JsreCompile(Handle<JSRegExp> re, ...@@ -311,7 +313,6 @@ Handle<Object> RegExpImpl::JsreCompile(Handle<JSRegExp> re,
} }
ASSERT(code != NULL); ASSERT(code != NULL);
// Convert the return address to a ByteArray pointer. // Convert the return address to a ByteArray pointer.
Handle<ByteArray> internal( Handle<ByteArray> internal(
ByteArray::FromDataStartAddress(reinterpret_cast<Address>(code))); ByteArray::FromDataStartAddress(reinterpret_cast<Address>(code)));
...@@ -368,14 +369,13 @@ Handle<Object> RegExpImpl::JsreExecOnce(Handle<JSRegExp> regexp, ...@@ -368,14 +369,13 @@ Handle<Object> RegExpImpl::JsreExecOnce(Handle<JSRegExp> regexp,
return Handle<Object>(Top::Throw(*regexp_err)); return Handle<Object>(Top::Throw(*regexp_err));
} }
Handle<JSArray> result = Factory::NewJSArray(2 * (num_captures+1)); Handle<FixedArray> array = Factory::NewFixedArray(2 * (num_captures+1));
// The captures come in (start, end+1) pairs. // The captures come in (start, end+1) pairs.
for (int i = 0; i < 2 * (num_captures+1); i += 2) { for (int i = 0; i < 2 * (num_captures+1); i += 2) {
SetElement(result, i, Handle<Object>(Smi::FromInt(offsets_vector[i]))); array->set(i, Smi::FromInt(offsets_vector[i]));
SetElement(result, i+1, Handle<Object>(Smi::FromInt(offsets_vector[i+1]))); array->set(i+1, Smi::FromInt(offsets_vector[i+1]));
} }
return result; return Factory::NewJSArrayWithElements(array);
} }
...@@ -450,7 +450,7 @@ Handle<Object> RegExpImpl::JsreExecGlobal(Handle<JSRegExp> regexp, ...@@ -450,7 +450,7 @@ Handle<Object> RegExpImpl::JsreExecGlobal(Handle<JSRegExp> regexp,
int previous_index = 0; int previous_index = 0;
Handle<JSArray> result = Factory::NewJSArray(0); Handle<JSArray> result = Factory::NewJSArray(0);
int i = 0; int i = 0;
Handle<Object> matches; Handle<Object> matches;
......
...@@ -4695,7 +4695,6 @@ Object* JSObject::SetFastElement(uint32_t index, Object* value) { ...@@ -4695,7 +4695,6 @@ Object* JSObject::SetFastElement(uint32_t index, Object* value) {
return SetElement(index, value); return SetElement(index, value);
} }
Object* JSObject::SetElement(uint32_t index, Object* value) { Object* JSObject::SetElement(uint32_t index, Object* value) {
// Check access rights if needed. // Check access rights if needed.
if (IsAccessCheckNeeded() && if (IsAccessCheckNeeded() &&
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment