Commit 535d8bb7 authored by barraclough@apple.com's avatar barraclough@apple.com

https://bugs.webkit.org/show_bug.cgi?id=75140

Reviewed by Sam Weinig.

Simplify JSArray creation - remove ArgsList/JSValue* create methods
(this functionality can be implemented in terms of tryCreateUninitialized).

* JavaScriptCore.exp:
* runtime/ArrayConstructor.cpp:
    - use constructArray/constructEmptyArray instead of calling JSArray::create directly
(JSC::constructArrayWithSizeQuirk):
* runtime/JSArray.cpp:
* runtime/JSArray.h:
    - removed ArgsList/JSValue* create methods
* runtime/JSGlobalObject.h:
(JSC::constructEmptyArray):
(JSC::constructArray):
    - changed to be implemented in terms of JSArray::tryCreateUninitialized



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@103960 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent c333760f
2012-01-03 Gavin Barraclough <barraclough@apple.com>
https://bugs.webkit.org/show_bug.cgi?id=75140
Reviewed by Sam Weinig.
Simplify JSArray creation - remove ArgsList/JSValue* create methods
(this functionality can be implemented in terms of tryCreateUninitialized).
* JavaScriptCore.exp:
* runtime/ArrayConstructor.cpp:
- use constructArray/constructEmptyArray instead of calling JSArray::create directly
(JSC::constructArrayWithSizeQuirk):
* runtime/JSArray.cpp:
* runtime/JSArray.h:
- removed ArgsList/JSValue* create methods
* runtime/JSGlobalObject.h:
(JSC::constructEmptyArray):
(JSC::constructArray):
- changed to be implemented in terms of JSArray::tryCreateUninitialized
2012-01-03 Gavin Barraclough <barraclough@apple.com>
https://bugs.webkit.org/show_bug.cgi?id=75429
......@@ -280,9 +280,9 @@ __ZN3JSC6RegExp5matchERNS_12JSGlobalDataERKNS_7UStringEiPN3WTF6VectorIiLm32EEE
__ZN3JSC6RegExp6createERNS_12JSGlobalDataERKNS_7UStringENS_11RegExpFlagsE
__ZN3JSC7JSArray13visitChildrenEPNS_6JSCellERNS_11SlotVisitorE
__ZN3JSC7JSArray14finishCreationERNS_12JSGlobalDataEj
__ZN3JSC7JSArray14finishCreationERNS_12JSGlobalDataERKNS_7ArgListE
__ZN3JSC7JSArray15setSubclassDataEPv
__ZN3JSC7JSArray25getOwnPropertySlotByIndexEPNS_6JSCellEPNS_9ExecStateEjRNS_12PropertySlotE
__ZN3JSC7JSArray30tryFinishCreationUninitializedERNS_12JSGlobalDataEj
__ZN3JSC7JSArray6s_infoE
__ZN3JSC7JSArray7destroyEPNS_6JSCellE
__ZN3JSC7JSArray9setLengthEj
......
......@@ -86,11 +86,11 @@ static inline JSObject* constructArrayWithSizeQuirk(ExecState* exec, const ArgLi
uint32_t n = args.at(0).toUInt32(exec);
if (n != args.at(0).toNumber(exec))
return throwError(exec, createRangeError(exec, "Array size is not a small enough positive integer."));
return JSArray::create(exec->globalData(), globalObject->arrayStructure(), n);
return constructEmptyArray(exec, globalObject, n);
}
// otherwise the array is constructed with the arguments in it
return JSArray::create(exec->globalData(), globalObject->arrayStructure(), args);
return constructArray(exec, globalObject, args);
}
static EncodedJSValue JSC_HOST_CALL constructWithArrayConstructor(ExecState* exec)
......
......@@ -194,84 +194,6 @@ JSArray* JSArray::tryFinishCreationUninitialized(JSGlobalData& globalData, unsig
return this;
}
void JSArray::finishCreation(JSGlobalData& globalData, const ArgList& list)
{
Base::finishCreation(globalData);
ASSERT(inherits(&s_info));
unsigned initialCapacity = list.size();
unsigned initialStorage;
// If the ArgList is empty, allocate space for 3 entries. This value empirically
// works well for benchmarks.
if (!initialCapacity)
initialStorage = 3;
else
initialStorage = initialCapacity;
m_storage = static_cast<ArrayStorage*>(fastMalloc(storageSize(initialStorage)));
m_storage->m_allocBase = m_storage;
m_indexBias = 0;
m_storage->m_length = initialCapacity;
m_vectorLength = initialStorage;
m_storage->m_numValuesInVector = initialCapacity;
m_storage->m_sparseValueMap = 0;
m_storage->subclassData = 0;
#if CHECK_ARRAY_CONSISTENCY
m_storage->m_inCompactInitialization = false;
#endif
size_t i = 0;
WriteBarrier<Unknown>* vector = m_storage->m_vector;
for (; i < list.size(); ++i)
vector[i].set(globalData, this, list.at(i));
for (; i < initialStorage; i++)
vector[i].clear();
checkConsistency();
Heap::heap(this)->reportExtraMemoryCost(storageSize(initialStorage));
}
void JSArray::finishCreation(JSGlobalData& globalData, const JSValue* values, size_t length)
{
Base::finishCreation(globalData);
ASSERT(inherits(&s_info));
unsigned initialCapacity = length;
unsigned initialStorage;
// If the ArgList is empty, allocate space for 3 entries. This value empirically
// works well for benchmarks.
if (!initialCapacity)
initialStorage = 3;
else
initialStorage = initialCapacity;
m_storage = static_cast<ArrayStorage*>(fastMalloc(storageSize(initialStorage)));
m_storage->m_allocBase = m_storage;
m_indexBias = 0;
m_storage->m_length = initialCapacity;
m_vectorLength = initialStorage;
m_storage->m_numValuesInVector = initialCapacity;
m_storage->m_sparseValueMap = 0;
m_storage->subclassData = 0;
#if CHECK_ARRAY_CONSISTENCY
m_storage->m_inCompactInitialization = false;
#endif
size_t i = 0;
WriteBarrier<Unknown>* vector = m_storage->m_vector;
for ( ; i != length; ++i)
vector[i].set(globalData, this, values[i]);
for (; i < initialStorage; i++)
vector[i].clear();
checkConsistency();
Heap::heap(this)->reportExtraMemoryCost(storageSize(initialStorage));
}
JSArray::~JSArray()
{
ASSERT(jsCast<JSArray*>(this));
......
......@@ -121,8 +121,6 @@ namespace JSC {
void finishCreation(JSGlobalData&, unsigned initialLength = 0);
JSArray* tryFinishCreationUninitialized(JSGlobalData&, unsigned initialLength);
void finishCreation(JSGlobalData&, const ArgList&);
void finishCreation(JSGlobalData&, const JSValue*, size_t length);
public:
typedef JSNonFinalObject Base;
......@@ -148,20 +146,6 @@ namespace JSC {
return array->tryFinishCreationUninitialized(globalData, initialLength);
}
static JSArray* create(JSGlobalData& globalData, Structure* structure, const ArgList& initialValues)
{
JSArray* array = new (NotNull, allocateCell<JSArray>(globalData.heap)) JSArray(globalData, structure);
array->finishCreation(globalData, initialValues);
return array;
}
static JSArray* create(JSGlobalData& globalData, Structure* structure, const JSValue* values, size_t length)
{
JSArray* array = new (NotNull, allocateCell<JSArray>(globalData.heap)) JSArray(globalData, structure);
array->finishCreation(globalData, values, length);
return array;
}
static bool getOwnPropertySlot(JSCell*, ExecState*, const Identifier& propertyName, PropertySlot&);
static bool getOwnPropertySlotByIndex(JSCell*, ExecState*, unsigned propertyName, PropertySlot&);
static bool getOwnPropertyDescriptor(JSObject*, ExecState*, const Identifier&, PropertyDescriptor&);
......
......@@ -430,41 +430,32 @@ namespace JSC {
return constructEmptyObject(exec, exec->lexicalGlobalObject());
}
inline JSArray* constructEmptyArray(ExecState* exec, JSGlobalObject* globalObject)
{
return JSArray::create(exec->globalData(), globalObject->arrayStructure());
}
inline JSArray* constructEmptyArray(ExecState* exec)
{
return constructEmptyArray(exec, exec->lexicalGlobalObject());
}
inline JSArray* constructEmptyArray(ExecState* exec, JSGlobalObject* globalObject, unsigned initialLength)
inline JSArray* constructEmptyArray(ExecState* exec, JSGlobalObject* globalObject, unsigned initialLength = 0)
{
return JSArray::create(exec->globalData(), globalObject->arrayStructure(), initialLength);
}
inline JSArray* constructEmptyArray(ExecState* exec, unsigned initialLength)
inline JSArray* constructEmptyArray(ExecState* exec, unsigned initialLength = 0)
{
return constructEmptyArray(exec, exec->lexicalGlobalObject(), initialLength);
}
inline JSArray* constructArray(ExecState* exec, JSGlobalObject* globalObject, JSValue singleItemValue)
{
MarkedArgumentBuffer values;
values.append(singleItemValue);
return JSArray::create(exec->globalData(), globalObject->arrayStructure(), values);
}
inline JSArray* constructArray(ExecState* exec, JSValue singleItemValue)
{
return constructArray(exec, exec->lexicalGlobalObject(), singleItemValue);
}
inline JSArray* constructArray(ExecState* exec, JSGlobalObject* globalObject, const ArgList& values)
{
return JSArray::create(exec->globalData(), globalObject->arrayStructure(), values);
JSGlobalData& globalData = exec->globalData();
unsigned length = values.size();
JSArray* array = JSArray::tryCreateUninitialized(globalData, globalObject->arrayStructure(), length);
// FIXME: we should probably throw an out of memory error here, but
// when making this change we should check that all clients of this
// function will correctly handle an exception being thrown from here.
if (!array)
CRASH();
for (unsigned i = 0; i < length; ++i)
array->initializeIndex(globalData, i, values.at(i));
array->completeInitialization(length);
return array;
}
inline JSArray* constructArray(ExecState* exec, const ArgList& values)
......@@ -472,9 +463,26 @@ namespace JSC {
return constructArray(exec, exec->lexicalGlobalObject(), values);
}
inline JSArray* constructArray(ExecState* exec, const JSValue* values, size_t length)
inline JSArray* constructArray(ExecState* exec, JSGlobalObject* globalObject, const JSValue* values, unsigned length)
{
JSGlobalData& globalData = exec->globalData();
JSArray* array = JSArray::tryCreateUninitialized(globalData, globalObject->arrayStructure(), length);
// FIXME: we should probably throw an out of memory error here, but
// when making this change we should check that all clients of this
// function will correctly handle an exception being thrown from here.
if (!array)
CRASH();
for (unsigned i = 0; i < length; ++i)
array->initializeIndex(globalData, i, values[i]);
array->completeInitialization(length);
return array;
}
inline JSArray* constructArray(ExecState* exec, const JSValue* values, unsigned length)
{
return JSArray::create(exec->globalData(), exec->lexicalGlobalObject()->arrayStructure(), values, length);
return constructArray(exec, exec->lexicalGlobalObject(), values, length);
}
class DynamicGlobalObjectScope {
......
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