Optimize array capacity settings in style and SVG processing classes

This commit is contained in:
wuggy 2026-04-26 11:07:52 -07:00
commit cd020e380d
3 changed files with 6 additions and 2 deletions

View file

@ -530,7 +530,7 @@ nsStyleSet::GatherRuleProcessors(SheetType aType)
scope->SetIsScopedStyleRoot();
// Create a rule processor for the scope.
nsTArray<RefPtr<CSSStyleSheet>> sheetsForScope;
nsTArray<RefPtr<CSSStyleSheet>> sheetsForScope(end - start);
sheetsForScope.AppendElements(sheets.Elements() + start, end - start);
nsCSSRuleProcessor* oldRP = oldScopedRuleProcessorHash.Get(scope);
mScopedDocSheetRuleProcessors.AppendElement

View file

@ -409,7 +409,7 @@ nsCSSFilterInstance::SetBounds(FilterPrimitiveDescription& aDescr,
nsIntRect inputBounds = (inputIndex < 0) ?
mTargetBoundsInFilterSpace : aPrimitiveDescrs[inputIndex].PrimitiveSubregion();
nsTArray<nsIntRegion> inputExtents;
AutoTArray<nsIntRegion, 1> inputExtents;
inputExtents.AppendElement(inputBounds);
nsIntRegion outputExtents =

View file

@ -670,6 +670,7 @@ nsSVGEffects::EffectProperties::GetMaskFrames()
bool ok = false;
const nsTArray<RefPtr<nsSVGPaintingProperty>>& props = mMask->GetProps();
result.SetCapacity(props.Length());
for (size_t i = 0; i < props.Length(); i++) {
nsSVGMaskFrame* maskFrame =
static_cast<nsSVGMaskFrame *>(props[i]->GetReferencedFrame(
@ -731,6 +732,7 @@ nsSVGRenderingObserverList::InvalidateAll()
return;
AutoTArray<nsSVGRenderingObserver*,10> observers;
observers.SetCapacity(mObservers.Count());
for (auto it = mObservers.Iter(); !it.Done(); it.Next()) {
observers.AppendElement(it.Get()->GetKey());
@ -749,6 +751,7 @@ nsSVGRenderingObserverList::InvalidateAllForReflow()
return;
AutoTArray<nsSVGRenderingObserver*,10> observers;
observers.SetCapacity(mObservers.Count());
for (auto it = mObservers.Iter(); !it.Done(); it.Next()) {
nsSVGRenderingObserver* obs = it.Get()->GetKey();
@ -767,6 +770,7 @@ void
nsSVGRenderingObserverList::RemoveAll()
{
AutoTArray<nsSVGRenderingObserver*,10> observers;
observers.SetCapacity(mObservers.Count());
for (auto it = mObservers.Iter(); !it.Done(); it.Next()) {
observers.AppendElement(it.Get()->GetKey());