From ddf68de5055a463f2967a495cda8c6ced24b88bf Mon Sep 17 00:00:00 2001 From: Nathan Froyd Date: Thu, 19 Nov 2015 20:19:57 -0500 Subject: [PATCH] Bug 1229962 - use UniquePtr instead of nsAutoArrayPtr in parser/html/; r=hsivonen --- parser/html/nsHtml5Highlighter.cpp | 6 +++--- parser/html/nsHtml5Highlighter.h | 4 ++-- parser/html/nsHtml5StreamParser.cpp | 21 ++++++++++--------- parser/html/nsHtml5StreamParser.h | 3 ++- parser/html/nsHtml5TreeBuilderCppSupplement.h | 5 +++-- parser/html/nsHtml5TreeBuilderHSupplement.h | 4 ++-- 6 files changed, 23 insertions(+), 20 deletions(-) diff --git a/parser/html/nsHtml5Highlighter.cpp b/parser/html/nsHtml5Highlighter.cpp index 7ae96ffed050..aa147b344f92 100644 --- a/parser/html/nsHtml5Highlighter.cpp +++ b/parser/html/nsHtml5Highlighter.cpp @@ -57,7 +57,7 @@ nsHtml5Highlighter::nsHtml5Highlighter(nsAHtml5TreeOpSink* aOpSink) , mCurrentRun(nullptr) , mAmpersand(nullptr) , mSlash(nullptr) - , mHandles(new nsIContent*[NS_HTML5_HIGHLIGHTER_HANDLE_ARRAY_LENGTH]) + , mHandles(MakeUnique(NS_HTML5_HIGHLIGHTER_HANDLE_ARRAY_LENGTH)) , mHandlesUsed(0) , mSeenBase(false) { @@ -641,8 +641,8 @@ nsIContent** nsHtml5Highlighter::AllocateContentHandle() { if (mHandlesUsed == NS_HTML5_HIGHLIGHTER_HANDLE_ARRAY_LENGTH) { - mOldHandles.AppendElement(mHandles.forget()); - mHandles = new nsIContent*[NS_HTML5_HIGHLIGHTER_HANDLE_ARRAY_LENGTH]; + mOldHandles.AppendElement(Move(mHandles)); + mHandles = MakeUnique(NS_HTML5_HIGHLIGHTER_HANDLE_ARRAY_LENGTH); mHandlesUsed = 0; } #ifdef DEBUG diff --git a/parser/html/nsHtml5Highlighter.h b/parser/html/nsHtml5Highlighter.h index 086cc76826e0..e9474869e68f 100644 --- a/parser/html/nsHtml5Highlighter.h +++ b/parser/html/nsHtml5Highlighter.h @@ -342,7 +342,7 @@ class nsHtml5Highlighter /** * Memory for element handles. */ - nsAutoArrayPtr mHandles; + mozilla::UniquePtr mHandles; /** * Number of handles used in mHandles @@ -352,7 +352,7 @@ class nsHtml5Highlighter /** * A holder for old contents of mHandles */ - nsTArray > mOldHandles; + nsTArray> mOldHandles; /** * The element stack. diff --git a/parser/html/nsHtml5StreamParser.cpp b/parser/html/nsHtml5StreamParser.cpp index d8ef1382ad0c..705f518f7d2f 100644 --- a/parser/html/nsHtml5StreamParser.cpp +++ b/parser/html/nsHtml5StreamParser.cpp @@ -17,6 +17,7 @@ #include "nsHtml5RefPtr.h" #include "nsIScriptError.h" #include "mozilla/Preferences.h" +#include "mozilla/UniquePtrExtensions.h" #include "nsHtml5Highlighter.h" #include "expat_config.h" #include "expat.h" @@ -300,7 +301,7 @@ nsHtml5StreamParser::SetupDecodingAndWriteSniffingBufferAndCurrentSegment(const mUnicodeDecoder = EncodingUtils::DecoderForEncoding(mCharset); if (mSniffingBuffer) { uint32_t writeCount; - rv = WriteStreamBytes(mSniffingBuffer, mSniffingLength, &writeCount); + rv = WriteStreamBytes(mSniffingBuffer.get(), mSniffingLength, &writeCount); NS_ENSURE_SUCCESS(rv, rv); mSniffingBuffer = nullptr; } @@ -783,13 +784,13 @@ nsHtml5StreamParser::SniffStreamBytes(const uint8_t* aFromSegment, } if (!mSniffingBuffer) { - mSniffingBuffer = new (mozilla::fallible) - uint8_t[NS_HTML5_STREAM_PARSER_SNIFFING_BUFFER_SIZE]; + mSniffingBuffer = + MakeUniqueFallible(NS_HTML5_STREAM_PARSER_SNIFFING_BUFFER_SIZE); if (!mSniffingBuffer) { return NS_ERROR_OUT_OF_MEMORY; } } - memcpy(mSniffingBuffer + mSniffingLength, aFromSegment, aCount); + memcpy(&mSniffingBuffer[mSniffingLength], aFromSegment, aCount); mSniffingLength += aCount; *aWriteCount = aCount; return NS_OK; @@ -1126,20 +1127,20 @@ class nsHtml5DataAvailable : public nsRunnable { private: nsHtml5RefPtr mStreamParser; - nsAutoArrayPtr mData; + UniquePtr mData; uint32_t mLength; public: nsHtml5DataAvailable(nsHtml5StreamParser* aStreamParser, - uint8_t* aData, + UniquePtr aData, uint32_t aLength) : mStreamParser(aStreamParser) - , mData(aData) + , mData(Move(aData)) , mLength(aLength) {} NS_IMETHODIMP Run() { mozilla::MutexAutoLock autoLock(mStreamParser->mTokenizerMutex); - mStreamParser->DoDataAvailable(mData, mLength); + mStreamParser->DoDataAvailable(mData.get(), mLength); return NS_OK; } }; @@ -1160,7 +1161,7 @@ nsHtml5StreamParser::OnDataAvailable(nsIRequest* aRequest, uint32_t totalRead; // Main thread to parser thread dispatch requires copying to buffer first. if (NS_IsMainThread()) { - nsAutoArrayPtr data(new (mozilla::fallible) uint8_t[aLength]); + auto data = MakeUniqueFallible(aLength); if (!data) { return mExecutor->MarkAsBroken(NS_ERROR_OUT_OF_MEMORY); } @@ -1170,7 +1171,7 @@ nsHtml5StreamParser::OnDataAvailable(nsIRequest* aRequest, NS_ASSERTION(totalRead <= aLength, "Read more bytes than were available?"); nsCOMPtr dataAvailable = new nsHtml5DataAvailable(this, - data.forget(), + Move(data), totalRead); if (NS_FAILED(mThread->Dispatch(dataAvailable, nsIThread::DISPATCH_NORMAL))) { NS_WARNING("Dispatching DataAvailable event failed."); diff --git a/parser/html/nsHtml5StreamParser.h b/parser/html/nsHtml5StreamParser.h index 2550b9b99561..ad62327087e3 100644 --- a/parser/html/nsHtml5StreamParser.h +++ b/parser/html/nsHtml5StreamParser.h @@ -15,6 +15,7 @@ #include "nsHtml5OwningUTF16Buffer.h" #include "nsIInputStream.h" #include "mozilla/Mutex.h" +#include "mozilla/UniquePtr.h" #include "nsHtml5AtomTable.h" #include "nsHtml5Speculation.h" #include "nsITimer.h" @@ -398,7 +399,7 @@ class nsHtml5StreamParser : public nsICharsetDetectionObserver { /** * The buffer for sniffing the character encoding */ - nsAutoArrayPtr mSniffingBuffer; + mozilla::UniquePtr mSniffingBuffer; /** * The number of meaningful bytes in mSniffingBuffer diff --git a/parser/html/nsHtml5TreeBuilderCppSupplement.h b/parser/html/nsHtml5TreeBuilderCppSupplement.h index 70eb9abfc8aa..3e59df6627b7 100644 --- a/parser/html/nsHtml5TreeBuilderCppSupplement.h +++ b/parser/html/nsHtml5TreeBuilderCppSupplement.h @@ -9,6 +9,7 @@ #include "nsNodeUtils.h" #include "nsIFrame.h" #include "mozilla/Likely.h" +#include "mozilla/UniquePtr.h" nsHtml5TreeBuilder::nsHtml5TreeBuilder(nsHtml5OplessBuilder* aBuilder) : scriptingEnabled(false) @@ -997,8 +998,8 @@ nsHtml5TreeBuilder::AllocateContentHandle() return nullptr; } if (mHandlesUsed == NS_HTML5_TREE_BUILDER_HANDLE_ARRAY_LENGTH) { - mOldHandles.AppendElement(mHandles.forget()); - mHandles = new nsIContent*[NS_HTML5_TREE_BUILDER_HANDLE_ARRAY_LENGTH]; + mOldHandles.AppendElement(Move(mHandles)); + mHandles = MakeUnique(NS_HTML5_TREE_BUILDER_HANDLE_ARRAY_LENGTH); mHandlesUsed = 0; } #ifdef DEBUG diff --git a/parser/html/nsHtml5TreeBuilderHSupplement.h b/parser/html/nsHtml5TreeBuilderHSupplement.h index b4549c6f7bd3..0e614434d23a 100644 --- a/parser/html/nsHtml5TreeBuilderHSupplement.h +++ b/parser/html/nsHtml5TreeBuilderHSupplement.h @@ -14,9 +14,9 @@ nsTArray mOpQueue; nsTArray mSpeculativeLoadQueue; nsAHtml5TreeOpSink* mOpSink; - nsAutoArrayPtr mHandles; + mozilla::UniquePtr mHandles; int32_t mHandlesUsed; - nsTArray > mOldHandles; + nsTArray> mOldHandles; nsHtml5TreeOpStage* mSpeculativeLoadStage; nsresult mBroken; bool mCurrentHtmlScriptIsAsyncOrDefer;