Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit c07c8f2

Browse files
committed
Bug 1706694 - Tidy string flattening to use JSRope* in a few more places r=jandem
Differential Revision: https://phabricator.services.mozilla.com/D113317
1 parent 5bb04f3 commit c07c8f2

File tree

2 files changed

+13
-15
lines changed

2 files changed

+13
-15
lines changed

js/src/vm/StringType.cpp

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -764,10 +764,10 @@ JSLinearString* JSRope::flattenInternal(JSRope* root) {
764764
}
765765
}
766766

767-
JSString* str = root;
767+
JSRope* str = root;
768768
CharT* pos = wholeChars;
769769

770-
JSString* parent = nullptr;
770+
JSRope* parent = nullptr;
771771
uint32_t parentFlag = 0;
772772

773773
first_visit_node : {
@@ -786,7 +786,7 @@ first_visit_node : {
786786
/* Return to this node when 'left' done, then goto visit_right_child. */
787787
parent = str;
788788
parentFlag = FLATTEN_VISIT_RIGHT;
789-
str = &left;
789+
str = &left.asRope();
790790
goto first_visit_node;
791791
}
792792
if (!(reuseLeftmostBuffer && &left == leftmostChild)) {
@@ -801,7 +801,7 @@ visit_right_child : {
801801
/* Return to this node when 'right' done, then goto finish_node. */
802802
parent = str;
803803
parentFlag = FLATTEN_FINISH_NODE;
804-
str = &right;
804+
str = &right.asRope();
805805
goto first_visit_node;
806806
}
807807
CopyChars(pos, right.asLinear());
@@ -815,7 +815,7 @@ finish_node : {
815815

816816
MOZ_ASSERT(pos >= wholeChars);
817817
CharT* chars = pos - str->length();
818-
JSString* strParent = str->d.s.u2.parent;
818+
JSRope* strParent = str->d.s.u2.parent;
819819
str->setNonInlineChars(chars);
820820

821821
MOZ_ASSERT(str->asRope().isBeingFlattened());
@@ -826,7 +826,8 @@ finish_node : {
826826
// This also clears the flags related to flattening.
827827
str->setLengthAndFlags(str->length(),
828828
StringFlagsForCharType<CharT>(INIT_DEPENDENT_FLAGS));
829-
str->d.s.u3.base = (JSLinearString*)root; /* will be true on exit */
829+
str->d.s.u3.base =
830+
reinterpret_cast<JSLinearString*>(root); /* will be true on exit */
830831

831832
// Every interior (rope) node in the rope's tree will be visited during
832833
// the traversal and post-barriered here, so earlier additions of
@@ -887,14 +888,11 @@ finish_node : {
887888

888889
template <JSRope::UsingBarrier usingBarrier>
889890
/* static */
890-
inline void JSRope::ropeBarrierDuringFlattening(JSString* str) {
891-
// |str| is a rope but its flags maybe have been overwritten by temporary data
892-
// at this point.
893-
MOZ_ASSERT(str->isRope());
894-
MOZ_ASSERT(!str->asRope().isBeingFlattened());
891+
inline void JSRope::ropeBarrierDuringFlattening(JSRope* rope) {
892+
MOZ_ASSERT(!rope->isBeingFlattened());
895893
if constexpr (usingBarrier) {
896-
gc::PreWriteBarrierDuringFlattening(str->d.s.u2.left);
897-
gc::PreWriteBarrierDuringFlattening(str->d.s.u3.right);
894+
gc::PreWriteBarrierDuringFlattening(rope->leftChild());
895+
gc::PreWriteBarrierDuringFlattening(rope->rightChild());
898896
}
899897
}
900898

js/src/vm/StringType.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ class JSString : public js::gc::CellWithLengthAndFlags {
219219
const char16_t* nonInlineCharsTwoByte; /* JSLinearString, except
220220
JS(Fat)InlineString */
221221
JSString* left; /* JSRope */
222-
JSString* parent; /* Used in flattening */
222+
JSRope* parent; /* Used in flattening */
223223
} u2;
224224
union {
225225
JSLinearString* base; /* JSDependentString */
@@ -723,7 +723,7 @@ class JSRope : public JSString {
723723
static JSLinearString* flattenInternal(JSRope* root);
724724

725725
template <UsingBarrier usingBarrier>
726-
static void ropeBarrierDuringFlattening(JSString* str);
726+
static void ropeBarrierDuringFlattening(JSRope* rope);
727727

728728
void init(JSContext* cx, JSString* left, JSString* right, size_t length);
729729

0 commit comments

Comments
 (0)