Skip to content

Commit

Permalink
Bug 1653335 - Replace MakeSpan uses by constructor calls. r=froydnj
Browse files Browse the repository at this point in the history
  • Loading branch information
sigiesec committed Aug 7, 2020
1 parent 3c0dcb9 commit 16cc146
Show file tree
Hide file tree
Showing 125 changed files with 428 additions and 455 deletions.
4 changes: 2 additions & 2 deletions dom/base/BodyUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -467,8 +467,8 @@ already_AddRefed<FormData> BodyUtil::ConsumeFormData(nsIGlobalObject* aParent,
// static
nsresult BodyUtil::ConsumeText(uint32_t aInputLength, uint8_t* aInput,
nsString& aText) {
nsresult rv = UTF_8_ENCODING->DecodeWithBOMRemoval(
MakeSpan(aInput, aInputLength), aText);
nsresult rv =
UTF_8_ENCODING->DecodeWithBOMRemoval(Span(aInput, aInputLength), aText);
if (NS_FAILED(rv)) {
return rv;
}
Expand Down
2 changes: 1 addition & 1 deletion dom/base/CharacterData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ nsresult CharacterData::SetTextInternal(
if (aLength) {
to.Append(aBuffer, aLength);
if (!bidi && (!document || !document->GetBidiEnabled())) {
bidi = HasRTLChars(MakeSpan(aBuffer, aLength));
bidi = HasRTLChars(Span(aBuffer, aLength));
}
}
if (endOffset != textLength) {
Expand Down
4 changes: 2 additions & 2 deletions dom/base/DOMParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ already_AddRefed<Document> DOMParser::ParseFromBuffer(const Uint8Array& aBuf,
SupportedType aType,
ErrorResult& aRv) {
aBuf.ComputeState();
return ParseFromBuffer(MakeSpan(aBuf.Data(), aBuf.Length()), aType, aRv);
return ParseFromBuffer(Span(aBuf.Data(), aBuf.Length()), aType, aRv);
}

already_AddRefed<Document> DOMParser::ParseFromBuffer(Span<const uint8_t> aBuf,
Expand All @@ -129,7 +129,7 @@ already_AddRefed<Document> DOMParser::ParseFromBuffer(Span<const uint8_t> aBuf,
nsCOMPtr<nsIInputStream> stream;
nsresult rv = NS_NewByteInputStream(
getter_AddRefs(stream),
MakeSpan(reinterpret_cast<const char*>(aBuf.Elements()), aBuf.Length()),
Span(reinterpret_cast<const char*>(aBuf.Elements()), aBuf.Length()),
NS_ASSIGNMENT_DEPEND);
if (NS_FAILED(rv)) {
aRv.Throw(rv);
Expand Down
2 changes: 1 addition & 1 deletion dom/base/DocumentOrShadowRoot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ void DocumentOrShadowRoot::SetAdoptedStyleSheets(
mAdoptedStyleSheets.SetCapacity(aAdoptedStyleSheets.Length());

// Only add sheets that are not already in the common prefix.
for (const auto& sheet : MakeSpan(aAdoptedStyleSheets).From(commonPrefix)) {
for (const auto& sheet : Span(aAdoptedStyleSheets).From(commonPrefix)) {
if (MOZ_UNLIKELY(!set.EnsureInserted(sheet))) {
// The idea is that this case is rare, so we pay the price of removing the
// old sheet from the styles and append it later rather than the other way
Expand Down
4 changes: 2 additions & 2 deletions dom/base/EventSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -759,8 +759,8 @@ void EventSourceImpl::ParseSegment(const char* aBuffer, uint32_t aLength) {
return;
}
char16_t buffer[1024];
auto dst = MakeSpan(buffer);
auto src = AsBytes(MakeSpan(aBuffer, aLength));
auto dst = Span(buffer);
auto src = AsBytes(Span(aBuffer, aLength));
// XXX EOF handling is https://bugzilla.mozilla.org/show_bug.cgi?id=1369018
for (;;) {
uint32_t result;
Expand Down
22 changes: 11 additions & 11 deletions dom/base/nsContentUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8301,26 +8301,26 @@ class StringBuilder {
EncodeAttrString(*(u.mString), appender);
break;
case Unit::eLiteral:
appender.Append(MakeSpan(u.mLiteral, u.mLength));
appender.Append(Span(u.mLiteral, u.mLength));
break;
case Unit::eTextFragment:
if (u.mTextFragment->Is2b()) {
appender.Append(MakeSpan(u.mTextFragment->Get2b(),
u.mTextFragment->GetLength()));
appender.Append(
Span(u.mTextFragment->Get2b(), u.mTextFragment->GetLength()));
} else {
appender.Append(MakeSpan(u.mTextFragment->Get1b(),
u.mTextFragment->GetLength()));
appender.Append(
Span(u.mTextFragment->Get1b(), u.mTextFragment->GetLength()));
}
break;
case Unit::eTextFragmentWithEncode:
if (u.mTextFragment->Is2b()) {
EncodeTextFragment(MakeSpan(u.mTextFragment->Get2b(),
u.mTextFragment->GetLength()),
appender);
EncodeTextFragment(
Span(u.mTextFragment->Get2b(), u.mTextFragment->GetLength()),
appender);
} else {
EncodeTextFragment(MakeSpan(u.mTextFragment->Get1b(),
u.mTextFragment->GetLength()),
appender);
EncodeTextFragment(
Span(u.mTextFragment->Get1b(), u.mTextFragment->GetLength()),
appender);
}
break;
default:
Expand Down
4 changes: 2 additions & 2 deletions dom/base/nsDocumentEncoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ nsresult TextStreamer::EncodeAndWrite() {
}

uint8_t buffer[kEncoderBufferSizeInBytes];
auto src = MakeSpan(mOutputBuffer);
auto bufferSpan = MakeSpan(buffer);
auto src = Span(mOutputBuffer);
auto bufferSpan = Span(buffer);
// Reserve space for terminator
auto dst = bufferSpan.To(bufferSpan.Length() - 1);
for (;;) {
Expand Down
14 changes: 6 additions & 8 deletions dom/base/nsTextFragment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,7 @@ bool nsTextFragment::SetTo(const char16_t* aBuffer, int32_t aLength,
}

// Copy data
LossyConvertUtf16toLatin1(MakeSpan(aBuffer, aLength),
MakeSpan(buff, aLength));
LossyConvertUtf16toLatin1(Span(aBuffer, aLength), Span(buff, aLength));
m1b = buff;
mState.mIs2b = false;
}
Expand Down Expand Up @@ -344,7 +343,7 @@ void nsTextFragment::CopyTo(char16_t* aDest, int32_t aOffset, int32_t aCount) {
memcpy(aDest, Get2b() + aOffset, sizeof(char16_t) * aCount);
} else {
const char* cp = m1b + aOffset;
ConvertLatin1toUtf16(MakeSpan(cp, aCount), MakeSpan(aDest, aCount));
ConvertLatin1toUtf16(Span(cp, aCount), Span(aDest, aCount));
}
}
}
Expand Down Expand Up @@ -429,8 +428,7 @@ bool nsTextFragment::Append(const char16_t* aBuffer, uint32_t aLength,

// Copy data into buff
char16_t* data = static_cast<char16_t*>(buff->Data());
ConvertLatin1toUtf16(MakeSpan(m1b, mState.mLength),
MakeSpan(data, mState.mLength));
ConvertLatin1toUtf16(Span(m1b, mState.mLength), Span(data, mState.mLength));

memcpy(data + mState.mLength, aBuffer, aLength * sizeof(char16_t));
mState.mLength += aLength;
Expand Down Expand Up @@ -471,8 +469,8 @@ bool nsTextFragment::Append(const char16_t* aBuffer, uint32_t aLength,
}

// Copy aBuffer into buff.
LossyConvertUtf16toLatin1(MakeSpan(aBuffer, aLength),
MakeSpan(buff + mState.mLength, aLength));
LossyConvertUtf16toLatin1(Span(aBuffer, aLength),
Span(buff + mState.mLength, aLength));

m1b = buff;
mState.mLength += aLength;
Expand All @@ -498,7 +496,7 @@ size_t nsTextFragment::SizeOfExcludingThis(
// every allocation
void nsTextFragment::UpdateBidiFlag(const char16_t* aBuffer, uint32_t aLength) {
if (mState.mIs2b && !mState.mIsBidi) {
if (HasRTLChars(MakeSpan(aBuffer, aLength))) {
if (HasRTLChars(Span(aBuffer, aLength))) {
mState.mIsBidi = true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion dom/base/nsXMLContentSerializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ nsresult nsXMLContentSerializer::AppendTextData(nsIContent* aNode,
}
} else {
nsAutoString utf16;
if (!CopyASCIItoUTF16(MakeSpan(frag->Get1b() + aStartOffset, length), utf16,
if (!CopyASCIItoUTF16(Span(frag->Get1b() + aStartOffset, length), utf16,
mozilla::fallible_t())) {
return NS_ERROR_OUT_OF_MEMORY;
}
Expand Down
2 changes: 1 addition & 1 deletion dom/bindings/BindingUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2624,7 +2624,7 @@ bool NormalizeUSVString(binding_detail::FakeString<char16_t>& aString) {
}

char16_t* ptr = aString.BeginWriting();
auto span = MakeSpan(ptr, len);
auto span = Span(ptr, len);
span[upTo] = 0xFFFD;
EnsureUtf16ValiditySpan(span.From(upTo + 1));
return true;
Expand Down
2 changes: 1 addition & 1 deletion dom/encoding/TextDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ void TextDecoder::Decode(const Optional<ArrayBufferViewOrArrayBuffer>& aBuffer,
data = buf.GetAsArrayBuffer().Data();
length = buf.GetAsArrayBuffer().Length();
}
Decode(MakeSpan(data, length), aOptions.mStream, aOutDecodedString, aRv);
Decode(Span(data, length), aOptions.mStream, aOutDecodedString, aRv);
}

void TextDecoder::GetEncoding(nsAString& aEncoding) {
Expand Down
2 changes: 1 addition & 1 deletion dom/encoding/TextEncoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ void TextEncoder::EncodeInto(JSContext* aCx, JS::Handle<JSString*> aSrc,
size_t read;
size_t written;
auto maybe = JS_EncodeStringToUTF8BufferPartial(
aCx, aSrc, AsWritableChars(MakeSpan(aDst.Data(), aDst.Length())));
aCx, aSrc, AsWritableChars(Span(aDst.Data(), aDst.Length())));
if (!maybe) {
aError.ReportOOM();
return;
Expand Down
11 changes: 5 additions & 6 deletions dom/events/DataTransfer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1062,7 +1062,7 @@ already_AddRefed<nsITransferable> DataTransfer::GetTransferable(
type.Length() * sizeof(nsString::char_type),
"Why is formatLength off?");
rv = stream->WriteBytes(
AsBytes(MakeSpan(type.BeginReading(), type.Length())));
AsBytes(Span(type.BeginReading(), type.Length())));
if (NS_WARN_IF(NS_FAILED(rv))) {
totalCustomLength = 0;
continue;
Expand All @@ -1076,9 +1076,9 @@ already_AddRefed<nsITransferable> DataTransfer::GetTransferable(
// length of "data" if the variant contained an nsISupportsString
// as VTYPE_INTERFACE, say. We used lengthInBytes above for
// sizing, so just keep doing that.
rv = stream->WriteBytes(MakeSpan(
reinterpret_cast<const uint8_t*>(data.BeginReading()),
lengthInBytes));
rv = stream->WriteBytes(
Span(reinterpret_cast<const uint8_t*>(data.BeginReading()),
lengthInBytes));
if (NS_WARN_IF(NS_FAILED(rv))) {
totalCustomLength = 0;
continue;
Expand Down Expand Up @@ -1492,8 +1492,7 @@ void DataTransfer::FillInExternalCustomTypes(nsIVariant* aData, uint32_t aIndex,

nsCOMPtr<nsIInputStream> stringStream;
NS_NewByteInputStream(getter_AddRefs(stringStream),
MakeSpan(chrs, checkedLen.value()),
NS_ASSIGNMENT_ADOPT);
Span(chrs, checkedLen.value()), NS_ASSIGNMENT_ADOPT);

nsCOMPtr<nsIObjectInputStream> stream = NS_NewObjectInputStream(stringStream);

Expand Down
2 changes: 1 addition & 1 deletion dom/fetch/BodyExtractor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ static nsresult GetBufferDataAsStream(

nsCOMPtr<nsIInputStream> stream;
nsresult rv = NS_NewByteInputStream(
getter_AddRefs(stream), MakeSpan(data, aDataLength), NS_ASSIGNMENT_COPY);
getter_AddRefs(stream), Span(data, aDataLength), NS_ASSIGNMENT_COPY);
NS_ENSURE_SUCCESS(rv, rv);

stream.forget(aResult);
Expand Down
4 changes: 2 additions & 2 deletions dom/file/FileReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ namespace {
void PopulateBufferForBinaryString(char16_t* aDest, const char* aSource,
uint32_t aCount) {
// Zero-extend each char to char16_t.
ConvertLatin1toUtf16(MakeSpan(aSource, aCount), MakeSpan(aDest, aCount));
ConvertLatin1toUtf16(Span(aSource, aCount), Span(aDest, aCount));
}

nsresult ReadFuncBinaryString(nsIInputStream* aInputStream, void* aClosure,
Expand Down Expand Up @@ -468,7 +468,7 @@ nsresult FileReader::GetAsText(Blob* aBlob, const nsACString& aCharset,
}
}

auto data = MakeSpan(reinterpret_cast<const uint8_t*>(aFileData), aDataLen);
auto data = Span(reinterpret_cast<const uint8_t*>(aFileData), aDataLen);
nsresult rv;
Tie(rv, encoding) = encoding->Decode(data, aResult);
return NS_FAILED(rv) ? rv : NS_OK;
Expand Down
2 changes: 1 addition & 1 deletion dom/file/MemoryBlobImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ nsresult MemoryBlobImpl::DataOwnerAdapter::Create(DataOwner* aDataOwner,

rv = NS_NewByteInputStream(
getter_AddRefs(stream),
MakeSpan(static_cast<const char*>(aDataOwner->mData) + aStart, aLength),
Span(static_cast<const char*>(aDataOwner->mData) + aStart, aLength),
NS_ASSIGNMENT_DEPEND);
NS_ENSURE_SUCCESS(rv, rv);

Expand Down
5 changes: 2 additions & 3 deletions dom/indexedDB/ActorsParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -894,7 +894,7 @@ nsresult ReadCompressedIndexDataValuesFromSource(
return NS_ERROR_FILE_CORRUPTED;
}

rv = ReadCompressedIndexDataValuesFromBlob(MakeSpan(blobData, blobDataLength),
rv = ReadCompressedIndexDataValuesFromBlob(Span(blobData, blobDataLength),
aOutIndexValues);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
Expand Down Expand Up @@ -3580,8 +3580,7 @@ UpgradeIndexDataValuesFunction::OnFunctionCall(
return rv;
}

auto oldIdvOrErr =
ReadOldCompressedIDVFromBlob(MakeSpan(oldBlob, oldBlobLength));
auto oldIdvOrErr = ReadOldCompressedIDVFromBlob(Span(oldBlob, oldBlobLength));
if (NS_WARN_IF(oldIdvOrErr.isErr())) {
return oldIdvOrErr.unwrapErr();
}
Expand Down
2 changes: 1 addition & 1 deletion dom/jsurl/nsJSProtocolHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ nsresult nsJSThunk::EvaluateScript(
aChannel->SetContentCharset(*charset);
if (bytes)
rv = NS_NewByteInputStream(getter_AddRefs(mInnerStream),
mozilla::MakeSpan(bytes, bytesLen),
mozilla::Span(bytes, bytesLen),
NS_ASSIGNMENT_ADOPT);
else
rv = NS_ERROR_OUT_OF_MEMORY;
Expand Down
4 changes: 2 additions & 2 deletions dom/media/AudioStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -606,8 +606,8 @@ long AudioStream::DataCallback(void* aBuffer, long aFrames) {
}

auto writer = AudioBufferWriter(
MakeSpan<AudioDataValue>(reinterpret_cast<AudioDataValue*>(aBuffer),
mOutChannels * aFrames),
Span<AudioDataValue>(reinterpret_cast<AudioDataValue*>(aBuffer),
mOutChannels * aFrames),
mOutChannels, aFrames);

if (mPrefillQuirk) {
Expand Down
4 changes: 2 additions & 2 deletions dom/media/DynamicResampler.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ class DynamicResampler final {
}

if (mInRate == mOutRate) {
mInternalInBuffer[aChannelIndex].Read(MakeSpan(aOutBuffer, *aOutFrames));
mInternalInBuffer[aChannelIndex].Read(Span(aOutBuffer, *aOutFrames));
// Workaround to avoid discontinuity when the speex resampler operates
// again. Feed it with the last 20 frames to warm up the internal memory
// of the resampler and then skip memory equals to resampler's input
Expand Down Expand Up @@ -176,7 +176,7 @@ class DynamicResampler final {
MOZ_ASSERT(aChannelIndex >= 0);
MOZ_ASSERT(aChannelIndex <= mChannels);
MOZ_ASSERT((uint32_t)aChannelIndex <= mInternalInBuffer.Length());
mInternalInBuffer[aChannelIndex].Write(MakeSpan(aInBuffer, aInFrames));
mInternalInBuffer[aChannelIndex].Write(Span(aInBuffer, aInFrames));
}

void WarmUpResampler(bool aSkipLatency);
Expand Down
18 changes: 9 additions & 9 deletions dom/media/MediaCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2009,13 +2009,13 @@ void MediaCacheStream::NotifyDataReceived(uint32_t aLoadID, uint32_t aCount,
// True if we commit any blocks to the cache.
bool cacheUpdated = false;

auto source = MakeSpan<const uint8_t>(aData, aCount);
auto source = Span<const uint8_t>(aData, aCount);

// We process the data one block (or part of a block) at a time
while (!source.IsEmpty()) {
// The data we've collected so far in the partial block.
auto partial = MakeSpan<const uint8_t>(mPartialBlockBuffer.get(),
OffsetInBlock(mChannelOffset));
auto partial = Span<const uint8_t>(mPartialBlockBuffer.get(),
OffsetInBlock(mChannelOffset));

if (partial.IsEmpty()) {
// We've just started filling this buffer so now is a good time
Expand All @@ -2037,8 +2037,8 @@ void MediaCacheStream::NotifyDataReceived(uint32_t aLoadID, uint32_t aCount,
cacheUpdated = true;
} else {
// The buffer to be filled in the partial block.
auto buf = MakeSpan<uint8_t>(mPartialBlockBuffer.get() + partial.Length(),
remaining);
auto buf = Span<uint8_t>(mPartialBlockBuffer.get() + partial.Length(),
remaining);
memcpy(buf.Elements(), source.Elements(), source.Length());
mChannelOffset += source.Length();
break;
Expand Down Expand Up @@ -2078,7 +2078,7 @@ void MediaCacheStream::FlushPartialBlockInternal(AutoLock& aLock,
// Write back the partial block
memset(mPartialBlockBuffer.get() + blockOffset, 0,
BLOCK_SIZE - blockOffset);
auto data = MakeSpan<const uint8_t>(mPartialBlockBuffer.get(), BLOCK_SIZE);
auto data = Span<const uint8_t>(mPartialBlockBuffer.get(), BLOCK_SIZE);
mMediaCache->AllocateAndWriteBlock(
aLock, this, blockIndex,
mMetadataInPartialBlockBuffer ? MODE_METADATA : MODE_PLAYBACK, data);
Expand Down Expand Up @@ -2458,7 +2458,7 @@ uint32_t MediaCacheStream::ReadPartialBlock(AutoLock&, int64_t aOffset,
return 0;
}

auto source = MakeSpan<const uint8_t>(
auto source = Span<const uint8_t>(
mPartialBlockBuffer.get() + OffsetInBlock(aOffset),
OffsetInBlock(mChannelOffset) - OffsetInBlock(aOffset));
// We have |source.Length() <= BLOCK_SIZE < INT32_MAX| to guarantee
Expand Down Expand Up @@ -2529,7 +2529,7 @@ nsresult MediaCacheStream::Read(AutoLock& aLock, char* aBuffer, uint32_t aCount,
auto streamOffset = mStreamOffset;

// The buffer we are about to fill.
auto buffer = MakeSpan<char>(aBuffer, aCount);
auto buffer = Span<char>(aBuffer, aCount);

// Read one block (or part of a block) at a time
while (!buffer.IsEmpty()) {
Expand Down Expand Up @@ -2634,7 +2634,7 @@ nsresult MediaCacheStream::ReadFromCache(char* aBuffer, int64_t aOffset,
AutoLock lock(mMediaCache->Monitor());

// The buffer we are about to fill.
auto buffer = MakeSpan<char>(aBuffer, aCount);
auto buffer = Span<char>(aBuffer, aCount);

// Read one block (or part of a block) at a time
int64_t streamOffset = aOffset;
Expand Down
Loading

0 comments on commit 16cc146

Please sign in to comment.