本文整理汇总了C++中nsTArray::SetLength方法的典型用法代码示例。如果您正苦于以下问题:C++ nsTArray::SetLength方法的具体用法?C++ nsTArray::SetLength怎么用?C++ nsTArray::SetLength使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nsTArray
的用法示例。
在下文中一共展示了nsTArray::SetLength方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
void
LayerManager::StopFrameTimeRecording(uint32_t aStartIndex,
nsTArray<float>& aFrameIntervals,
nsTArray<float>& aPaintTimes)
{
uint32_t bufferSize = mRecording.mIntervals.Length();
uint32_t length = mRecording.mNextIndex - aStartIndex;
if (mRecording.mIsPaused || length > bufferSize || aStartIndex < mRecording.mCurrentRunStartIndex) {
// aStartIndex is too old. Also if aStartIndex was issued before mRecordingNextIndex overflowed (uint32_t)
// and stopped after the overflow (would happen once every 828 days of constant 60fps).
length = 0;
}
// Set length in advance to avoid possibly repeated reallocations (and OOM checks).
if (!length || !aFrameIntervals.SetLength(length) || !aPaintTimes.SetLength(length)) {
aFrameIntervals.Clear();
aPaintTimes.Clear();
return; // empty recording or OOM, return empty arrays.
}
uint32_t cyclicPos = aStartIndex % bufferSize;
for (uint32_t i = 0; i < length; i++, cyclicPos++) {
if (cyclicPos == bufferSize) {
cyclicPos = 0;
}
aFrameIntervals[i] = mRecording.mIntervals[cyclicPos];
aPaintTimes[i] = mRecording.mPaints[cyclicPos];
}
}
示例2: Initialize
bool DWriteFontFileStream::Initialize(uint8_t* aData, uint32_t aSize) {
if (!mData.SetLength(aSize, fallible)) {
return false;
}
memcpy(mData.Elements(), aData, aSize);
return true;
}
示例3: return
bool
ReadIntoArray(nsIFile* aFile,
nsTArray<uint8_t>& aOutDst,
size_t aMaxLength)
{
if (!FileExists(aFile)) {
return false;
}
PRFileDesc* fd = nullptr;
nsresult rv = aFile->OpenNSPRFileDesc(PR_RDONLY, 0, &fd);
if (NS_FAILED(rv)) {
return false;
}
int32_t length = PR_Seek(fd, 0, PR_SEEK_END);
PR_Seek(fd, 0, PR_SEEK_SET);
if (length < 0 || (size_t)length > aMaxLength) {
NS_WARNING("EME file is longer than maximum allowed length");
PR_Close(fd);
return false;
}
aOutDst.SetLength(length);
int32_t bytesRead = PR_Read(fd, aOutDst.Elements(), length);
PR_Close(fd);
return (bytesRead == length);
}
示例4: addContinuation
// add a continuation, return false on error if segment already has been seen
bool addContinuation(nsTArray<Continuation>& aArray, uint32_t aIndex,
const char *aValue, uint32_t aLength,
bool aNeedsPercentDecoding, bool aWasQuotedString)
{
if (aIndex < aArray.Length() && aArray[aIndex].value) {
NS_WARNING("duplicate RC2231 continuation segment #\n");
return false;
}
if (aIndex > MAX_CONTINUATIONS) {
NS_WARNING("RC2231 continuation segment # exceeds limit\n");
return false;
}
if (aNeedsPercentDecoding && aWasQuotedString) {
NS_WARNING("RC2231 continuation segment can't use percent encoding and quoted string form at the same time\n");
return false;
}
Continuation cont(aValue, aLength, aNeedsPercentDecoding, aWasQuotedString);
if (aArray.Length() <= aIndex) {
aArray.SetLength(aIndex + 1);
}
aArray[aIndex] = cont;
return true;
}
示例5:
// Getter for weighted regions: { top, bottom, left, right, weight }
nsresult
nsDOMCameraControl::Get(uint32_t aKey, nsTArray<CameraRegion>& aValue)
{
nsTArray<ICameraControl::Region> regionArray;
nsresult rv = mCameraControl->Get(aKey, regionArray);
NS_ENSURE_SUCCESS(rv, rv);
uint32_t length = regionArray.Length();
DOM_CAMERA_LOGI("%s:%d : got %d regions\n", __func__, __LINE__, length);
aValue.SetLength(length);
for (uint32_t i = 0; i < length; ++i) {
ICameraControl::Region& r = regionArray[i];
CameraRegion& v = aValue[i];
v.mTop = r.top;
v.mLeft = r.left;
v.mBottom = r.bottom;
v.mRight = r.right;
v.mWeight = r.weight;
DOM_CAMERA_LOGI("region %d: top=%d, left=%d, bottom=%d, right=%d, weight=%u\n",
i,
v.mTop,
v.mLeft,
v.mBottom,
v.mRight,
v.mWeight
);
}
return NS_OK;
}
示例6: GetNumberOfChars
void
nsSVGTextContainerFrame::CopyPositionList(nsTArray<float> *parentList,
SVGUserUnitList *selfList,
nsTArray<float> &dstList,
uint32_t aOffset)
{
dstList.Clear();
uint32_t strLength = GetNumberOfChars();
uint32_t parentCount = 0;
if (parentList && parentList->Length() > aOffset) {
parentCount = NS_MIN(parentList->Length() - aOffset, strLength);
}
uint32_t selfCount = NS_MIN(selfList->Length(), strLength);
uint32_t count = NS_MAX(parentCount, selfCount);
if (!dstList.SetLength(count))
return;
for (uint32_t i = 0; i < selfCount; i++) {
dstList[i] = (*selfList)[i];
}
for (uint32_t i = selfCount; i < parentCount; i++) {
dstList[i] = (*parentList)[aOffset + i];
}
}
示例7: DoConversion
void detail::DoConversion(const nsTArray<nsString> &aUTF16Array,
nsTArray<nsCString> &aUTF8Array) {
uint32_t count = aUTF16Array.Length();
aUTF8Array.SetLength(count);
for (uint32_t i = 0; i < count; ++i)
CopyUTF16toUTF8(aUTF16Array[i], aUTF8Array[i]);
}
示例8: font
nsresult
GDIFontEntry::CopyFontTable(uint32_t aTableTag, nsTArray<uint8_t>& aBuffer)
{
if (!IsTrueType()) {
return NS_ERROR_FAILURE;
}
AutoDC dc;
AutoSelectFont font(dc.GetDC(), &mLogFont);
if (font.IsValid()) {
uint32_t tableSize =
::GetFontData(dc.GetDC(),
NativeEndian::swapToBigEndian(aTableTag),
0, nullptr, 0);
if (tableSize != GDI_ERROR) {
if (aBuffer.SetLength(tableSize, fallible)) {
::GetFontData(dc.GetDC(),
NativeEndian::swapToBigEndian(aTableTag), 0,
aBuffer.Elements(), tableSize);
return NS_OK;
}
return NS_ERROR_OUT_OF_MEMORY;
}
}
return NS_ERROR_FAILURE;
}
示例9: Read
GMPErr Read(const nsCString& aRecordName,
nsTArray<uint8_t>& aOutBytes) override
{
if (!IsOpen(aRecordName)) {
return GMPClosedErr;
}
Record* record = nullptr;
mRecords.Get(aRecordName, &record);
MOZ_ASSERT(record && !!record->mFileDesc); // IsOpen() guarantees this.
// Our error strategy is to report records with invalid contents as
// containing 0 bytes. Zero length records are considered "deleted" by
// the GMPStorage API.
aOutBytes.SetLength(0);
int32_t recordLength = 0;
nsCString recordName;
nsresult err = ReadRecordMetadata(record->mFileDesc,
recordLength,
recordName);
if (NS_FAILED(err) || recordLength == 0) {
// We failed to read the record metadata. Or the record is 0 length.
// Treat damaged records as empty.
// ReadRecordMetadata() could fail if the GMP opened a new record and
// tried to read it before anything was written to it..
return GMPNoErr;
}
if (!aRecordName.Equals(recordName)) {
NS_WARNING("Record file contains some other record's contents!");
return GMPRecordCorrupted;
}
// After calling ReadRecordMetadata, we should be ready to read the
// record data.
if (PR_Available(record->mFileDesc) != recordLength) {
NS_WARNING("Record file length mismatch!");
return GMPRecordCorrupted;
}
aOutBytes.SetLength(recordLength);
int32_t bytesRead = PR_Read(record->mFileDesc, aOutBytes.Elements(), recordLength);
return (bytesRead == recordLength) ? GMPNoErr : GMPRecordCorrupted;
}
示例10: ExtractDisplayAddresses
void ExtractDisplayAddresses(const nsCOMArray<msgIAddressObject> &aHeader,
nsTArray<nsString> &displayAddrs) {
uint32_t count = aHeader.Length();
displayAddrs.SetLength(count);
for (uint32_t i = 0; i < count; i++) aHeader[i]->ToString(displayAddrs[i]);
if (count == 1 && displayAddrs[0].IsEmpty()) displayAddrs.Clear();
}
示例11:
/* static */ bool
PushUtil::CopyArrayBufferToArray(const ArrayBuffer& aBuffer,
nsTArray<uint8_t>& aArray)
{
aBuffer.ComputeLengthAndData();
return aArray.SetLength(aBuffer.Length(), fallible) &&
aArray.ReplaceElementsAt(0, aBuffer.Length(), aBuffer.Data(),
aBuffer.Length(), fallible);
}
示例12: AudioChannelsUpMix
void
AudioNodeStream::UpMixDownMixChunk(const AudioChunk* aChunk,
uint32_t aOutputChannelCount,
nsTArray<const void*>& aOutputChannels,
nsTArray<float>& aDownmixBuffer)
{
static const float silenceChannel[WEBAUDIO_BLOCK_SIZE] = {0.f};
aOutputChannels.AppendElements(aChunk->mChannelData);
if (aOutputChannels.Length() < aOutputChannelCount) {
if (mChannelInterpretation == ChannelInterpretation::Speakers) {
AudioChannelsUpMix(&aOutputChannels, aOutputChannelCount, nullptr);
NS_ASSERTION(aOutputChannelCount == aOutputChannels.Length(),
"We called GetAudioChannelsSuperset to avoid this");
} else {
// Fill up the remaining aOutputChannels by zeros
for (uint32_t j = aOutputChannels.Length(); j < aOutputChannelCount; ++j) {
aOutputChannels.AppendElement(silenceChannel);
}
}
} else if (aOutputChannels.Length() > aOutputChannelCount) {
if (mChannelInterpretation == ChannelInterpretation::Speakers) {
nsAutoTArray<float*,GUESS_AUDIO_CHANNELS> outputChannels;
outputChannels.SetLength(aOutputChannelCount);
aDownmixBuffer.SetLength(aOutputChannelCount * WEBAUDIO_BLOCK_SIZE);
for (uint32_t j = 0; j < aOutputChannelCount; ++j) {
outputChannels[j] = &aDownmixBuffer[j * WEBAUDIO_BLOCK_SIZE];
}
AudioChannelsDownMix(aOutputChannels, outputChannels.Elements(),
aOutputChannelCount, WEBAUDIO_BLOCK_SIZE);
aOutputChannels.SetLength(aOutputChannelCount);
for (uint32_t j = 0; j < aOutputChannels.Length(); ++j) {
aOutputChannels[j] = outputChannels[j];
}
} else {
// Drop the remaining aOutputChannels
aOutputChannels.RemoveElementsAt(aOutputChannelCount,
aOutputChannels.Length() - aOutputChannelCount);
}
}
}
示例13: ExtractAllAddresses
void ExtractAllAddresses(const nsCOMArray<msgIAddressObject> &aHeader,
nsTArray<nsString> &names,
nsTArray<nsString> &emails) {
uint32_t count = aHeader.Length();
// Prefill arrays before we start
names.SetLength(count);
emails.SetLength(count);
for (uint32_t i = 0; i < count; i++) {
aHeader[i]->GetName(names[i]);
aHeader[i]->GetEmail(emails[i]);
}
if (count == 1 && names[0].IsEmpty() && emails[0].IsEmpty()) {
names.Clear();
emails.Clear();
}
}
示例14: GetRawInputDeviceInfo
bool
GetPreparsedData(HANDLE handle, nsTArray<uint8_t>& data)
{
UINT size;
if (GetRawInputDeviceInfo(handle, RIDI_PREPARSEDDATA, nullptr, &size) == kRawInputError) {
return false;
}
data.SetLength(size);
return GetRawInputDeviceInfo(handle, RIDI_PREPARSEDDATA,
data.Elements(), &size) > 0;
}
示例15: GetWritingMode
void
nsGridContainerFrame::CalculateTrackSizes(const LogicalSize& aPercentageBasis,
const nsStylePosition* aStyle,
nsTArray<TrackSize>& aColSizes,
nsTArray<TrackSize>& aRowSizes)
{
aColSizes.SetLength(mGridColEnd - 1);
aRowSizes.SetLength(mGridRowEnd - 1);
WritingMode wm = GetWritingMode();
InitializeTrackSizes(aPercentageBasis.ISize(wm),
aStyle->mGridTemplateColumns.mMinTrackSizingFunctions,
aStyle->mGridTemplateColumns.mMaxTrackSizingFunctions,
aStyle->mGridAutoColumnsMin,
aStyle->mGridAutoColumnsMax,
aColSizes);
InitializeTrackSizes(aPercentageBasis.BSize(wm),
aStyle->mGridTemplateRows.mMinTrackSizingFunctions,
aStyle->mGridTemplateRows.mMaxTrackSizingFunctions,
aStyle->mGridAutoRowsMin,
aStyle->mGridAutoRowsMax,
aRowSizes);
}