Refactor code (#396)

* Revise hasProperty and apply it everywhere
* Add hasIndexedProperty for performance
* Change Object::nextIndex{Forward, Backward} double parameter types into int for performance
* in String.prototype.replace, Use test fast path correctly & use old method because newer method cannot support regexp correctly(old method is faster)

Signed-off-by: seonghyun kim <sh8281.kim@samsung.com>
This commit is contained in:
Patrick Kim 2019-08-29 14:35:50 +09:00 committed by Hyukwoo Park
commit b656248ce4
17 changed files with 511 additions and 242 deletions

View file

@ -295,7 +295,7 @@ bool ArrayObject::setArrayLength(ExecutionState& state, const uint64_t newLength
ObjectPropertyName key(state, Value(oldLen));
if (!getOwnProperty(state, key).hasValue()) {
double result;
int64_t result;
Object::nextIndexBackward(state, this, oldLen, -1, false, result);
oldLen = result;
@ -373,6 +373,20 @@ bool ArrayObject::setFastModeValue(ExecutionState& state, const ObjectPropertyNa
return false;
}
ObjectHasPropertyResult ArrayObject::hasIndexedProperty(ExecutionState& state, const Value& propertyName)
{
if (LIKELY(isFastModeArray())) {
uint32_t idx = propertyName.tryToUseAsArrayIndex(state);
if (LIKELY(idx != Value::InvalidArrayIndexValue) && LIKELY(idx < getArrayLength(state))) {
Value v = m_fastModeData[idx];
if (LIKELY(!v.isEmpty())) {
return ObjectHasPropertyResult(ObjectGetResult(v, true, true, true));
}
}
}
return hasProperty(state, ObjectPropertyName(state, propertyName));
}
ObjectGetResult ArrayObject::getIndexedProperty(ExecutionState& state, const Value& property)
{
if (LIKELY(isFastModeArray())) {
@ -382,7 +396,6 @@ ObjectGetResult ArrayObject::getIndexedProperty(ExecutionState& state, const Val
if (LIKELY(!v.isEmpty())) {
return ObjectGetResult(v, true, true, true);
}
return get(state, ObjectPropertyName(state, property));
}
}
return get(state, ObjectPropertyName(state, property));