Bug 796279 - remove remaining PR_MAX instances from the tree; r=ehsan
authorNathan Froyd <froydnj@mozilla.com>
Mon, 01 Oct 2012 20:38:21 -0400
changeset 109087 fc59bd8d49baa75609067270759b21dde4017055
parent 109086 9e38c551860548f77d289ac26baf1e0ee2ac0330
child 109088 d0ba1abde985264ddafe3f43561cb52d914c3161
push id82
push usershu@rfrn.org
push dateFri, 05 Oct 2012 13:20:22 +0000
reviewersehsan
bugs796279
milestone18.0a1
Bug 796279 - remove remaining PR_MAX instances from the tree; r=ehsan We can't use NS_MAX or std::max because we lack uniform constexpr support across our supported compilers. But we can do a simple inline max ourselves.
layout/style/nsCSSProps.cpp
xpcom/glue/nsTArray.h
--- a/layout/style/nsCSSProps.cpp
+++ b/layout/style/nsCSSProps.cpp
@@ -80,49 +80,55 @@ enum {
 #define CSS_PROP_ALIAS(aliasname_, propid_, aliasmethod_, pref_)              \
   eCSSAliasCountBefore_##aliasmethod_,
 #include "nsCSSPropAliasList.h"
 #undef CSS_PROP_ALIAS
 
   eCSSAliasCount
 };
 
+// Use a macro in the definitions below to ensure compile-time constants
+// in all the necessary places.
+#define CSS_MAX(x, y) ((x) > (y) ? (x) : (y))
+
 enum {
   // We want the largest sizeof(#aliasname_).  To find that, we use the
   // auto-incrementing behavior of C++ enums (a value without an
   // initializer is one larger than the previous value, or 0 at the
   // start of the enum), and for each alias we define two values:
   //   eMaxCSSAliasNameSizeBefore_##aliasmethod_ is the largest
   //     sizeof(#aliasname_) before that alias.  The first one is
   //     conveniently zero.
   //   eMaxCSSAliasNameSizeWith_##aliasmethod_ is **one less than** the
   //     largest sizeof(#aliasname_) before or including that alias.
 #define CSS_PROP_ALIAS(aliasname_, propid_, aliasmethod_, pref_)              \
   eMaxCSSAliasNameSizeBefore_##aliasmethod_,                                  \
   eMaxCSSAliasNameSizeWith_##aliasmethod_ =                                   \
-    PR_MAX(sizeof(#aliasname_), eMaxCSSAliasNameSizeBefore_##aliasmethod_) - 1,
+    CSS_MAX(sizeof(#aliasname_), eMaxCSSAliasNameSizeBefore_##aliasmethod_) - 1,
 #include "nsCSSPropAliasList.h"
 #undef CSS_PROP_ALIAS
 
   eMaxCSSAliasNameSize
 };
 
 struct CSSPropertyAlias {
-  const char name[PR_MAX(eMaxCSSAliasNameSize, 1)];
+  const char name[CSS_MAX(eMaxCSSAliasNameSize, 1)];
   const nsCSSProperty id;
   bool enabled;
 };
 
-static CSSPropertyAlias gAliases[PR_MAX(eCSSAliasCount, 1)] = {
+static CSSPropertyAlias gAliases[CSS_MAX(eCSSAliasCount, 1)] = {
 #define CSS_PROP_ALIAS(aliasname_, propid_, aliasmethod_, pref_)  \
   { #aliasname_, eCSSProperty_##propid_, true },
 #include "nsCSSPropAliasList.h"
 #undef CSS_PROP_ALIAS
 };
 
+#undef CSS_MAX
+
 void
 nsCSSProps::AddRefTable(void)
 {
   if (0 == gTableRefCount++) {
     NS_ABORT_IF_FALSE(!gPropertyTable, "pre existing array!");
     NS_ABORT_IF_FALSE(!gFontDescTable, "pre existing array!");
 
     gPropertyTable = new nsStaticCaseInsensitiveNameTable();
--- a/xpcom/glue/nsTArray.h
+++ b/xpcom/glue/nsTArray.h
@@ -1344,17 +1344,19 @@ private:
   }
 
   // Declare mAutoBuf aligned to the maximum of the header's alignment and
   // elem_type's alignment.  We need to use a union rather than
   // MOZ_ALIGNED_DECL because GCC is picky about what goes into
   // __attribute__((aligned(foo))).
   union {
     char mAutoBuf[sizeof(nsTArrayHeader) + N * sizeof(elem_type)];
-    mozilla::AlignedElem<PR_MAX(MOZ_ALIGNOF(Header), MOZ_ALIGNOF(elem_type))> mAlign;
+    // Do the max operation inline to ensure that it is a compile-time constant.
+    mozilla::AlignedElem<(MOZ_ALIGNOF(Header) > MOZ_ALIGNOF(elem_type))
+                         ? MOZ_ALIGNOF(Header) : MOZ_ALIGNOF(elem_type)> mAlign;
   };
 };
 
 template<class E, uint32_t N, class Alloc=nsTArrayDefaultAllocator>
 class nsAutoTArray : public nsAutoArrayBase<nsTArray<E, Alloc>, N>
 {
   typedef nsAutoArrayBase<nsTArray<E, Alloc>, N> Base;