本文整理汇总了C++中nsTArray::SetCapacity方法的典型用法代码示例。如果您正苦于以下问题:C++ nsTArray::SetCapacity方法的具体用法?C++ nsTArray::SetCapacity怎么用?C++ nsTArray::SetCapacity使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nsTArray
的用法示例。
在下文中一共展示了nsTArray::SetCapacity方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetWindowGlobals
void CanonicalBrowsingContext::GetWindowGlobals(
nsTArray<RefPtr<WindowGlobalParent>>& aWindows) {
aWindows.SetCapacity(mWindowGlobals.Count());
for (auto iter = mWindowGlobals.Iter(); !iter.Done(); iter.Next()) {
aWindows.AppendElement(iter.Get()->GetKey());
}
}
示例2: InitInputBuffer
void InitInputBuffer(const GMPEncryptedBufferMetadata* aCrypto,
int64_t aTimestamp,
const uint8_t* aData,
size_t aDataSize,
cdm::InputBuffer &aInputBuffer,
nsTArray<cdm::SubsampleEntry> &aSubsamples)
{
if (aCrypto) {
aInputBuffer.key_id = aCrypto->KeyId();
aInputBuffer.key_id_size = aCrypto->KeyIdSize();
aInputBuffer.iv = aCrypto->IV();
aInputBuffer.iv_size = aCrypto->IVSize();
aInputBuffer.num_subsamples = aCrypto->NumSubsamples();
aSubsamples.SetCapacity(aInputBuffer.num_subsamples);
const uint16_t* clear = aCrypto->ClearBytes();
const uint32_t* cipher = aCrypto->CipherBytes();
for (size_t i = 0; i < aCrypto->NumSubsamples(); i++) {
aSubsamples.AppendElement(cdm::SubsampleEntry(clear[i], cipher[i]));
}
}
aInputBuffer.data = aData;
aInputBuffer.data_size = aDataSize;
aInputBuffer.subsamples = aSubsamples.Elements();
aInputBuffer.timestamp = aTimestamp;
}
示例3: textRect
bool
PuppetWidget::GetCompositionRects(uint32_t& aStartOffset,
nsTArray<LayoutDeviceIntRect>& aTextRectArray,
uint32_t& aTargetCauseOffset)
{
nsRefPtr<TextComposition> textComposition =
IMEStateManager::GetTextCompositionFor(this);
NS_ENSURE_TRUE(textComposition, false);
nsEventStatus status;
aTextRectArray.SetCapacity(textComposition->String().Length());
aStartOffset = textComposition->NativeOffsetOfStartComposition();
aTargetCauseOffset = textComposition->OffsetOfTargetClause();
uint32_t endOffset = textComposition->String().Length() + aStartOffset;
for (uint32_t i = aStartOffset; i < endOffset; i++) {
WidgetQueryContentEvent textRect(true, NS_QUERY_TEXT_RECT, this);
InitEvent(textRect, nullptr);
textRect.InitForQueryTextRect(i, 1);
DispatchEvent(&textRect, status);
NS_ENSURE_TRUE(textRect.mSucceeded, false);
aTextRectArray.AppendElement(textRect.mReply.mRect);
}
return true;
}
示例4:
/* static */ void
SharedMessagePortMessage::FromSharedToMessagesChild(
MessagePortChild* aActor,
const nsTArray<nsRefPtr<SharedMessagePortMessage>>& aData,
nsTArray<MessagePortMessage>& aArray)
{
MOZ_ASSERT(aActor);
MOZ_ASSERT(aArray.IsEmpty());
aArray.SetCapacity(aData.Length());
PBackgroundChild* backgroundManager = aActor->Manager();
MOZ_ASSERT(backgroundManager);
for (auto& data : aData) {
MessagePortMessage* message = aArray.AppendElement();
message->data().SwapElements(data->mData);
const nsTArray<nsRefPtr<BlobImpl>>& blobImpls = data->BlobImpls();
if (!blobImpls.IsEmpty()) {
message->blobsChild().SetCapacity(blobImpls.Length());
for (uint32_t i = 0, len = blobImpls.Length(); i < len; ++i) {
PBlobChild* blobChild =
BackgroundChild::GetOrCreateActorForBlobImpl(backgroundManager,
blobImpls[i]);
message->blobsChild().AppendElement(blobChild);
}
}
message->transferredPorts().AppendElements(data->PortIdentifiers());
}
}
示例5:
void
HTMLOptionsCollection::GetSupportedNames(unsigned aFlags,
nsTArray<nsString>& aNames)
{
if (!(aFlags & JSITER_HIDDEN)) {
return;
}
nsAutoTArray<nsIAtom*, 8> atoms;
for (uint32_t i = 0; i < mElements.Length(); ++i) {
HTMLOptionElement* content = mElements.ElementAt(i);
if (content) {
// Note: HasName means the names is exposed on the document,
// which is false for options, so we don't check it here.
const nsAttrValue* val = content->GetParsedAttr(nsGkAtoms::name);
if (val && val->Type() == nsAttrValue::eAtom) {
nsIAtom* name = val->GetAtomValue();
if (!atoms.Contains(name)) {
atoms.AppendElement(name);
}
}
if (content->HasID()) {
nsIAtom* id = content->GetID();
if (!atoms.Contains(id)) {
atoms.AppendElement(id);
}
}
}
}
aNames.SetCapacity(atoms.Length());
for (uint32_t i = 0; i < atoms.Length(); ++i) {
aNames.AppendElement(nsDependentAtomString(atoms[i]));
}
}
示例6: MoveSignalSlotListTo
void DocGroup::MoveSignalSlotListTo(nsTArray<RefPtr<HTMLSlotElement>>& aDest) {
aDest.SetCapacity(aDest.Length() + mSignalSlotList.Length());
for (RefPtr<HTMLSlotElement>& slot : mSignalSlotList) {
slot->RemovedFromSignalSlotList();
aDest.AppendElement(std::move(slot));
}
mSignalSlotList.Clear();
}
示例7: CHECK
status_t
SampleTable::getSampleCencInfo(
uint32_t sample_index, nsTArray<uint16_t>& clear_sizes,
nsTArray<uint32_t>& cipher_sizes, uint8_t iv[]) {
CHECK(clear_sizes.IsEmpty() && cipher_sizes.IsEmpty());
if (sample_index >= mCencInfoCount) {
ALOGE("cenc info requested for out of range sample index");
return ERROR_MALFORMED;
}
auto& info = mCencInfo[sample_index];
clear_sizes.SetCapacity(info.mSubsampleCount);
cipher_sizes.SetCapacity(info.mSubsampleCount);
for (uint32_t i = 0; i < info.mSubsampleCount; i++) {
clear_sizes.AppendElement(info.mSubsamples[i].mClearBytes);
cipher_sizes.AppendElement(info.mSubsamples[i].mCipherBytes);
}
memcpy(iv, info.mIV, IV_BYTES);
return OK;
}
示例8: lock
void
nsGonkCameraControl::GetParameter(uint32_t aKey, nsTArray<CameraRegion>& aRegions)
{
aRegions.Clear();
const char* key = getKeyText(aKey);
if (!key) {
return;
}
RwAutoLockRead lock(mRwLock);
const char* value = mParams.get(key);
DOM_CAMERA_LOGI("key='%s' --> value='%s'\n", key, value);
if (!value) {
return;
}
const char* p = value;
uint32_t count = 1;
// count the number of regions in the string
while ((p = strstr(p, "),("))) {
++count;
p += 3;
}
aRegions.SetCapacity(count);
CameraRegion* r;
// parse all of the region sets
uint32_t i;
for (i = 0, p = value; p && i < count; ++i, p = strchr(p + 1, '(')) {
r = aRegions.AppendElement();
if (sscanf(p, "(%d,%d,%d,%d,%u)", &r->top, &r->left, &r->bottom, &r->right, &r->weight) != 5) {
DOM_CAMERA_LOGE("%s:%d : region tuple has bad format: '%s'\n", __func__, __LINE__, p);
goto GetParameter_error;
}
}
return;
GetParameter_error:
aRegions.Clear();
}
示例9:
/* static */ void
SharedMessagePortMessage::FromSharedToMessagesChild(
MessagePortChild* aActor,
const nsTArray<RefPtr<SharedMessagePortMessage>>& aData,
nsTArray<ClonedMessageData>& aArray)
{
MOZ_ASSERT(aActor);
MOZ_ASSERT(aArray.IsEmpty());
aArray.SetCapacity(aData.Length());
PBackgroundChild* backgroundManager = aActor->Manager();
MOZ_ASSERT(backgroundManager);
for (auto& data : aData) {
ClonedMessageData* message = aArray.AppendElement();
data->BuildClonedMessageDataForBackgroundChild(backgroundManager, *message);
}
}
示例10: 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;
}
示例11:
// static
bool
SVGTransformListSMILType::GetTransforms(const nsSMILValue& aValue,
nsTArray<SVGTransform>& aTransforms)
{
NS_PRECONDITION(aValue.mType == &sSingleton, "Unexpected SMIL value type");
const TransformArray& smilTransforms =
*static_cast<const TransformArray*>(aValue.mU.mPtr);
aTransforms.Clear();
if (!aTransforms.SetCapacity(smilTransforms.Length()))
return PR_FALSE;
for (PRUint32 i = 0; i < smilTransforms.Length(); ++i) {
// No need to check the return value below since we have already allocated
// the necessary space
aTransforms.AppendElement(smilTransforms[i].ToSVGTransform());
}
return PR_TRUE;
}
示例12: GetImpl
nsresult
GonkCameraParameters::GetTranslated(uint32_t aKey, nsTArray<ICameraControl::Region>& aRegions)
{
aRegions.Clear();
const char* value;
nsresult rv = GetImpl(aKey, value);
if (NS_FAILED(rv)) {
return rv;
}
if (!value || *value == '\0') {
DOM_CAMERA_LOGW("Camera parameter aKey=%d not available\n", aKey);
return NS_ERROR_NOT_AVAILABLE;
}
const char* p = value;
uint32_t count = 1;
// count the number of regions in the string
while ((p = strstr(p, "),("))) {
++count;
p += 3;
}
aRegions.SetCapacity(count);
ICameraControl::Region* r;
// parse all of the region sets
uint32_t i;
for (i = 0, p = value; p && i < count; ++i, p = strchr(p + 1, '(')) {
r = aRegions.AppendElement();
if (sscanf(p, "(%d,%d,%d,%d,%u)", &r->left, &r->top, &r->right, &r->bottom, &r->weight) != 5) {
DOM_CAMERA_LOGE("Camera parameter aKey=%d region tuple has bad format: '%s'\n", aKey, p);
aRegions.Clear();
return NS_ERROR_NOT_AVAILABLE;
}
}
return NS_OK;
}
示例13: sizeof
// Populate an array with the given number of bytes. Data is lorem ipsum
// random text, but deterministic across multiple calls.
void
CreateData(uint32_t aNumBytes, nsTArray<char>& aDataOut)
{
static const char data[] =
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec egestas "
"purus eu condimentum iaculis. In accumsan leo eget odio porttitor, non "
"rhoncus nulla vestibulum. Etiam lacinia consectetur nisl nec "
"sollicitudin. Sed fringilla accumsan diam, pulvinar varius massa. Duis "
"mollis dignissim felis, eget tempus nisi tristique ut. Fusce euismod, "
"lectus non lacinia tempor, tellus diam suscipit quam, eget hendrerit "
"lacus nunc fringilla ante. Sed ultrices massa vitae risus molestie, ut "
"finibus quam laoreet nullam.";
static const uint32_t dataLength = sizeof(data) - 1;
aDataOut.SetCapacity(aNumBytes);
while (aNumBytes > 0) {
uint32_t amount = std::min(dataLength, aNumBytes);
aDataOut.AppendElements(data, amount);
aNumBytes -= amount;
}
}
示例14: while
nsresult
HTMLFormControlsCollection::GetSortedControls(
nsTArray<nsGenericHTMLFormElement*>& aControls) const
{
#ifdef DEBUG
HTMLFormElement::AssertDocumentOrder(mElements, mForm);
HTMLFormElement::AssertDocumentOrder(mNotInElements, mForm);
#endif
aControls.Clear();
// Merge the elements list and the not in elements list. Both lists are
// already sorted.
uint32_t elementsLen = mElements.Length();
uint32_t notInElementsLen = mNotInElements.Length();
aControls.SetCapacity(elementsLen + notInElementsLen);
uint32_t elementsIdx = 0;
uint32_t notInElementsIdx = 0;
while (elementsIdx < elementsLen || notInElementsIdx < notInElementsLen) {
// Check whether we're done with mElements
if (elementsIdx == elementsLen) {
NS_ASSERTION(notInElementsIdx < notInElementsLen,
"Should have remaining not-in-elements");
// Append the remaining mNotInElements elements
if (!aControls.AppendElements(mNotInElements.Elements() +
notInElementsIdx,
notInElementsLen -
notInElementsIdx)) {
return NS_ERROR_OUT_OF_MEMORY;
}
break;
}
// Check whether we're done with mNotInElements
if (notInElementsIdx == notInElementsLen) {
NS_ASSERTION(elementsIdx < elementsLen,
"Should have remaining in-elements");
// Append the remaining mElements elements
if (!aControls.AppendElements(mElements.Elements() +
elementsIdx,
elementsLen -
elementsIdx)) {
return NS_ERROR_OUT_OF_MEMORY;
}
break;
}
// Both lists have elements left.
NS_ASSERTION(mElements[elementsIdx] &&
mNotInElements[notInElementsIdx],
"Should have remaining elements");
// Determine which of the two elements should be ordered
// first and add it to the end of the list.
nsGenericHTMLFormElement* elementToAdd;
if (HTMLFormElement::CompareFormControlPosition(
mElements[elementsIdx], mNotInElements[notInElementsIdx], mForm) < 0) {
elementToAdd = mElements[elementsIdx];
++elementsIdx;
} else {
elementToAdd = mNotInElements[notInElementsIdx];
++notInElementsIdx;
}
// Add the first element to the list.
if (!aControls.AppendElement(elementToAdd)) {
return NS_ERROR_OUT_OF_MEMORY;
}
}
NS_ASSERTION(aControls.Length() == elementsLen + notInElementsLen,
"Not all form controls were added to the sorted list");
#ifdef DEBUG
HTMLFormElement::AssertDocumentOrder(aControls, mForm);
#endif
return NS_OK;
}
示例15: keyframeJSValue
void
KeyframeEffectReadOnly::GetKeyframes(JSContext*& aCx,
nsTArray<JSObject*>& aResult,
ErrorResult& aRv)
{
MOZ_ASSERT(aResult.IsEmpty());
MOZ_ASSERT(!aRv.Failed());
if (!aResult.SetCapacity(mKeyframes.Length(), mozilla::fallible)) {
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
return;
}
for (const Keyframe& keyframe : mKeyframes) {
// Set up a dictionary object for the explicit members
BaseComputedKeyframe keyframeDict;
if (keyframe.mOffset) {
keyframeDict.mOffset.SetValue(keyframe.mOffset.value());
}
MOZ_ASSERT(keyframe.mComputedOffset != Keyframe::kComputedOffsetNotSet,
"Invalid computed offset");
keyframeDict.mComputedOffset.Construct(keyframe.mComputedOffset);
if (keyframe.mTimingFunction) {
keyframeDict.mEasing.Truncate();
keyframe.mTimingFunction.ref().AppendToString(keyframeDict.mEasing);
} // else if null, leave easing as its default "linear".
JS::Rooted<JS::Value> keyframeJSValue(aCx);
if (!ToJSValue(aCx, keyframeDict, &keyframeJSValue)) {
aRv.Throw(NS_ERROR_FAILURE);
return;
}
JS::Rooted<JSObject*> keyframeObject(aCx, &keyframeJSValue.toObject());
for (const PropertyValuePair& propertyValue : keyframe.mPropertyValues) {
const char* name = nsCSSProps::PropertyIDLName(propertyValue.mProperty);
// nsCSSValue::AppendToString does not accept shorthands properties but
// works with token stream values if we pass eCSSProperty_UNKNOWN as
// the property.
nsCSSPropertyID propertyForSerializing =
nsCSSProps::IsShorthand(propertyValue.mProperty)
? eCSSProperty_UNKNOWN
: propertyValue.mProperty;
nsAutoString stringValue;
propertyValue.mValue.AppendToString(
propertyForSerializing, stringValue, nsCSSValue::eNormalized);
JS::Rooted<JS::Value> value(aCx);
if (!ToJSValue(aCx, stringValue, &value) ||
!JS_DefineProperty(aCx, keyframeObject, name, value,
JSPROP_ENUMERATE)) {
aRv.Throw(NS_ERROR_FAILURE);
return;
}
}
aResult.AppendElement(keyframeObject);
}
}