From 0746eb9600f6d3bc07972352d688729d2a2c86ea Mon Sep 17 00:00:00 2001 From: Benoit Jacob Date: Thu, 29 May 2014 11:59:37 -0400 Subject: [PATCH] Bug 852393 - Specialize nsAutoTArray to be an nsTArray - r=froydnj --- xpcom/glue/nsTArray.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/xpcom/glue/nsTArray.h b/xpcom/glue/nsTArray.h index 643bfafa5a3..01b78e7afe3 100644 --- a/xpcom/glue/nsTArray.h +++ b/xpcom/glue/nsTArray.h @@ -1696,6 +1696,7 @@ public: template class nsAutoArrayBase : public TArrayBase { + static_assert(N != 0, "nsAutoArrayBase should be specialized"); public: typedef nsAutoArrayBase self_type; typedef TArrayBase base_type; @@ -1756,6 +1757,24 @@ private: }; }; +// +// Specialization of nsAutoArrayBase for the case where N == 0. +// nsAutoArrayBase behaves exactly like TArrayBase, but without +// this specialization, it stores a useless inline header. +// +// We do have many nsAutoArrayBase objects in memory: about +// 2,000 per tab as of May 2014. These are typically not explicitly +// nsAutoArrayBase but rather nsAutoArrayBase +// for some value N depending on template parameters, in generic code. +// +// For that reason, we optimize this case with the below partial specialization, +// which ensures that nsAutoArrayBase is just like TArrayBase, +// without any inline header overhead. +// +template +class nsAutoArrayBase : public TArrayBase +{}; + // // nsAutoTArray is an infallible vector class with N elements of inline // storage. If you try to store more than N elements inside an