本文整理汇总了C++中Span::Length方法的典型用法代码示例。如果您正苦于以下问题:C++ Span::Length方法的具体用法?C++ Span::Length怎么用?C++ Span::Length使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Span
的用法示例。
在下文中一共展示了Span::Length方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: lock
nsresult
MemoryBlockCache::WriteBlock(uint32_t aBlockIndex,
Span<const uint8_t> aData1,
Span<const uint8_t> aData2)
{
MutexAutoLock lock(mMutex);
size_t offset = BlockIndexToOffset(aBlockIndex);
if (offset + aData1.Length() + aData2.Length() > mBuffer.Length() &&
!mHasGrown) {
LOG("WriteBlock() MEMORYBLOCKCACHE_ERRORS='WriteBlockOverflow'");
Telemetry::Accumulate(Telemetry::HistogramID::MEMORYBLOCKCACHE_ERRORS,
WriteBlockOverflow);
}
if (!EnsureBufferCanContain(offset + aData1.Length() + aData2.Length())) {
LOG("WriteBlock() MEMORYBLOCKCACHE_ERRORS='WriteBlockCannotGrow'");
Telemetry::Accumulate(Telemetry::HistogramID::MEMORYBLOCKCACHE_ERRORS,
WriteBlockCannotGrow);
return NS_ERROR_FAILURE;
}
memcpy(mBuffer.Elements() + offset, aData1.Elements(), aData1.Length());
if (aData2.Length() > 0) {
memcpy(mBuffer.Elements() + offset + aData1.Length(),
aData2.Elements(),
aData2.Length());
}
return NS_OK;
}
示例2: ParseFromStream
already_AddRefed<nsIDocument>
DOMParser::ParseFromBuffer(Span<const uint8_t> aBuf, SupportedType aType,
ErrorResult& aRv)
{
// The new stream holds a reference to the buffer
nsCOMPtr<nsIInputStream> stream;
nsresult rv = NS_NewByteInputStream(getter_AddRefs(stream),
reinterpret_cast<const char *>(aBuf.Elements()),
aBuf.Length(), NS_ASSIGNMENT_DEPEND);
if (NS_FAILED(rv)) {
aRv.Throw(rv);
return nullptr;
}
return ParseFromStream(stream, VoidString(), aBuf.Length(), aType, aRv);
}