Closed Bug 1717526 Opened 4 years ago Closed 4 years ago

String's implicit conversion operator causes COW relocations

Categories

(Core :: XPCOM, defect, P2)

defect

Tracking

()

RESOLVED FIXED
91 Branch
Tracking Status
firefox91 --- fixed

People

(Reporter: nika, Assigned: nika)

Details

Attachments

(1 file)

The operator Span<char_type> operator defined on nsTSubstring in bug 1295611 implicitly invokes BeginWriting() which can relocate the string's backing buffer to make it writable. This means that any code which casts a non-const nsTSubstring to a Span<char_type> will make the string owned.

We shouldn't do this kind of relocation implicitly, as it can be done accidentally very easily, such as when a user is intending to use operator Span<const char_type>. This patch tracks changing uses of the non-const operator to be explicit calls instead.

Pushed by nlayzell@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/3beb01f5d643 String's implicit conversion operator causes COW relocations, r=xpcom-reviewers,mccr8

Backed out changeset 3beb01f5d643 (Bug 1717526) for causing gtest failures in SpanTest.from_xpcom_collections
Backout link: https://hg.mozilla.org/integration/autoland/rev/15b20f4cd02f9497f40e3dfe06adbc9dab1eb050
Push with failures, failure log.

Flags: needinfo?(nika)
Flags: needinfo?(nika)
Pushed by nlayzell@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/3afce3166219 String's implicit conversion operator causes COW relocations, r=xpcom-reviewers,mccr8
Status: NEW → RESOLVED
Closed: 4 years ago
Resolution: --- → FIXED
Target Milestone: --- → 91 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: