diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 05:35:37 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 05:35:37 +0000 |
commit | a90a5cba08fdf6c0ceb95101c275108a152a3aed (patch) | |
tree | 532507288f3defd7f4dcf1af49698bcb76034855 /dom/serializers/nsDocumentEncoder.cpp | |
parent | Adding debian version 126.0.1-1. (diff) | |
download | firefox-a90a5cba08fdf6c0ceb95101c275108a152a3aed.tar.xz firefox-a90a5cba08fdf6c0ceb95101c275108a152a3aed.zip |
Merging upstream version 127.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/serializers/nsDocumentEncoder.cpp')
-rw-r--r-- | dom/serializers/nsDocumentEncoder.cpp | 33 |
1 files changed, 12 insertions, 21 deletions
diff --git a/dom/serializers/nsDocumentEncoder.cpp b/dom/serializers/nsDocumentEncoder.cpp index 46ea15fecc..c50a94ea8e 100644 --- a/dom/serializers/nsDocumentEncoder.cpp +++ b/dom/serializers/nsDocumentEncoder.cpp @@ -341,7 +341,7 @@ class nsDocumentEncoder : public nsIDocumentEncoder { // argument of nsIContentSerializer::Init(). bool mNeedsPreformatScanning; bool mIsCopying; // Set to true only while copying - nsStringBuffer* mCachedBuffer; + RefPtr<nsStringBuffer> mCachedBuffer; class NodeSerializer { public: @@ -701,11 +701,7 @@ nsresult nsDocumentEncoder::SerializeWholeDocument(uint32_t aMaxLength) { return rv; } -nsDocumentEncoder::~nsDocumentEncoder() { - if (mCachedBuffer) { - mCachedBuffer->Release(); - } -} +nsDocumentEncoder::~nsDocumentEncoder() = default; NS_IMETHODIMP nsDocumentEncoder::Init(Document* aDocument, const nsAString& aMimeType, @@ -1372,7 +1368,7 @@ nsDocumentEncoder::EncodeToStringWithMaxLength(uint32_t aMaxLength, nsString output; static const size_t kStringBufferSizeInBytes = 2048; if (!mCachedBuffer) { - mCachedBuffer = nsStringBuffer::Alloc(kStringBufferSizeInBytes).take(); + mCachedBuffer = nsStringBuffer::Alloc(kStringBufferSizeInBytes); if (NS_WARN_IF(!mCachedBuffer)) { return NS_ERROR_OUT_OF_MEMORY; } @@ -1381,9 +1377,7 @@ nsDocumentEncoder::EncodeToStringWithMaxLength(uint32_t aMaxLength, !mCachedBuffer->IsReadonly(), "nsIDocumentEncoder shouldn't keep reference to non-readonly buffer!"); static_cast<char16_t*>(mCachedBuffer->Data())[0] = char16_t(0); - mCachedBuffer->ToString(0, output, true); - // output owns the buffer now! - mCachedBuffer = nullptr; + output.Assign(mCachedBuffer.forget(), 0); if (!mSerializer) { nsAutoCString progId(NS_CONTENTSERIALIZER_CONTRACTID_PREFIX); @@ -1407,21 +1401,18 @@ nsDocumentEncoder::EncodeToStringWithMaxLength(uint32_t aMaxLength, rv = mSerializer->FlushAndFinish(); - mCachedBuffer = nsStringBuffer::FromString(output); // We have to be careful how we set aOutputString, because we don't // want it to end up sharing mCachedBuffer if we plan to reuse it. bool setOutput = false; + MOZ_ASSERT(!mCachedBuffer); // Try to cache the buffer. - if (mCachedBuffer) { - if ((mCachedBuffer->StorageSize() == kStringBufferSizeInBytes) && - !mCachedBuffer->IsReadonly()) { - mCachedBuffer->AddRef(); - } else { - if (NS_SUCCEEDED(rv)) { - mCachedBuffer->ToString(output.Length(), aOutputString); - setOutput = true; - } - mCachedBuffer = nullptr; + if (nsStringBuffer* outputBuffer = output.GetStringBuffer()) { + if (outputBuffer->StorageSize() == kStringBufferSizeInBytes && + !outputBuffer->IsReadonly()) { + mCachedBuffer = outputBuffer; + } else if (NS_SUCCEEDED(rv)) { + aOutputString.Assign(outputBuffer, output.Length()); + setOutput = true; } } |