mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-08 02:14:43 +00:00
Bug 1229962 - use UniquePtr<T[]> instead of nsAutoArrayPtr<T> in parser/html/; r=hsivonen
This commit is contained in:
parent
40373a6e18
commit
ddf68de505
@ -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<nsIContent*[]>(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<nsIContent*[]>(NS_HTML5_HIGHLIGHTER_HANDLE_ARRAY_LENGTH);
|
||||
mHandlesUsed = 0;
|
||||
}
|
||||
#ifdef DEBUG
|
||||
|
@ -342,7 +342,7 @@ class nsHtml5Highlighter
|
||||
/**
|
||||
* Memory for element handles.
|
||||
*/
|
||||
nsAutoArrayPtr<nsIContent*> mHandles;
|
||||
mozilla::UniquePtr<nsIContent*[]> mHandles;
|
||||
|
||||
/**
|
||||
* Number of handles used in mHandles
|
||||
@ -352,7 +352,7 @@ class nsHtml5Highlighter
|
||||
/**
|
||||
* A holder for old contents of mHandles
|
||||
*/
|
||||
nsTArray<nsAutoArrayPtr<nsIContent*> > mOldHandles;
|
||||
nsTArray<mozilla::UniquePtr<nsIContent*[]>> mOldHandles;
|
||||
|
||||
/**
|
||||
* The element stack.
|
||||
|
@ -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<uint8_t[]>(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<nsHtml5StreamParser> mStreamParser;
|
||||
nsAutoArrayPtr<uint8_t> mData;
|
||||
UniquePtr<uint8_t[]> mData;
|
||||
uint32_t mLength;
|
||||
public:
|
||||
nsHtml5DataAvailable(nsHtml5StreamParser* aStreamParser,
|
||||
uint8_t* aData,
|
||||
UniquePtr<uint8_t[]> 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<uint8_t> data(new (mozilla::fallible) uint8_t[aLength]);
|
||||
auto data = MakeUniqueFallible<uint8_t[]>(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<nsIRunnable> dataAvailable = new nsHtml5DataAvailable(this,
|
||||
data.forget(),
|
||||
Move(data),
|
||||
totalRead);
|
||||
if (NS_FAILED(mThread->Dispatch(dataAvailable, nsIThread::DISPATCH_NORMAL))) {
|
||||
NS_WARNING("Dispatching DataAvailable event failed.");
|
||||
|
@ -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<uint8_t> mSniffingBuffer;
|
||||
mozilla::UniquePtr<uint8_t[]> mSniffingBuffer;
|
||||
|
||||
/**
|
||||
* The number of meaningful bytes in mSniffingBuffer
|
||||
|
@ -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<nsIContent*[]>(NS_HTML5_TREE_BUILDER_HANDLE_ARRAY_LENGTH);
|
||||
mHandlesUsed = 0;
|
||||
}
|
||||
#ifdef DEBUG
|
||||
|
@ -14,9 +14,9 @@
|
||||
nsTArray<nsHtml5TreeOperation> mOpQueue;
|
||||
nsTArray<nsHtml5SpeculativeLoad> mSpeculativeLoadQueue;
|
||||
nsAHtml5TreeOpSink* mOpSink;
|
||||
nsAutoArrayPtr<nsIContent*> mHandles;
|
||||
mozilla::UniquePtr<nsIContent*[]> mHandles;
|
||||
int32_t mHandlesUsed;
|
||||
nsTArray<nsAutoArrayPtr<nsIContent*> > mOldHandles;
|
||||
nsTArray<mozilla::UniquePtr<nsIContent*[]>> mOldHandles;
|
||||
nsHtml5TreeOpStage* mSpeculativeLoadStage;
|
||||
nsresult mBroken;
|
||||
bool mCurrentHtmlScriptIsAsyncOrDefer;
|
||||
|
Loading…
Reference in New Issue
Block a user