mirror of
https://github.com/Samsung/escargot.git
synced 2026-06-29 10:02:14 +00:00
Improve performance little
* divide Value::toBoolean into 2 functions for better function call inlinling * try to avoid call RopeString::flattenRopeString if possible flatten RopeString for read one char is waste I think Signed-off-by: Seonghyun Kim <sh8281.kim@samsung.com>
This commit is contained in:
parent
925543bc15
commit
4d69bed6c5
9 changed files with 115 additions and 93 deletions
|
|
@ -23,15 +23,6 @@
|
|||
|
||||
namespace Escargot {
|
||||
|
||||
static inline Value charToStringValue(ExecutionState& state, char16_t ch)
|
||||
{
|
||||
if (ch < ESCARGOT_ASCII_TABLE_MAX) {
|
||||
return state.context()->staticStrings().asciiTable[ch].string();
|
||||
} else {
|
||||
return String::fromCharCode(ch);
|
||||
}
|
||||
}
|
||||
|
||||
StringObject::StringObject(ExecutionState& state, String* value)
|
||||
: StringObject(state, state.context()->globalObject()->stringPrototype(), value)
|
||||
{
|
||||
|
|
@ -65,7 +56,7 @@ ObjectHasPropertyResult StringObject::hasProperty(ExecutionState& state, const O
|
|||
if (idx != Value::InvalidIndexPropertyValue) {
|
||||
size_t strLen = m_primitiveValue->length();
|
||||
if (LIKELY(idx < strLen)) {
|
||||
return ObjectHasPropertyResult(ObjectGetResult(charToStringValue(state, m_primitiveValue->charAt(idx)), false, true, false));
|
||||
return ObjectHasPropertyResult(ObjectGetResult(state.context()->staticStrings().charCodeToString(m_primitiveValue->charAt(idx)), false, true, false));
|
||||
}
|
||||
}
|
||||
return Object::hasProperty(state, P);
|
||||
|
|
@ -78,7 +69,7 @@ ObjectGetResult StringObject::getOwnProperty(ExecutionState& state, const Object
|
|||
if (idx != Value::InvalidIndexPropertyValue) {
|
||||
size_t strLen = m_primitiveValue->length();
|
||||
if (LIKELY(idx < strLen)) {
|
||||
return ObjectGetResult(charToStringValue(state, m_primitiveValue->charAt(idx)), false, true, false);
|
||||
return ObjectGetResult(state.context()->staticStrings().charCodeToString(m_primitiveValue->charAt(idx)), false, true, false);
|
||||
}
|
||||
}
|
||||
return Object::getOwnProperty(state, P);
|
||||
|
|
@ -117,7 +108,7 @@ ObjectGetResult StringObject::getIndexedProperty(ExecutionState& state, const Va
|
|||
if (idx != Value::InvalidIndexPropertyValue) {
|
||||
size_t strLen = m_primitiveValue->length();
|
||||
if (LIKELY(idx < strLen)) {
|
||||
return ObjectGetResult(charToStringValue(state, m_primitiveValue->charAt(idx)), false, true, false);
|
||||
return ObjectGetResult(state.context()->staticStrings().charCodeToString(m_primitiveValue->charAt(idx)), false, true, false);
|
||||
}
|
||||
}
|
||||
return get(state, ObjectPropertyName(state, property), receiver);
|
||||
|
|
@ -129,7 +120,7 @@ ObjectHasPropertyResult StringObject::hasIndexedProperty(ExecutionState& state,
|
|||
if (idx != Value::InvalidIndexPropertyValue) {
|
||||
size_t strLen = m_primitiveValue->length();
|
||||
if (LIKELY(idx < strLen)) {
|
||||
return ObjectHasPropertyResult(ObjectGetResult(charToStringValue(state, m_primitiveValue->charAt(idx)), false, true, false));
|
||||
return ObjectHasPropertyResult(ObjectGetResult(state.context()->staticStrings().charCodeToString(m_primitiveValue->charAt(idx)), false, true, false));
|
||||
}
|
||||
}
|
||||
return hasProperty(state, ObjectPropertyName(state, propertyName));
|
||||
|
|
@ -182,13 +173,13 @@ std::pair<Value, bool> StringIteratorObject::advance(ExecutionState& state)
|
|||
// If first < 0xD800 or first > 0xDBFF or position+1 = len, let resultString be the string consisting of the single code unit first.
|
||||
String* resultString;
|
||||
if (first < 0xD800 || first > 0xDBFF || (position + 1 == len)) {
|
||||
resultString = String::fromCharCode(first);
|
||||
resultString = state.context()->staticStrings().charCodeToString(first);
|
||||
} else {
|
||||
// Let second be the code unit value at index position+1 in the String S.
|
||||
auto second = s->charAt(position + 1);
|
||||
// If second < 0xDC00 or second > 0xDFFF, let resultString be the string consisting of the single code unit first.
|
||||
if (second < 0xDC00 || second > 0xDFFF) {
|
||||
resultString = String::fromCharCode(first);
|
||||
resultString = state.context()->staticStrings().charCodeToString(first);
|
||||
} else {
|
||||
// Else, let resultString be the string consisting of the code unit first followed by the code unit second.
|
||||
char16_t s[2] = { first, second };
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue