mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-27 04:38:02 +00:00

The IPDL compiler generates code like this in DestroySubtree methods: // Recursively shutting down PAPZ kids nsTArray<PAPZChild*> kids((mManagedPAPZChild).Count()); // Accumulate kids into a stable structure to iterate over ManagedPAPZChild(kids); for (uint32_t i = 0; (i) < ((kids).Length()); (++(i))) { // Guarding against a child removing a sibling from the list during the iteration. if ((mManagedPAPZChild).Contains(kids[i])) { (kids[i])->DestroySubtree(subtreewhy); } } There are three problems with this code: 1) We initialize |kids| with a capacity, which is wasted work; ManagedPAPZChild() is going to resize the array for us anyway. 2) We're constantly reading from |kids.Length()| in the loop, when we only really need to read from it once. 3) We're repeatedly accessing kids[i], and doing needless bounds checks. Let's fix those three problems.