mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-10-24 16:17:29 +09:00
Optimize substring handling in js::SubstringKernel by caching leftChild length
This commit is contained in:
parent
df7595c912
commit
2c30d61740
1 changed files with 8 additions and 7 deletions
|
|
@ -564,14 +564,15 @@ js::SubstringKernel(JSContext* cx, HandleString str, int32_t beginInt, int32_t l
|
||||||
*/
|
*/
|
||||||
if (str->isRope()) {
|
if (str->isRope()) {
|
||||||
JSRope* rope = &str->asRope();
|
JSRope* rope = &str->asRope();
|
||||||
|
size_t leftLength = rope->leftChild()->length();
|
||||||
|
|
||||||
/* Substring is totally in leftChild of rope. */
|
/* Substring is totally in leftChild of rope. */
|
||||||
if (begin + len <= rope->leftChild()->length())
|
if (begin + len <= leftLength)
|
||||||
return NewDependentString(cx, rope->leftChild(), begin, len);
|
return NewDependentString(cx, rope->leftChild(), begin, len);
|
||||||
|
|
||||||
/* Substring is totally in rightChild of rope. */
|
/* Substring is totally in rightChild of rope. */
|
||||||
if (begin >= rope->leftChild()->length()) {
|
if (begin >= leftLength) {
|
||||||
begin -= rope->leftChild()->length();
|
begin -= leftLength;
|
||||||
return NewDependentString(cx, rope->rightChild(), begin, len);
|
return NewDependentString(cx, rope->rightChild(), begin, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -579,11 +580,11 @@ js::SubstringKernel(JSContext* cx, HandleString str, int32_t beginInt, int32_t l
|
||||||
* Requested substring is partly in the left and partly in right child.
|
* Requested substring is partly in the left and partly in right child.
|
||||||
* Create a rope of substrings for both childs.
|
* Create a rope of substrings for both childs.
|
||||||
*/
|
*/
|
||||||
MOZ_ASSERT(begin < rope->leftChild()->length() &&
|
MOZ_ASSERT(begin < leftLength &&
|
||||||
begin + len > rope->leftChild()->length());
|
begin + len > leftLength);
|
||||||
|
|
||||||
size_t lhsLength = rope->leftChild()->length() - begin;
|
size_t lhsLength = leftLength - begin;
|
||||||
size_t rhsLength = begin + len - rope->leftChild()->length();
|
size_t rhsLength = begin + len - leftLength;
|
||||||
|
|
||||||
Rooted<JSRope*> ropeRoot(cx, rope);
|
Rooted<JSRope*> ropeRoot(cx, rope);
|
||||||
RootedString lhs(cx, NewDependentString(cx, ropeRoot->leftChild(), begin, lhsLength));
|
RootedString lhs(cx, NewDependentString(cx, ropeRoot->leftChild(), begin, lhsLength));
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue