本文整理汇总了C++中nsTArray::InsertElementsAt方法的典型用法代码示例。如果您正苦于以下问题:C++ nsTArray::InsertElementsAt方法的具体用法?C++ nsTArray::InsertElementsAt怎么用?C++ nsTArray::InsertElementsAt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nsTArray
的用法示例。
在下文中一共展示了nsTArray::InsertElementsAt方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: autoFree
// Copies a subscription key buffer into an array.
nsresult
CopySubscriptionKeyToArray(nsIPushSubscription* aSubscription,
const nsAString& aKeyName,
nsTArray<uint8_t>& aKey)
{
uint8_t* keyBuffer = nullptr;
AutoFreeKeyBuffer autoFree(&keyBuffer);
uint32_t keyLen;
nsresult rv = aSubscription->GetKey(aKeyName, &keyLen, &keyBuffer);
if (NS_FAILED(rv)) {
return rv;
}
if (!aKey.SetCapacity(keyLen, fallible) ||
!aKey.InsertElementsAt(0, keyBuffer, keyLen, fallible)) {
return NS_ERROR_OUT_OF_MEMORY;
}
return NS_OK;
}
示例2: SortSubQueueBasedOnStrategy
// This method is a hack to prioritize newly inserted messages,
// without changing the size of the queue. It is required since
// we cannot sort ranges in nsTArray.
nsresult nsAutoSyncState::SortSubQueueBasedOnStrategy(nsTArray<nsMsgKey> &aQueue,
uint32_t aStartingOffset)
{
NS_ASSERTION(aStartingOffset < aQueue.Length(), "*** Starting offset is out of range");
// Copy already downloaded messages into a temporary queue,
// we want to exclude them from the sort.
nsTArray<nsMsgKey> tmpQ;
tmpQ.AppendElements(aQueue.Elements(), aStartingOffset);
// Remove already downloaded messages and sort the resulting queue
aQueue.RemoveElementsAt(0, aStartingOffset);
nsresult rv = SortQueueBasedOnStrategy(aQueue);
// copy excluded messages back
aQueue.InsertElementsAt(0, tmpQ);
return rv;
}