Bug 1353618 - Optimize storage of MozPromise::mThenValues.
1. Set the capacity to 1 when IsExclusive is true.
2. Set it to 3 because Try shows we never have more the 3 elements when IsExclusive is false.
MozReview-Commit-ID: dmIeE6ZTeh
--- a/xpcom/threads/MozPromise.h
+++ b/xpcom/threads/MozPromise.h
@@ -921,17 +921,19 @@ protected:
};
const char* mCreationSite; // For logging
Mutex mMutex;
ResolveOrRejectValue mValue;
#ifdef PROMISE_DEBUG
uint32_t mMagic1 = sMagic;
#endif
- nsTArray<RefPtr<ThenValueBase>> mThenValues;
+ // Try shows we never have more than 3 elements when IsExclusive is false.
+ // So '3' is a good value to avoid heap allocation in most cases.
+ AutoTArray<RefPtr<ThenValueBase>, IsExclusive ? 1 : 3> mThenValues;
#ifdef PROMISE_DEBUG
uint32_t mMagic2 = sMagic;
#endif
nsTArray<RefPtr<Private>> mChainedPromises;
#ifdef PROMISE_DEBUG
uint32_t mMagic3 = sMagic;
#endif
bool mHaveRequest;