Bug 828300 - Replace NS_ARRAY_LENGTH with mozilla::ArrayLength/MOZ_ARRAY_LENGTH. r=ehsan
authorBirunthan Mohanathas <birunthan@mohanathas.com>
Thu, 30 Jan 2014 13:26:54 -0500
changeset 166108 f33daf2f8fb435f00f3983c8f561a846a04bf925
parent 166107 684a2eac38b61c5f68e7ec87fb078a7030101f50
child 166109 26028496b50818ec2f7c9af4e8d4195e73a1f9d1
push id26112
push usercbook@mozilla.com
push dateFri, 31 Jan 2014 11:49:40 +0000
treeherdermozilla-central@93d3ecdfad07 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs828300
milestone29.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 828300 - Replace NS_ARRAY_LENGTH with mozilla::ArrayLength/MOZ_ARRAY_LENGTH. r=ehsan
accessible/src/generic/DocAccessible.cpp
browser/components/about/AboutRedirector.cpp
content/mathml/content/src/nsMathMLElement.cpp
content/media/directshow/DirectShowUtils.cpp
content/media/wmf/WMFReader.cpp
content/media/wmf/WMFUtils.cpp
content/svg/content/src/SVGPathSegUtils.h
docshell/base/nsAboutRedirector.cpp
dom/bluetooth/bluez/linux/BluetoothDBusService.cpp
dom/workers/RuntimeService.cpp
extensions/permissions/nsContentBlocker.cpp
extensions/universalchardet/src/base/CharDistribution.cpp
gfx/src/nsFont.cpp
gfx/thebes/gfxASurface.cpp
hal/gonk/GonkHal.cpp
ipc/nfc/Nfc.cpp
ipc/ril/Ril.cpp
layout/base/nsLayoutUtils.cpp
layout/base/nsPresContext.cpp
layout/inspector/inDOMUtils.cpp
layout/style/nsCSSParser.cpp
layout/style/nsCSSRuleProcessor.cpp
layout/style/nsRuleNode.cpp
layout/style/nsStyleSet.cpp
layout/svg/nsSVGPathGeometryFrame.cpp
parser/html/nsHtml5NamedCharacters.cpp
toolkit/components/mediasniffer/nsMediaSniffer.cpp
toolkit/components/remote/nsXRemoteService.cpp
widget/gonk/GonkMemoryPressureMonitoring.cpp
widget/gtk/nsCUPSShim.cpp
xpcom/base/CycleCollectedJSRuntime.cpp
xpcom/build/nsXULAppAPI.h
xpcom/tests/TestTArray.cpp
xulrunner/stub/nsXULStub.cpp
--- a/accessible/src/generic/DocAccessible.cpp
+++ b/accessible/src/generic/DocAccessible.cpp
@@ -35,16 +35,17 @@
 #include "nsIPresShell.h"
 #include "nsIServiceManager.h"
 #include "nsViewManager.h"
 #include "nsIScrollableFrame.h"
 #include "nsUnicharUtils.h"
 #include "nsIURI.h"
 #include "nsIWebNavigation.h"
 #include "nsFocusManager.h"
+#include "mozilla/ArrayUtils.h"
 #include "mozilla/Assertions.h"
 #include "mozilla/dom/DocumentType.h"
 #include "mozilla/dom/Element.h"
 
 #ifdef MOZ_XUL
 #include "nsIXULDocument.h"
 #endif
 
@@ -60,17 +61,17 @@ static nsIAtom** kRelationAttrs[] =
   &nsGkAtoms::aria_describedby,
   &nsGkAtoms::aria_owns,
   &nsGkAtoms::aria_controls,
   &nsGkAtoms::aria_flowto,
   &nsGkAtoms::_for,
   &nsGkAtoms::control
 };
 
-static const uint32_t kRelationAttrsLen = NS_ARRAY_LENGTH(kRelationAttrs);
+static const uint32_t kRelationAttrsLen = ArrayLength(kRelationAttrs);
 
 ////////////////////////////////////////////////////////////////////////////////
 // Constructor/desctructor
 
 DocAccessible::
   DocAccessible(nsIDocument* aDocument, nsIContent* aRootContent,
                   nsIPresShell* aPresShell) :
   HyperTextAccessibleWrap(aRootContent, this),
--- a/browser/components/about/AboutRedirector.cpp
+++ b/browser/components/about/AboutRedirector.cpp
@@ -3,16 +3,17 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 // See also: docshell/base/nsAboutRedirector.cpp
 
 #include "AboutRedirector.h"
 #include "nsNetUtil.h"
 #include "nsIScriptSecurityManager.h"
+#include "mozilla/ArrayUtils.h"
 
 namespace mozilla {
 namespace browser {
 
 NS_IMPL_ISUPPORTS1(AboutRedirector, nsIAboutModule)
 
 struct RedirEntry {
   const char* id;
@@ -92,17 +93,17 @@ static RedirEntry kRedirMap[] = {
 #endif
   { "accounts", "chrome://browser/content/aboutaccounts/aboutaccounts.xhtml",
     nsIAboutModule::ALLOW_SCRIPT },
   { "app-manager", "chrome://browser/content/devtools/app-manager/index.xul",
     nsIAboutModule::ALLOW_SCRIPT },
   { "customizing", "chrome://browser/content/customizableui/aboutCustomizing.xhtml",
     nsIAboutModule::ALLOW_SCRIPT },
 };
-static const int kRedirTotal = NS_ARRAY_LENGTH(kRedirMap);
+static const int kRedirTotal = ArrayLength(kRedirMap);
 
 static nsAutoCString
 GetAboutModuleName(nsIURI *aURI)
 {
   nsAutoCString path;
   aURI->GetPath(path);
 
   int32_t f = path.FindChar('#');
--- a/content/mathml/content/src/nsMathMLElement.cpp
+++ b/content/mathml/content/src/nsMathMLElement.cpp
@@ -608,17 +608,17 @@ nsMathMLElement::MapMathMLAttributesInto
     if (value && value->Type() == nsAttrValue::eString &&
         fontSize->GetUnit() == eCSSUnit_Null) {
       nsAutoString str(value->GetStringValue());
       if (!ParseNumericValue(str, *fontSize, PARSE_SUPPRESS_WARNINGS |
                              PARSE_ALLOW_UNITLESS | CONVERT_UNITLESS_TO_PERCENT,
                              nullptr)
           && parseSizeKeywords) {
         static const char sizes[3][7] = { "small", "normal", "big" };
-        static const int32_t values[NS_ARRAY_LENGTH(sizes)] = {
+        static const int32_t values[MOZ_ARRAY_LENGTH(sizes)] = {
           NS_STYLE_FONT_SIZE_SMALL, NS_STYLE_FONT_SIZE_MEDIUM,
           NS_STYLE_FONT_SIZE_LARGE
         };
         str.CompressWhitespace();
         for (uint32_t i = 0; i < ArrayLength(sizes); ++i) {
           if (str.EqualsASCII(sizes[i])) {
             fontSize->SetIntValue(values[i], eCSSUnit_Enumerated);
             break;
@@ -725,17 +725,17 @@ nsMathMLElement::MapMathMLAttributesInto
       nsAutoString str(value->GetStringValue());
       str.CompressWhitespace();
       static const char sizes[19][23] = {
         "normal", "bold", "italic", "bold-italic", "script", "bold-script",
         "fraktur", "double-struck", "bold-fraktur", "sans-serif",
         "bold-sans-serif", "sans-serif-italic", "sans-serif-bold-italic",
         "monospace", "initial", "tailed", "looped", "stretched"
       };
-      static const int32_t values[NS_ARRAY_LENGTH(sizes)] = {
+      static const int32_t values[MOZ_ARRAY_LENGTH(sizes)] = {
         NS_MATHML_MATHVARIANT_NORMAL, NS_MATHML_MATHVARIANT_BOLD,
         NS_MATHML_MATHVARIANT_ITALIC, NS_MATHML_MATHVARIANT_BOLD_ITALIC,
         NS_MATHML_MATHVARIANT_SCRIPT, NS_MATHML_MATHVARIANT_BOLD_SCRIPT,
         NS_MATHML_MATHVARIANT_FRAKTUR, NS_MATHML_MATHVARIANT_DOUBLE_STRUCK,
         NS_MATHML_MATHVARIANT_BOLD_FRAKTUR, NS_MATHML_MATHVARIANT_SANS_SERIF,
         NS_MATHML_MATHVARIANT_BOLD_SANS_SERIF,
         NS_MATHML_MATHVARIANT_SANS_SERIF_ITALIC,
         NS_MATHML_MATHVARIANT_SANS_SERIF_BOLD_ITALIC,
@@ -871,17 +871,17 @@ nsMathMLElement::MapMathMLAttributesInto
   //
   if (aData->mSIDs & NS_STYLE_INHERIT_BIT(Visibility)) {
     const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::dir);
     nsCSSValue* direction = aData->ValueForDirection();
     if (value && value->Type() == nsAttrValue::eString &&
         direction->GetUnit() == eCSSUnit_Null) {
       nsAutoString str(value->GetStringValue());
       static const char dirs[][4] = { "ltr", "rtl" };
-      static const int32_t dirValues[NS_ARRAY_LENGTH(dirs)] = {
+      static const int32_t dirValues[MOZ_ARRAY_LENGTH(dirs)] = {
         NS_STYLE_DIRECTION_LTR, NS_STYLE_DIRECTION_RTL
       };
       for (uint32_t i = 0; i < ArrayLength(dirs); ++i) {
         if (str.EqualsASCII(dirs[i])) {
           direction->SetIntValue(dirValues[i], eCSSUnit_Enumerated);
           break;
         }
       }
--- a/content/media/directshow/DirectShowUtils.cpp
+++ b/content/media/directshow/DirectShowUtils.cpp
@@ -4,18 +4,18 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "dshow.h"
 #include "dmodshow.h"
 #include "wmcodecdsp.h"
 #include "dmoreg.h"
 #include "DirectShowUtils.h"
 #include "nsAutoPtr.h"
+#include "mozilla/ArrayUtils.h"
 #include "mozilla/RefPtr.h"
-#include "nsMemory.h"
 
 namespace mozilla {
 
 #if defined(PR_LOGGING)
 
 // Create a table which maps GUIDs to a string representation of the GUID.
 // This is useful for debugging purposes, for logging the GUIDs of media types.
 // This is only available when logging is enabled, i.e. not in release builds.
@@ -33,17 +33,17 @@ static const GuidToName GuidToNameTable[
 #include <uuids.h>
 };
 
 #pragma pop_macro("OUR_GUID_ENTRY")
 
 const char*
 GetDirectShowGuidName(const GUID& aGuid)
 {
-  size_t len = NS_ARRAY_LENGTH(GuidToNameTable);
+  const size_t len = ArrayLength(GuidToNameTable);
   for (unsigned i = 0; i < len; i++) {
     if (IsEqualGUID(aGuid, GuidToNameTable[i].guid)) {
       return GuidToNameTable[i].name;
     }
   }
   return "Unknown";
 }
 #endif // PR_LOGGING
--- a/content/media/wmf/WMFReader.cpp
+++ b/content/media/wmf/WMFReader.cpp
@@ -4,16 +4,17 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "WMFReader.h"
 #include "WMFDecoder.h"
 #include "WMFUtils.h"
 #include "WMFByteStream.h"
 #include "WMFSourceReaderCallback.h"
+#include "mozilla/ArrayUtils.h"
 #include "mozilla/dom/TimeRanges.h"
 #include "mozilla/dom/HTMLMediaElement.h"
 #include "mozilla/Preferences.h"
 #include "DXVA2Manager.h"
 #include "ImageContainer.h"
 #include "Layers.h"
 #include "mozilla/layers/LayersTypes.h"
 
@@ -354,17 +355,17 @@ WMFReader::ConfigureVideoDecoder()
 
   static const GUID MP4VideoTypes[] = {
     MFVideoFormat_H264
   };
   HRESULT hr = ConfigureSourceReaderStream(mSourceReader,
                                            MF_SOURCE_READER_FIRST_VIDEO_STREAM,
                                            mUseHwAccel ? MFVideoFormat_NV12 : MFVideoFormat_YV12,
                                            MP4VideoTypes,
-                                           NS_ARRAY_LENGTH(MP4VideoTypes));
+                                           ArrayLength(MP4VideoTypes));
   if (FAILED(hr)) {
     DECODER_LOG("Failed to configured video output");
     return hr;
   }
 
   RefPtr<IMFMediaType> mediaType;
   hr = mSourceReader->GetCurrentMediaType(MF_SOURCE_READER_FIRST_VIDEO_STREAM,
                                           byRef(mediaType));
@@ -395,23 +396,23 @@ WMFReader::GetSupportedAudioCodecs(const
     GUID aacOrMp3 = MFMPEG4Format_Base;
     aacOrMp3.Data1 = 0x6D703461;// FOURCC('m','p','4','a');
     static const GUID codecs[] = {
       MFAudioFormat_AAC,
       MFAudioFormat_MP3,
       aacOrMp3
     };
     *aCodecs = codecs;
-    *aNumCodecs = NS_ARRAY_LENGTH(codecs);
+    *aNumCodecs = ArrayLength(codecs);
   } else {
     static const GUID codecs[] = {
       MFAudioFormat_AAC
     };
     *aCodecs = codecs;
-    *aNumCodecs = NS_ARRAY_LENGTH(codecs);
+    *aNumCodecs = ArrayLength(codecs);
   }
 }
 
 HRESULT
 WMFReader::ConfigureAudioDecoder()
 {
   NS_ASSERTION(mSourceReader, "Must have a SourceReader before configuring decoders!");
 
--- a/content/media/wmf/WMFUtils.cpp
+++ b/content/media/wmf/WMFUtils.cpp
@@ -1,16 +1,17 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim:set ts=2 sw=2 sts=2 et cindent: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "WMFUtils.h"
 #include <stdint.h>
+#include "mozilla/ArrayUtils.h"
 #include "mozilla/RefPtr.h"
 #include "mozilla/WindowsVersion.h"
 #include "prlog.h"
 #include "nsThreadUtils.h"
 #include "nsWindowsHelpers.h"
 #include "mozilla/CheckedInt.h"
 #include "VideoUtils.h"
 
@@ -179,17 +180,17 @@ GuidToName GuidToNameTable[] = {
   INTERFACE_TO_NAME_ENTRY(IMFByteStream),
   INTERFACE_TO_NAME_ENTRY(IMFMediaSource),
   INTERFACE_TO_NAME_ENTRY(IMFAttributes),
   INTERFACE_TO_NAME_ENTRY(IMFByteStreamBuffering),
 };
 
 nsCString GetGUIDName(const GUID& guid)
 {
-  unsigned numTypes = NS_ARRAY_LENGTH(GuidToNameTable);
+  const unsigned numTypes = ArrayLength(GuidToNameTable);
   for (unsigned i = 0; i < numTypes; i++) {
     if (guid == GuidToNameTable[i].guid) {
       return nsDependentCString(GuidToNameTable[i].name);
     }
   }
 
   WCHAR* name = nullptr;
   HRESULT hr = StringFromCLSID(guid , &name);
@@ -441,17 +442,17 @@ LoadDLLs()
   if (sDLLsLoaded) {
     return S_OK;
   }
   if (sFailedToLoadDlls) {
     return E_FAIL;
   }
 
   // Try to load all the required DLLs.
-  uint32_t dllLength = NS_ARRAY_LENGTH(sDLLs);
+  const uint32_t dllLength = ArrayLength(sDLLs);
   for (uint32_t i = 0; i < dllLength; i++) {
     sDLLs[i].handle = LoadLibrarySystem32(sDLLs[i].name);
     if (!sDLLs[i].handle) {
       sFailedToLoadDlls = true;
       NS_WARNING("Failed to load WMF DLLs");
       UnloadDLLs();
       return E_FAIL;
     }
@@ -471,17 +472,17 @@ LoadDLLs()
   return S_OK;
 }
 
 HRESULT
 UnloadDLLs()
 {
   NS_ASSERTION(NS_IsMainThread(), "Should be on main thread.");
 
-  uint32_t length = NS_ARRAY_LENGTH(sDLLs);
+  const uint32_t length = ArrayLength(sDLLs);
   for (uint32_t i = 0; i < length; i++) {
     if (sDLLs[i].handle) {
       FreeLibrary(sDLLs[i].handle);
       sDLLs[i].handle = nullptr;
     }
     sDLLsLoaded = false;
   }
   return S_OK;
--- a/content/svg/content/src/SVGPathSegUtils.h
+++ b/content/svg/content/src/SVGPathSegUtils.h
@@ -2,19 +2,19 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef MOZILLA_SVGPATHSEGUTILS_H__
 #define MOZILLA_SVGPATHSEGUTILS_H__
 
 #include "gfxPoint.h"
+#include "mozilla/ArrayUtils.h"
 #include "mozilla/gfx/Point.h"
 #include "nsDebug.h"
-#include "nsMemory.h"
 
 namespace mozilla {
 
 // Path Segment Types
 static const unsigned short PATHSEG_UNKNOWN                      = 0;
 static const unsigned short PATHSEG_CLOSEPATH                    = 1;
 static const unsigned short PATHSEG_MOVETO_ABS                   = 2;
 static const unsigned short PATHSEG_MOVETO_REL                   = 3;
@@ -147,17 +147,17 @@ public:
       char16_t('h'),  // 13 == PATHSEG_LINETO_HORIZONTAL_REL
       char16_t('V'),  // 14 == PATHSEG_LINETO_VERTICAL_ABS
       char16_t('v'),  // 15 == PATHSEG_LINETO_VERTICAL_REL
       char16_t('S'),  // 16 == PATHSEG_CURVETO_CUBIC_SMOOTH_ABS
       char16_t('s'),  // 17 == PATHSEG_CURVETO_CUBIC_SMOOTH_REL
       char16_t('T'),  // 18 == PATHSEG_CURVETO_QUADRATIC_SMOOTH_ABS
       char16_t('t')   // 19 == PATHSEG_CURVETO_QUADRATIC_SMOOTH_REL
     };
-    static_assert(NS_ARRAY_LENGTH(table) == NS_SVG_PATH_SEG_TYPE_COUNT, "Unexpected table size");
+    static_assert(MOZ_ARRAY_LENGTH(table) == NS_SVG_PATH_SEG_TYPE_COUNT, "Unexpected table size");
 
     return table[aType];
   }
 
   static uint32_t ArgCountForType(uint32_t aType) {
     NS_ABORT_IF_FALSE(IsValidType(aType), "Seg type not recognized");
 
     static const uint8_t table[] = {
@@ -177,17 +177,17 @@ public:
       1,  // 13 == PATHSEG_LINETO_HORIZONTAL_REL
       1,  // 14 == PATHSEG_LINETO_VERTICAL_ABS
       1,  // 15 == PATHSEG_LINETO_VERTICAL_REL
       4,  // 16 == PATHSEG_CURVETO_CUBIC_SMOOTH_ABS
       4,  // 17 == PATHSEG_CURVETO_CUBIC_SMOOTH_REL
       2,  // 18 == PATHSEG_CURVETO_QUADRATIC_SMOOTH_ABS
       2   // 19 == PATHSEG_CURVETO_QUADRATIC_SMOOTH_REL
     };
-    static_assert(NS_ARRAY_LENGTH(table) == NS_SVG_PATH_SEG_TYPE_COUNT, "Unexpected table size");
+    static_assert(MOZ_ARRAY_LENGTH(table) == NS_SVG_PATH_SEG_TYPE_COUNT, "Unexpected table size");
 
     return table[aType];
   }
 
   /**
    * Convenience so that callers can pass a float containing an encoded type
    * and have it decoded implicitly.
    */
--- a/docshell/base/nsAboutRedirector.cpp
+++ b/docshell/base/nsAboutRedirector.cpp
@@ -2,16 +2,17 @@
 /* vim:set ts=4 sw=4 sts=4 et cindent: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsAboutRedirector.h"
 #include "nsNetUtil.h"
 #include "nsAboutProtocolUtils.h"
+#include "mozilla/ArrayUtils.h"
 
 NS_IMPL_ISUPPORTS1(nsAboutRedirector, nsIAboutModule)
 
 struct RedirEntry {
     const char* id;
     const char* url;
     uint32_t flags;
 };
@@ -68,17 +69,17 @@ static RedirEntry kRedirMap[] = {
     { "webrtc", "chrome://global/content/aboutWebrtc.xhtml",
        nsIAboutModule::ALLOW_SCRIPT },
     // about:srcdoc is unresolvable by specification.  It is included here
     // because the security manager would disallow srcdoc iframes otherwise.
     { "srcdoc", "about:blank",
       nsIAboutModule::URI_SAFE_FOR_UNTRUSTED_CONTENT |
       nsIAboutModule::HIDE_FROM_ABOUTABOUT }
 };
-static const int kRedirTotal = NS_ARRAY_LENGTH(kRedirMap);
+static const int kRedirTotal = mozilla::ArrayLength(kRedirMap);
 
 NS_IMETHODIMP
 nsAboutRedirector::NewChannel(nsIURI *aURI, nsIChannel **result)
 {
     NS_ENSURE_ARG_POINTER(aURI);
     NS_ASSERTION(result, "must not be null");
 
     nsresult rv;
--- a/dom/bluetooth/bluez/linux/BluetoothDBusService.cpp
+++ b/dom/bluetooth/bluez/linux/BluetoothDBusService.cpp
@@ -1377,17 +1377,17 @@ public:
 
     const dbus_uint32_t* services = sServices;
 
     bool success = connection->SendWithReply(
       DBusReplyHandler::Callback, handler.get(), -1,
       NS_ConvertUTF16toUTF8(sAdapterPath).get(),
       DBUS_ADAPTER_IFACE, "AddReservedServiceRecords",
       DBUS_TYPE_ARRAY, DBUS_TYPE_UINT32,
-      &services, NS_ARRAY_LENGTH(sServices), DBUS_TYPE_INVALID);
+      &services, ArrayLength(sServices), DBUS_TYPE_INVALID);
 
     NS_ENSURE_TRUE(success, NS_ERROR_FAILURE);
 
     handler.forget();
 
     return NS_OK;
   }
 
--- a/dom/workers/RuntimeService.cpp
+++ b/dom/workers/RuntimeService.cpp
@@ -179,17 +179,17 @@ const char* gStringChars[] = {
   "Event",
   "MessageEvent",
   "ErrorEvent"
 
   // XXX Don't care about ProgressEvent since it should never leak to the main
   // thread.
 };
 
-static_assert(NS_ARRAY_LENGTH(gStringChars) == ID_COUNT,
+static_assert(MOZ_ARRAY_LENGTH(gStringChars) == ID_COUNT,
               "gStringChars should have the right length.");
 
 class LiteralRebindingCString : public nsDependentCString
 {
 public:
   template<int N>
   void RebindLiteral(const char (&aStr)[N])
   {
--- a/extensions/permissions/nsContentBlocker.cpp
+++ b/extensions/permissions/nsContentBlocker.cpp
@@ -8,16 +8,17 @@
 #include "nsIServiceManager.h"
 #include "nsIDocShellTreeItem.h"
 #include "nsIPrefService.h"
 #include "nsIPrefBranch.h"
 #include "nsIDocShell.h"
 #include "nsString.h"
 #include "nsContentPolicyUtils.h"
 #include "nsIObjectLoadingContent.h"
+#include "mozilla/ArrayUtils.h"
 
 // Possible behavior pref values
 // Those map to the nsIPermissionManager values where possible
 #define BEHAVIOR_ACCEPT nsIPermissionManager::ALLOW_ACTION
 #define BEHAVIOR_REJECT nsIPermissionManager::DENY_ACTION
 #define BEHAVIOR_NOFOREIGN 3
 
 // From nsIContentPolicy
@@ -35,17 +36,17 @@ static const char *kTypeString[] = {"oth
                                     "objectsubrequest",
                                     "dtd",
                                     "font",
                                     "media",
                                     "websocket",
                                     "csp_report",
                                     "xslt"};
 
-#define NUMBER_OF_TYPES NS_ARRAY_LENGTH(kTypeString)
+#define NUMBER_OF_TYPES MOZ_ARRAY_LENGTH(kTypeString)
 uint8_t nsContentBlocker::mBehaviorPref[NUMBER_OF_TYPES];
 
 NS_IMPL_ISUPPORTS3(nsContentBlocker, 
                    nsIContentPolicy,
                    nsIObserver,
                    nsSupportsWeakReference)
 
 nsContentBlocker::nsContentBlocker()
--- a/extensions/universalchardet/src/base/CharDistribution.cpp
+++ b/extensions/universalchardet/src/base/CharDistribution.cpp
@@ -5,17 +5,17 @@
 
 #include "CharDistribution.h"
 
 #include "JISFreq.tab"
 #include "Big5Freq.tab"
 #include "EUCKRFreq.tab"
 #include "EUCTWFreq.tab"
 #include "GB2312Freq.tab"
-#include "nsMemory.h"
+#include "mozilla/ArrayUtils.h"
 
 #define SURE_YES 0.99f
 #define SURE_NO  0.01f
 
 //return confidence base on received data
 float CharDistributionAnalysis::GetConfidence(void)
 { 
   //if we didn't receive any character in our consideration range, or the
@@ -32,47 +32,47 @@ float CharDistributionAnalysis::GetConfi
   }
   //normalize confidence, (we don't want to be 100% sure)
   return SURE_YES;
 }
 
 EUCTWDistributionAnalysis::EUCTWDistributionAnalysis()
 {
   mCharToFreqOrder = EUCTWCharToFreqOrder;
-  mTableSize = NS_ARRAY_LENGTH(EUCTWCharToFreqOrder);
+  mTableSize = mozilla::ArrayLength(EUCTWCharToFreqOrder);
   mTypicalDistributionRatio = EUCTW_TYPICAL_DISTRIBUTION_RATIO;
 }
 
 EUCKRDistributionAnalysis::EUCKRDistributionAnalysis()
 {
   mCharToFreqOrder = EUCKRCharToFreqOrder;
-  mTableSize = NS_ARRAY_LENGTH(EUCKRCharToFreqOrder);
+  mTableSize = mozilla::ArrayLength(EUCKRCharToFreqOrder);
   mTypicalDistributionRatio = EUCKR_TYPICAL_DISTRIBUTION_RATIO;
 }
 
 GB2312DistributionAnalysis::GB2312DistributionAnalysis()
 {
   mCharToFreqOrder = GB2312CharToFreqOrder;
-  mTableSize = NS_ARRAY_LENGTH(GB2312CharToFreqOrder);
+  mTableSize = mozilla::ArrayLength(GB2312CharToFreqOrder);
   mTypicalDistributionRatio = GB2312_TYPICAL_DISTRIBUTION_RATIO;
 }
 
 Big5DistributionAnalysis::Big5DistributionAnalysis()
 {
   mCharToFreqOrder = Big5CharToFreqOrder;
-  mTableSize = NS_ARRAY_LENGTH(Big5CharToFreqOrder);
+  mTableSize = mozilla::ArrayLength(Big5CharToFreqOrder);
   mTypicalDistributionRatio = BIG5_TYPICAL_DISTRIBUTION_RATIO;
 }
 
 SJISDistributionAnalysis::SJISDistributionAnalysis()
 {
   mCharToFreqOrder = JISCharToFreqOrder;
-  mTableSize = NS_ARRAY_LENGTH(JISCharToFreqOrder);
+  mTableSize = mozilla::ArrayLength(JISCharToFreqOrder);
   mTypicalDistributionRatio = JIS_TYPICAL_DISTRIBUTION_RATIO;
 }
 
 EUCJPDistributionAnalysis::EUCJPDistributionAnalysis()
 {
   mCharToFreqOrder = JISCharToFreqOrder;
-  mTableSize = NS_ARRAY_LENGTH(JISCharToFreqOrder);
+  mTableSize = mozilla::ArrayLength(JISCharToFreqOrder);
   mTypicalDistributionRatio = JIS_TYPICAL_DISTRIBUTION_RATIO;
 }
 
--- a/gfx/src/nsFont.cpp
+++ b/gfx/src/nsFont.cpp
@@ -6,19 +6,19 @@
 #include "nsFont.h"
 #include "gfxFont.h"                    // for gfxFontStyle
 #include "gfxFontConstants.h"           // for NS_FONT_KERNING_AUTO, etc
 #include "gfxFontFeatures.h"            // for gfxFontFeature, etc
 #include "gfxFontUtils.h"               // for TRUETYPE_TAG
 #include "nsCRT.h"                      // for nsCRT
 #include "nsDebug.h"                    // for NS_ASSERTION
 #include "nsISupports.h"
-#include "nsMemory.h"                   // for NS_ARRAY_LENGTH
 #include "nsUnicharUtils.h"
 #include "nscore.h"                     // for char16_t
+#include "mozilla/ArrayUtils.h"
 #include "mozilla/gfx/2D.h"
 
 nsFont::nsFont(const char* aName, uint8_t aStyle, uint8_t aVariant,
                uint16_t aWeight, int16_t aStretch, uint8_t aDecoration,
                nscoord aSize)
 {
   NS_ASSERTION(aName && IsASCII(nsDependentCString(aName)),
                "Must only pass ASCII names here");
@@ -249,50 +249,50 @@ const gfxFontFeature eastAsianDefaults[]
   { TRUETYPE_TAG('j','p','0','4'), 1 },
   { TRUETYPE_TAG('s','m','p','l'), 1 },
   { TRUETYPE_TAG('t','r','a','d'), 1 },
   { TRUETYPE_TAG('f','w','i','d'), 1 },
   { TRUETYPE_TAG('p','w','i','d'), 1 },
   { TRUETYPE_TAG('r','u','b','y'), 1 }
 };
 
-static_assert(NS_ARRAY_LENGTH(eastAsianDefaults) ==
+static_assert(MOZ_ARRAY_LENGTH(eastAsianDefaults) ==
               eFeatureEastAsian_numFeatures,
               "eFeatureEastAsian_numFeatures should be correct");
 
 // NS_FONT_VARIANT_LIGATURES_xxx values
 const gfxFontFeature ligDefaults[] = {
   { TRUETYPE_TAG('l','i','g','a'), 0 },  // none value means all off
   { TRUETYPE_TAG('l','i','g','a'), 1 },
   { TRUETYPE_TAG('l','i','g','a'), 0 },
   { TRUETYPE_TAG('d','l','i','g'), 1 },
   { TRUETYPE_TAG('d','l','i','g'), 0 },
   { TRUETYPE_TAG('h','l','i','g'), 1 },
   { TRUETYPE_TAG('h','l','i','g'), 0 },
   { TRUETYPE_TAG('c','a','l','t'), 1 },
   { TRUETYPE_TAG('c','a','l','t'), 0 }
 };
 
-static_assert(NS_ARRAY_LENGTH(ligDefaults) ==
+static_assert(MOZ_ARRAY_LENGTH(ligDefaults) ==
               eFeatureLigatures_numFeatures,
               "eFeatureLigatures_numFeatures should be correct");
 
 // NS_FONT_VARIANT_NUMERIC_xxx values
 const gfxFontFeature numericDefaults[] = {
   { TRUETYPE_TAG('l','n','u','m'), 1 },
   { TRUETYPE_TAG('o','n','u','m'), 1 },
   { TRUETYPE_TAG('p','n','u','m'), 1 },
   { TRUETYPE_TAG('t','n','u','m'), 1 },
   { TRUETYPE_TAG('f','r','a','c'), 1 },
   { TRUETYPE_TAG('a','f','r','c'), 1 },
   { TRUETYPE_TAG('z','e','r','o'), 1 },
   { TRUETYPE_TAG('o','r','d','n'), 1 }
 };
 
-static_assert(NS_ARRAY_LENGTH(numericDefaults) ==
+static_assert(MOZ_ARRAY_LENGTH(numericDefaults) ==
               eFeatureNumeric_numFeatures,
               "eFeatureNumeric_numFeatures should be correct");
 
 static void
 AddFontFeaturesBitmask(uint32_t aValue, uint32_t aMin, uint32_t aMax,
                       const gfxFontFeature aFeatureDefaults[],
                       nsTArray<gfxFontFeature>& aFeaturesOut)
 
--- a/gfx/thebes/gfxASurface.cpp
+++ b/gfx/thebes/gfxASurface.cpp
@@ -1,15 +1,16 @@
 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsIMemoryReporter.h"
 #include "nsMemory.h"
+#include "mozilla/ArrayUtils.h"
 #include "mozilla/Base64.h"
 #include "mozilla/CheckedInt.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/MemoryReporting.h"
 #include "nsTraceRefcnt.h"
 #include "mozilla/gfx/2D.h"
 
 #include "gfxASurface.h"
@@ -613,17 +614,17 @@ static const SurfaceMemoryReporterAttrs 
     {"gfx-surface-drm", nullptr},
     {"gfx-surface-tee", nullptr},
     {"gfx-surface-xml", nullptr},
     {"gfx-surface-skia", nullptr},
     {"gfx-surface-subsurface", nullptr},
     {"gfx-surface-d2d", nullptr},
 };
 
-PR_STATIC_ASSERT(NS_ARRAY_LENGTH(sSurfaceMemoryReporterAttrs) ==
+PR_STATIC_ASSERT(MOZ_ARRAY_LENGTH(sSurfaceMemoryReporterAttrs) ==
                  size_t(gfxSurfaceType::Max));
 #ifdef CAIRO_HAS_D2D_SURFACE
 PR_STATIC_ASSERT(uint32_t(CAIRO_SURFACE_TYPE_D2D) ==
                  uint32_t(gfxSurfaceType::D2D));
 #endif
 PR_STATIC_ASSERT(uint32_t(CAIRO_SURFACE_TYPE_SKIA) ==
                  uint32_t(gfxSurfaceType::Skia));
 
@@ -634,17 +635,17 @@ static int64_t gSurfaceMemoryUsed[size_t
 class SurfaceMemoryReporter MOZ_FINAL : public nsIMemoryReporter
 {
 public:
     NS_DECL_ISUPPORTS
 
     NS_IMETHOD CollectReports(nsIMemoryReporterCallback *aCb,
                               nsISupports *aClosure)
     {
-        size_t len = NS_ARRAY_LENGTH(sSurfaceMemoryReporterAttrs);
+        const size_t len = ArrayLength(sSurfaceMemoryReporterAttrs);
         for (size_t i = 0; i < len; i++) {
             int64_t amount = gSurfaceMemoryUsed[i];
 
             if (amount != 0) {
                 const char *path = sSurfaceMemoryReporterAttrs[i].path;
                 const char *desc = sSurfaceMemoryReporterAttrs[i].description;
                 if (!desc) {
                     desc = sDefaultSurfaceDescription;
--- a/hal/gonk/GonkHal.cpp
+++ b/hal/gonk/GonkHal.cpp
@@ -38,16 +38,17 @@
 #include "hardware_legacy/vibrator.h"
 #include "hardware_legacy/power.h"
 #include "libdisplay/GonkDisplay.h"
 
 #include "base/message_loop.h"
 
 #include "Hal.h"
 #include "HalImpl.h"
+#include "mozilla/ArrayUtils.h"
 #include "mozilla/dom/battery/Constants.h"
 #include "mozilla/FileUtils.h"
 #include "mozilla/Monitor.h"
 #include "mozilla/RefPtr.h"
 #include "mozilla/Services.h"
 #include "mozilla/StaticPtr.h"
 #include "mozilla/Preferences.h"
 #include "nsAlgorithm.h"
@@ -1103,17 +1104,17 @@ OomVictimLogger::Observe(
   }
 
   // OOM message finding regexes
   const char* const regexes_raw[] = {
     ".*select.*to kill.*",
     ".*send sigkill to.*",
     ".*lowmem_shrink.*, return",
     ".*lowmem_shrink.*, ofree.*"};
-  const size_t regex_count = NS_ARRAY_LENGTH(regexes_raw);
+  const size_t regex_count = ArrayLength(regexes_raw);
 
   // Compile our regex just in time
   if (!mRegexes) {
     mRegexes = static_cast<regex_t*>(malloc(sizeof(regex_t) * regex_count));
     for (size_t i = 0; i < regex_count; i++) {
       int compilation_err = regcomp(&(mRegexes[i]), regexes_raw[i], REG_NOSUB);
       if (compilation_err) {
         OOM_LOG(ANDROID_LOG_ERROR, "Cannot compile regex \"%s\"\n", regexes_raw[i]);
--- a/ipc/nfc/Nfc.cpp
+++ b/ipc/nfc/Nfc.cpp
@@ -16,16 +16,17 @@
 #if (defined(MOZ_WIDGET_GONK) && defined(DEBUG))
 #include <android/log.h>
 #define CHROMIUM_LOG(args...)  __android_log_print(ANDROID_LOG_INFO, "Gonk", args)
 #else
 #define CHROMIUM_LOG(args...)
 #endif
 
 #include "jsfriendapi.h"
+#include "mozilla/ArrayUtils.h"
 #include "nsThreadUtils.h" // For NS_IsMainThread.
 
 USING_WORKERS_NAMESPACE
 using namespace mozilla::ipc;
 
 namespace {
 
 const char* NFC_SOCKET_NAME = "/dev/socket/nfcd";
@@ -160,18 +161,18 @@ DispatchNFCEvent::RunTask(JSContext* aCx
 
     JSObject* array = JS_NewUint8Array(aCx, mMessage->mSize);
     if (!array) {
         return false;
     }
 
     memcpy(JS_GetArrayBufferViewData(array), mMessage->mData, mMessage->mSize);
     JS::Value argv[] = { OBJECT_TO_JSVAL(array) };
-    return JS_CallFunctionName(aCx, obj, "onNfcMessage", NS_ARRAY_LENGTH(argv),
-                               argv, argv);
+    return JS_CallFunctionName(aCx, obj, "onNfcMessage",
+                               mozilla::ArrayLength(argv), argv, argv);
 }
 
 class NfcConnector : public mozilla::ipc::UnixSocketConnector
 {
 public:
     NfcConnector()
     {}
 
--- a/ipc/ril/Ril.cpp
+++ b/ipc/ril/Ril.cpp
@@ -15,16 +15,17 @@
 #if defined(MOZ_WIDGET_GONK)
 #include <android/log.h>
 #define CHROMIUM_LOG(args...)  __android_log_print(ANDROID_LOG_INFO, "Gonk", args)
 #else
 #define CHROMIUM_LOG(args...)  printf(args);
 #endif
 
 #include "jsfriendapi.h"
+#include "mozilla/ArrayUtils.h"
 #include "nsTArray.h"
 #include "nsThreadUtils.h" // For NS_IsMainThread.
 
 USING_WORKERS_NAMESPACE
 using namespace mozilla::ipc;
 
 namespace {
 
@@ -167,18 +168,18 @@ DispatchRILEvent::RunTask(JSContext *aCx
 
     JSObject *array = JS_NewUint8Array(aCx, mMessage->mSize);
     if (!array) {
         return false;
     }
 
     memcpy(JS_GetArrayBufferViewData(array), mMessage->mData, mMessage->mSize);
     JS::Value argv[] = { OBJECT_TO_JSVAL(array) };
-    return JS_CallFunctionName(aCx, obj, "onRILMessage", NS_ARRAY_LENGTH(argv),
-                               argv, argv);
+    return JS_CallFunctionName(aCx, obj, "onRILMessage",
+                               mozilla::ArrayLength(argv), argv, argv);
 }
 
 class RilConnector : public mozilla::ipc::UnixSocketConnector
 {
 public:
   RilConnector(unsigned long aClientId) : mClientId(aClientId)
   {}
 
--- a/layout/base/nsLayoutUtils.cpp
+++ b/layout/base/nsLayoutUtils.cpp
@@ -130,17 +130,17 @@ static ContentMap& GetContentMap() {
 
 // When the pref "layout.css.sticky.enabled" changes, this function is invoked
 // to let us update kPositionKTable, to selectively disable or restore the
 // entry for "sticky" in that table.
 static void
 StickyEnabledPrefChangeCallback(const char* aPrefName, void* aClosure)
 {
   MOZ_ASSERT(strncmp(aPrefName, STICKY_ENABLED_PREF_NAME,
-                     NS_ARRAY_LENGTH(STICKY_ENABLED_PREF_NAME)) == 0,
+                     ArrayLength(STICKY_ENABLED_PREF_NAME)) == 0,
              "We only registered this callback for a single pref, so it "
              "should only be called for that pref");
 
   static int32_t sIndexOfStickyInPositionTable;
   static bool sIsStickyKeywordIndexInitialized; // initialized to false
 
   bool isStickyEnabled =
     Preferences::GetBool(STICKY_ENABLED_PREF_NAME, false);
--- a/layout/base/nsPresContext.cpp
+++ b/layout/base/nsPresContext.cpp
@@ -1,15 +1,16 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /* a presentation of a document, part 1 */
 
+#include "mozilla/ArrayUtils.h"
 #include "mozilla/DebugOnly.h"
 
 #include "base/basictypes.h"
 
 #include "nsCOMPtr.h"
 #include "nsPresContext.h"
 #include "nsIPresShell.h"
 #include "nsDocShell.h"
@@ -595,17 +596,17 @@ nsPresContext::GetFontPrefsForLang(nsIAt
     &prefs->mDefaultVariableFont,
     &prefs->mDefaultFixedFont,
     &prefs->mDefaultSerifFont,
     &prefs->mDefaultSansSerifFont,
     &prefs->mDefaultMonospaceFont,
     &prefs->mDefaultCursiveFont,
     &prefs->mDefaultFantasyFont
   };
-  static_assert(NS_ARRAY_LENGTH(fontTypes) == eDefaultFont_COUNT,
+  static_assert(MOZ_ARRAY_LENGTH(fontTypes) == eDefaultFont_COUNT,
                 "FontTypes array count is not correct");
 
   // Get attributes specific to each generic font. We do not get the user's
   // generic-font-name-to-specific-family-name preferences because its the
   // generic name that should be fed into the cascade. It is up to the GFX
   // code to look up the font prefs to convert generic names to specific
   // family names as necessary.
   nsAutoCString generic_dot_langGroup;
--- a/layout/inspector/inDOMUtils.cpp
+++ b/layout/inspector/inDOMUtils.cpp
@@ -1,13 +1,15 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
+#include "mozilla/ArrayUtils.h"
+
 #include "inDOMUtils.h"
 #include "inLayoutUtils.h"
 
 #include "nsIServiceManager.h"
 #include "nsISupportsArray.h"
 #include "nsString.h"
 #include "nsIDOMElement.h"
 #include "nsIDocument.h"
@@ -756,17 +758,17 @@ GetStatesForPseudoClass(const nsAString&
 #undef CSS_STATE_PSEUDO_CLASS
 #undef CSS_PSEUDO_CLASS
 
     // Add more entries for our fake values to make sure we can't
     // index out of bounds into this array no matter what.
     nsEventStates(),
     nsEventStates()
   };
-  static_assert(NS_ARRAY_LENGTH(sPseudoClassStates) ==
+  static_assert(MOZ_ARRAY_LENGTH(sPseudoClassStates) ==
                 nsCSSPseudoClasses::ePseudoClass_NotPseudoClass + 1,
                 "Length of PseudoClassStates array is incorrect");
 
   nsCOMPtr<nsIAtom> atom = do_GetAtom(aStatePseudo);
 
   // Ignore :moz-any-link so we don't give the element simultaneous
   // visited and unvisited style state
   if (nsCSSPseudoClasses::GetPseudoType(atom) ==
--- a/layout/style/nsCSSParser.cpp
+++ b/layout/style/nsCSSParser.cpp
@@ -1,16 +1,17 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim: set ts=2 et sw=2 tw=78: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /* parsing of CSS stylesheets, based on a token stream from the CSS scanner */
 
+#include "mozilla/ArrayUtils.h"
 #include "mozilla/DebugOnly.h"
 
 #include "nsCSSParser.h"
 #include "nsCSSProps.h"
 #include "nsCSSKeywords.h"
 #include "nsCSSScanner.h"
 #include "mozilla/css/ErrorReporter.h"
 #include "mozilla/css/Loader.h"
@@ -6744,17 +6745,17 @@ CSSParserImpl::ParseFlex()
 // flex-flow: <flex-direction> || <flex-wrap>
 bool
 CSSParserImpl::ParseFlexFlow()
 {
   static const nsCSSProperty kFlexFlowSubprops[] = {
     eCSSProperty_flex_direction,
     eCSSProperty_flex_wrap
   };
-  const size_t numProps = NS_ARRAY_LENGTH(kFlexFlowSubprops);
+  const size_t numProps = MOZ_ARRAY_LENGTH(kFlexFlowSubprops);
   nsCSSValue values[numProps];
 
   int32_t found = ParseChoice(values, kFlexFlowSubprops, numProps);
 
   // Bail if we didn't successfully parse anything, or if there's trailing junk.
   if (found < 1 || !ExpectEndProperty()) {
     return false;
   }
@@ -9672,17 +9673,17 @@ CSSParserImpl::ParseColumns()
   // If the fake "auto" value is found, and one of the real values isn't,
   // that means the fake auto value is meant for the real value we didn't
   // find.
   static const nsCSSProperty columnIDs[] = {
     eCSSPropertyExtra_x_auto_value,
     eCSSProperty__moz_column_count,
     eCSSProperty__moz_column_width
   };
-  const int32_t numProps = NS_ARRAY_LENGTH(columnIDs);
+  const int32_t numProps = MOZ_ARRAY_LENGTH(columnIDs);
 
   nsCSSValue values[numProps];
   int32_t found = ParseChoice(values, columnIDs, numProps);
   if (found < 1 || !ExpectEndProperty()) {
     return false;
   }
   if ((found & (1|2|4)) == (1|2|4) &&
       values[0].GetUnit() ==  eCSSUnit_Auto) {
@@ -10219,17 +10220,17 @@ static const int32_t maskEastAsian[] = {
   NS_FONT_VARIANT_EAST_ASIAN_VARIANT_MASK,
   NS_FONT_VARIANT_EAST_ASIAN_WIDTH_MASK,
   MASK_END_VALUE
 };
 
 bool
 CSSParserImpl::ParseFontVariantEastAsian(nsCSSValue& aValue)
 {
-  NS_ASSERTION(maskEastAsian[NS_ARRAY_LENGTH(maskEastAsian) - 1] ==
+  NS_ASSERTION(maskEastAsian[ArrayLength(maskEastAsian) - 1] ==
                  MASK_END_VALUE,
                "incorrectly terminated array");
 
   return ParseBitmaskValues(aValue, nsCSSProps::kFontVariantEastAsianKTable,
                             maskEastAsian);
 }
 
 static const int32_t maskLigatures[] = {
@@ -10238,17 +10239,17 @@ static const int32_t maskLigatures[] = {
   NS_FONT_VARIANT_LIGATURES_HISTORICAL_MASK,
   NS_FONT_VARIANT_LIGATURES_CONTEXTUAL_MASK,
   MASK_END_VALUE
 };
 
 bool
 CSSParserImpl::ParseFontVariantLigatures(nsCSSValue& aValue)
 {
-  NS_ASSERTION(maskLigatures[NS_ARRAY_LENGTH(maskLigatures) - 1] ==
+  NS_ASSERTION(maskLigatures[ArrayLength(maskLigatures) - 1] ==
                  MASK_END_VALUE,
                "incorrectly terminated array");
 
   bool parsed =
     ParseBitmaskValues(aValue, nsCSSProps::kFontVariantLigaturesKTable,
                        maskLigatures);
 
   // if none value included, no other values are possible
@@ -10268,17 +10269,17 @@ static const int32_t maskNumeric[] = {
   NS_FONT_VARIANT_NUMERIC_SPACING_MASK,
   NS_FONT_VARIANT_NUMERIC_FRACTION_MASK,
   MASK_END_VALUE
 };
 
 bool
 CSSParserImpl::ParseFontVariantNumeric(nsCSSValue& aValue)
 {
-  NS_ASSERTION(maskNumeric[NS_ARRAY_LENGTH(maskNumeric) - 1] ==
+  NS_ASSERTION(maskNumeric[ArrayLength(maskNumeric) - 1] ==
                  MASK_END_VALUE,
                "incorrectly terminated array");
 
   return ParseBitmaskValues(aValue, nsCSSProps::kFontVariantNumericKTable,
                             maskNumeric);
 }
 
 bool
@@ -10671,17 +10672,17 @@ CSSParserImpl::ParseListStyle()
   // allocated to a dummy property instead.
   static const nsCSSProperty listStyleIDs[] = {
     eCSSPropertyExtra_x_none_value,
     eCSSProperty_list_style_type,
     eCSSProperty_list_style_position,
     eCSSProperty_list_style_image
   };
 
-  nsCSSValue values[NS_ARRAY_LENGTH(listStyleIDs)];
+  nsCSSValue values[MOZ_ARRAY_LENGTH(listStyleIDs)];
   int32_t found =
     ParseChoice(values, listStyleIDs, ArrayLength(listStyleIDs));
   if (found < 1 || !ExpectEndProperty()) {
     return false;
   }
 
   if ((found & (1|2|8)) == (1|2|8)) {
     if (values[0].GetUnit() == eCSSUnit_None) {
@@ -12039,17 +12040,17 @@ CSSParserImpl::ParseTransition()
     // syntax (the first time given is the duration, and the second
     // given is the delay).
     eCSSProperty_transition_delay,
     // Must check 'transition-property' after
     // 'transition-timing-function' since 'transition-property' accepts
     // any keyword.
     eCSSProperty_transition_property
   };
-  static const uint32_t numProps = NS_ARRAY_LENGTH(kTransitionProperties);
+  static const uint32_t numProps = MOZ_ARRAY_LENGTH(kTransitionProperties);
   // this is a shorthand property that accepts -property, -delay,
   // -duration, and -timing-function with some components missing.
   // there can be multiple transitions, separated with commas
 
   nsCSSValue initialValues[numProps];
   initialValues[0].SetFloatValue(0.0, eCSSUnit_Seconds);
   initialValues[1].SetIntValue(NS_STYLE_TRANSITION_TIMING_FUNCTION_EASE,
                                eCSSUnit_Enumerated);
@@ -12121,17 +12122,17 @@ CSSParserImpl::ParseAnimation()
     eCSSProperty_animation_fill_mode,
     eCSSProperty_animation_iteration_count,
     // Must check 'animation-name' after 'animation-timing-function',
     // 'animation-direction', 'animation-fill-mode',
     // 'animation-iteration-count', and 'animation-play-state' since
     // 'animation-name' accepts any keyword.
     eCSSProperty_animation_name
   };
-  static const uint32_t numProps = NS_ARRAY_LENGTH(kAnimationProperties);
+  static const uint32_t numProps = MOZ_ARRAY_LENGTH(kAnimationProperties);
   // this is a shorthand property that accepts -property, -delay,
   // -duration, and -timing-function with some components missing.
   // there can be multiple animations, separated with commas
 
   nsCSSValue initialValues[numProps];
   initialValues[0].SetFloatValue(0.0, eCSSUnit_Seconds);
   initialValues[1].SetIntValue(NS_STYLE_TRANSITION_TIMING_FUNCTION_EASE,
                                eCSSUnit_Enumerated);
@@ -12391,17 +12392,17 @@ CSSParserImpl::ParsePaintOrder()
   static const int32_t kPaintOrderKTable[] = {
     eCSSKeyword_normal,  NS_STYLE_PAINT_ORDER_NORMAL,
     eCSSKeyword_fill,    NS_STYLE_PAINT_ORDER_FILL,
     eCSSKeyword_stroke,  NS_STYLE_PAINT_ORDER_STROKE,
     eCSSKeyword_markers, NS_STYLE_PAINT_ORDER_MARKERS,
     eCSSKeyword_UNKNOWN,-1
   };
 
-  static_assert(NS_ARRAY_LENGTH(kPaintOrderKTable) ==
+  static_assert(MOZ_ARRAY_LENGTH(kPaintOrderKTable) ==
                   2 * (NS_STYLE_PAINT_ORDER_LAST_VALUE + 2),
                 "missing paint-order values in kPaintOrderKTable");
 
   nsCSSValue value;
   if (!ParseVariant(value, VARIANT_HK, kPaintOrderKTable)) {
     return false;
   }
 
--- a/layout/style/nsCSSRuleProcessor.cpp
+++ b/layout/style/nsCSSRuleProcessor.cpp
@@ -1622,17 +1622,17 @@ static const nsEventStates sPseudoClassS
 #include "nsCSSPseudoClassList.h"
 #undef CSS_STATE_PSEUDO_CLASS
 #undef CSS_PSEUDO_CLASS
   // Add more entries for our fake values to make sure we can't
   // index out of bounds into this array no matter what.
   nsEventStates(),
   nsEventStates()
 };
-static_assert(NS_ARRAY_LENGTH(sPseudoClassStates) ==
+static_assert(MOZ_ARRAY_LENGTH(sPseudoClassStates) ==
               nsCSSPseudoClasses::ePseudoClass_NotPseudoClass + 1,
               "ePseudoClass_NotPseudoClass is no longer at the end of"
               "sPseudoClassStates");
 
 static bool
 StateSelectorMatches(Element* aElement,
                      nsCSSSelector* aSelector,
                      NodeMatchContext& aNodeMatchContext,
--- a/layout/style/nsRuleNode.cpp
+++ b/layout/style/nsRuleNode.cpp
@@ -8657,25 +8657,25 @@ nsRuleNode::HasAuthorSpecifiedRules(nsSt
 
   static const nsCSSProperty textShadowValues[] = {
     eCSSProperty_text_shadow
   };
 
   // Number of properties we care about
   size_t nValues = 0;
 
-  nsCSSValue* values[NS_ARRAY_LENGTH(backgroundValues) +
-                     NS_ARRAY_LENGTH(borderValues) +
-                     NS_ARRAY_LENGTH(paddingValues) +
-                     NS_ARRAY_LENGTH(textShadowValues)];
-
-  nsCSSProperty properties[NS_ARRAY_LENGTH(backgroundValues) +
-                           NS_ARRAY_LENGTH(borderValues) +
-                           NS_ARRAY_LENGTH(paddingValues) +
-                           NS_ARRAY_LENGTH(textShadowValues)];
+  nsCSSValue* values[MOZ_ARRAY_LENGTH(backgroundValues) +
+                     MOZ_ARRAY_LENGTH(borderValues) +
+                     MOZ_ARRAY_LENGTH(paddingValues) +
+                     MOZ_ARRAY_LENGTH(textShadowValues)];
+
+  nsCSSProperty properties[MOZ_ARRAY_LENGTH(backgroundValues) +
+                           MOZ_ARRAY_LENGTH(borderValues) +
+                           MOZ_ARRAY_LENGTH(paddingValues) +
+                           MOZ_ARRAY_LENGTH(textShadowValues)];
 
   if (ruleTypeMask & NS_AUTHOR_SPECIFIED_BACKGROUND) {
     for (uint32_t i = 0, i_end = ArrayLength(backgroundValues);
          i < i_end; ++i) {
       properties[nValues] = backgroundValues[i];
       values[nValues++] = ruleData.ValueFor(backgroundValues[i]);
     }
   }
--- a/layout/style/nsStyleSet.cpp
+++ b/layout/style/nsStyleSet.cpp
@@ -1601,17 +1601,17 @@ nsStyleSet::KeyframesRuleForName(nsPresC
 }
 
 bool
 nsStyleSet::AppendFontFeatureValuesRules(nsPresContext* aPresContext,
                                  nsTArray<nsCSSFontFeatureValuesRule*>& aArray)
 {
   NS_ENSURE_FALSE(mInShutdown, false);
 
-  for (uint32_t i = 0; i < NS_ARRAY_LENGTH(gCSSSheetTypes); ++i) {
+  for (uint32_t i = 0; i < ArrayLength(gCSSSheetTypes); ++i) {
     nsCSSRuleProcessor *ruleProc = static_cast<nsCSSRuleProcessor*>
                                     (mRuleProcessors[gCSSSheetTypes[i]].get());
     if (ruleProc &&
         !ruleProc->AppendFontFeatureValuesRules(aPresContext, aArray))
     {
       return false;
     }
   }
@@ -1654,17 +1654,17 @@ nsStyleSet::GetFontFeatureValuesLookup()
 }
 
 bool
 nsStyleSet::AppendPageRules(nsPresContext* aPresContext,
                             nsTArray<nsCSSPageRule*>& aArray)
 {
   NS_ENSURE_FALSE(mInShutdown, false);
 
-  for (uint32_t i = 0; i < NS_ARRAY_LENGTH(gCSSSheetTypes); ++i) {
+  for (uint32_t i = 0; i < ArrayLength(gCSSSheetTypes); ++i) {
     if (gCSSSheetTypes[i] == eScopedDocSheet)
       continue;
     nsCSSRuleProcessor* ruleProc = static_cast<nsCSSRuleProcessor*>
                                     (mRuleProcessors[gCSSSheetTypes[i]].get());
     if (ruleProc && !ruleProc->AppendPageRules(aPresContext, aArray))
       return false;
   }
   return true;
--- a/layout/svg/nsSVGPathGeometryFrame.cpp
+++ b/layout/svg/nsSVGPathGeometryFrame.cpp
@@ -13,16 +13,17 @@
 #include "nsDisplayList.h"
 #include "nsGkAtoms.h"
 #include "nsRenderingContext.h"
 #include "nsSVGEffects.h"
 #include "nsSVGIntegrationUtils.h"
 #include "nsSVGMarkerFrame.h"
 #include "nsSVGPathGeometryElement.h"
 #include "nsSVGUtils.h"
+#include "mozilla/ArrayUtils.h"
 #include "SVGAnimatedTransformList.h"
 #include "SVGGraphicsElement.h"
 
 using namespace mozilla;
 using namespace mozilla::gfx;
 
 //----------------------------------------------------------------------
 // Implementation
@@ -481,17 +482,17 @@ nsSVGPathGeometryFrame::GetBBoxContribut
       uint32_t num = marks.Length();
 
       // These are in the same order as the nsSVGMark::Type constants.
       nsSVGMarkerFrame* markerFrames[] = {
         properties.GetMarkerStartFrame(),
         properties.GetMarkerMidFrame(),
         properties.GetMarkerEndFrame(),
       };
-      PR_STATIC_ASSERT(NS_ARRAY_LENGTH(markerFrames) == nsSVGMark::eTypeCount);
+      PR_STATIC_ASSERT(MOZ_ARRAY_LENGTH(markerFrames) == nsSVGMark::eTypeCount);
 
       for (uint32_t i = 0; i < num; i++) {
         nsSVGMark& mark = marks[i];
         nsSVGMarkerFrame* frame = markerFrames[mark.type];
         if (frame) {
           SVGBBox mbbox =
             frame->GetMarkBBoxContribution(aToBBoxUserspace, aFlags, this,
                                            &marks[i], strokeWidth);
@@ -702,17 +703,17 @@ nsSVGPathGeometryFrame::PaintMarkers(nsR
       uint32_t num = marks.Length();
       if (num) {
         // These are in the same order as the nsSVGMark::Type constants.
         nsSVGMarkerFrame* markerFrames[] = {
           properties.GetMarkerStartFrame(),
           properties.GetMarkerMidFrame(),
           properties.GetMarkerEndFrame(),
         };
-        PR_STATIC_ASSERT(NS_ARRAY_LENGTH(markerFrames) == nsSVGMark::eTypeCount);
+        PR_STATIC_ASSERT(MOZ_ARRAY_LENGTH(markerFrames) == nsSVGMark::eTypeCount);
 
         for (uint32_t i = 0; i < num; i++) {
           nsSVGMark& mark = marks[i];
           nsSVGMarkerFrame* frame = markerFrames[mark.type];
           if (frame) {
             frame->PaintMark(aContext, this, &mark, strokeWidth);
           }
         }
--- a/parser/html/nsHtml5NamedCharacters.cpp
+++ b/parser/html/nsHtml5NamedCharacters.cpp
@@ -19,18 +19,18 @@
  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
  * DEALINGS IN THE SOFTWARE.
  */
 
 #define nsHtml5NamedCharacters_cpp_
 #include "jArray.h"
 #include "nscore.h"
 #include "nsDebug.h"
+#include "mozilla/ArrayUtils.h"
 #include "prlog.h"
-#include "nsMemory.h"
 
 #include "nsHtml5NamedCharacters.h"
 
 const char16_t nsHtml5NamedCharacters::VALUES[][2] = {
 #define NAMED_CHARACTER_REFERENCE(N, CHARS, LEN, FLAG, VALUE) \
 { VALUE },
 #include "nsHtml5NamedCharactersInclude.h"
 #undef NAMED_CHARACTER_REFERENCE
@@ -95,17 +95,17 @@ NAME_##N##_DUMMY, /* automatically one h
 NAME_##N##_START = NAME_##N##_DUMMY - 1, \
 NAME_##N##_END = NAME_##N##_START + LEN + FLAG,
 #include "nsHtml5NamedCharactersInclude.h"
 #undef NAMED_CHARACTER_REFERENCE
   DUMMY_FINAL_NAME_VALUE
 };
 
 /* check that the start positions will fit in 16 bits */
-PR_STATIC_ASSERT(NS_ARRAY_LENGTH(ALL_NAMES) < 0x10000);
+PR_STATIC_ASSERT(MOZ_ARRAY_LENGTH(ALL_NAMES) < 0x10000);
 
 const nsHtml5CharacterName nsHtml5NamedCharacters::NAMES[] = {
 #ifdef DEBUG
   #define NAMED_CHARACTER_REFERENCE(N, CHARS, LEN, FLAG, VALUE) \
 { NAME_##N##_START, LEN, N },
 #else
   #define NAMED_CHARACTER_REFERENCE(N, CHARS, LEN, FLAG, VALUE) \
 { NAME_##N##_START, LEN, },
--- a/toolkit/components/mediasniffer/nsMediaSniffer.cpp
+++ b/toolkit/components/mediasniffer/nsMediaSniffer.cpp
@@ -1,19 +1,19 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim:set ts=2 sw=2 sts=2 tw=80 et cindent: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsMediaSniffer.h"
-#include "nsMemory.h"
 #include "nsIHttpChannel.h"
 #include "nsString.h"
 #include "nsMimeTypes.h"
+#include "mozilla/ArrayUtils.h"
 #include "mozilla/ModuleUtils.h"
 #include "mp3sniff.h"
 #ifdef MOZ_WEBM
 #include "nestegg/nestegg.h"
 #endif
 
 #include "nsIClassInfoImpl.h"
 #include <algorithm>
@@ -109,17 +109,17 @@ nsMediaSniffer::GetMIMETypeFromContent(n
         !contentType.EqualsLiteral(APPLICATION_OCTET_STREAM) &&
         !contentType.EqualsLiteral(UNKNOWN_CONTENT_TYPE)) {
       return NS_ERROR_NOT_AVAILABLE;
     }
   }
 
   const uint32_t clampedLength = std::min(aLength, MAX_BYTES_SNIFFED);
 
-  for (uint32_t i = 0; i < NS_ARRAY_LENGTH(sSnifferEntries); ++i) {
+  for (uint32_t i = 0; i < mozilla::ArrayLength(sSnifferEntries); ++i) {
     const nsMediaSnifferEntry& currentEntry = sSnifferEntries[i];
     if (clampedLength < currentEntry.mLength || currentEntry.mLength == 0) {
       continue;
     }
     bool matched = true;
     for (uint32_t j = 0; j < currentEntry.mLength; ++j) {
       if ((currentEntry.mMask[j] & aData[j]) != currentEntry.mPattern[j]) {
         matched = false;
--- a/toolkit/components/remote/nsXRemoteService.cpp
+++ b/toolkit/components/remote/nsXRemoteService.cpp
@@ -63,17 +63,17 @@ static const char *XAtomNames[] = {
   MOZILLA_LOCK_PROP,
   MOZILLA_COMMAND_PROP,
   MOZILLA_RESPONSE_PROP,
   MOZILLA_USER_PROP,
   MOZILLA_PROFILE_PROP,
   MOZILLA_PROGRAM_PROP,
   MOZILLA_COMMANDLINE_PROP
 };
-static Atom XAtoms[NS_ARRAY_LENGTH(XAtomNames)];
+static Atom XAtoms[MOZ_ARRAY_LENGTH(XAtomNames)];
 
 Atom nsXRemoteService::sMozVersionAtom;
 Atom nsXRemoteService::sMozLockAtom;
 Atom nsXRemoteService::sMozCommandAtom;
 Atom nsXRemoteService::sMozResponseAtom;
 Atom nsXRemoteService::sMozUserAtom;
 Atom nsXRemoteService::sMozProfileAtom;
 Atom nsXRemoteService::sMozProgramAtom;
--- a/widget/gonk/GonkMemoryPressureMonitoring.cpp
+++ b/widget/gonk/GonkMemoryPressureMonitoring.cpp
@@ -1,15 +1,16 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim: set ts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "GonkMemoryPressureMonitoring.h"
+#include "mozilla/ArrayUtils.h"
 #include "mozilla/FileUtils.h"
 #include "mozilla/Monitor.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/Services.h"
 #include "nsIObserver.h"
 #include "nsIObserverService.h"
 #include "nsMemoryPressure.h"
 #include "nsThreadUtils.h"
@@ -140,17 +141,17 @@ public:
       struct pollfd pollfds[2];
       pollfds[0].fd = lowMemFd;
       pollfds[0].events = POLLPRI;
       pollfds[1].fd = mShutdownPipeRead;
       pollfds[1].events = POLLIN;
 
       int pollRv;
       do {
-        pollRv = poll(pollfds, NS_ARRAY_LENGTH(pollfds), /* timeout */ -1);
+        pollRv = poll(pollfds, ArrayLength(pollfds), /* timeout */ -1);
       } while (pollRv == -1 && errno == EINTR);
 
       if (pollfds[1].revents) {
         // Something was written to our shutdown pipe; we're outta here.
         LOG("shutting down (1)");
         return NS_OK;
       }
 
--- a/widget/gtk/nsCUPSShim.cpp
+++ b/widget/gtk/nsCUPSShim.cpp
@@ -2,31 +2,32 @@
 /* ex: set tabstop=8 softtabstop=4 shiftwidth=4 expandtab: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsDebug.h"
 #include "nsString.h"
 #include "nsCUPSShim.h"
+#include "mozilla/ArrayUtils.h"
 #include "prlink.h"
 
 
 // List of symbols to find in libcups. Must match symAddr[] defined in Init().
 // Making this an array of arrays instead of pointers allows storing the
 // whole thing in read-only memory.
 static const char gSymName[][sizeof("cupsPrintFile")] = {
     { "cupsAddOption" },
     { "cupsFreeDests" },
     { "cupsGetDest" },
     { "cupsGetDests" },
     { "cupsPrintFile" },
     { "cupsTempFd" },
 };
-static const int gSymNameCt = NS_ARRAY_LENGTH(gSymName);
+static const int gSymNameCt = mozilla::ArrayLength(gSymName);
 
 
 bool
 nsCUPSShim::Init()
 {
     mCupsLib = PR_LoadLibrary("libcups.so.2");
     if (!mCupsLib)
         return false;
--- a/xpcom/base/CycleCollectedJSRuntime.cpp
+++ b/xpcom/base/CycleCollectedJSRuntime.cpp
@@ -51,16 +51,17 @@
 // edge from the JS object to the C++ object and so it will be marked black
 // too. This decreases the number of objects that the cycle collector has to
 // deal with.
 // To improve debugging, if WantAllTraces() is true all JS objects are
 // traversed.
 
 #include "mozilla/CycleCollectedJSRuntime.h"
 #include <algorithm>
+#include "mozilla/ArrayUtils.h"
 #include "mozilla/MemoryReporting.h"
 #include "mozilla/dom/BindingUtils.h"
 #include "mozilla/dom/DOMJSClass.h"
 #include "mozilla/dom/ScriptSettings.h"
 #include "jsprf.h"
 #include "nsCycleCollectionNoteRootCallback.h"
 #include "nsCycleCollectionParticipant.h"
 #include "nsCycleCollector.h"
@@ -542,17 +543,17 @@ CycleCollectedJSRuntime::DescribeGCThing
       "String",
       "Script",
       "LazyScript",
       "IonCode",
       "Shape",
       "BaseShape",
       "TypeObject",
     };
-    JS_STATIC_ASSERT(NS_ARRAY_LENGTH(trace_types) == JSTRACE_LAST + 1);
+    JS_STATIC_ASSERT(MOZ_ARRAY_LENGTH(trace_types) == JSTRACE_LAST + 1);
     JS_snprintf(name, sizeof(name), "JS %s", trace_types[aTraceKind]);
   }
 
   // Disable printing global for objects while we figure out ObjShrink fallout.
   aCb.DescribeGCedNode(aIsMarked, name, compartmentAddress);
 }
 
 void
--- a/xpcom/build/nsXULAppAPI.h
+++ b/xpcom/build/nsXULAppAPI.h
@@ -9,16 +9,17 @@
 #include "nsID.h"
 #include "xrecore.h"
 #include "nsXPCOM.h"
 #include "nsISupports.h"
 #include "prlog.h"
 #include "nsXREAppData.h"
 #include "js/TypeDecls.h"
 
+#include "mozilla/ArrayUtils.h"
 #include "mozilla/Assertions.h"
 
 /**
  * A directory service key which provides the platform-correct "application
  * data" directory as follows, where $name and $vendor are as defined above and
  * $vendor is optional:
  *
  * Windows:
@@ -361,20 +362,17 @@ enum GeckoProcessType {
 
 static const char* const kGeckoProcessTypeString[] = {
   "default",
   "plugin",
   "tab",
   "ipdlunittest"
 };
 
-// Oddly, NS_ARRAY_LENGTH causes an internal compiler error with MSVC10, so
-// compute the length manually.
-static_assert(sizeof(kGeckoProcessTypeString) /
-              sizeof(kGeckoProcessTypeString[0]) ==
+static_assert(MOZ_ARRAY_LENGTH(kGeckoProcessTypeString) ==
               GeckoProcessType_End,
               "Array length mismatch");
 
 XRE_API(const char*,
         XRE_ChildProcessTypeToString, (GeckoProcessType aProcessType))
 
 XRE_API(GeckoProcessType,
         XRE_StringToChildProcessType, (const char* aProcessTypeString))
--- a/xpcom/tests/TestTArray.cpp
+++ b/xpcom/tests/TestTArray.cpp
@@ -4,17 +4,16 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/ArrayUtils.h"
 
 #include <stdlib.h>
 #include <stdio.h>
 #include "nsTArray.h"
-#include "nsMemory.h"
 #include "nsAutoPtr.h"
 #include "nsStringAPI.h"
 #include "nsDirectoryServiceDefs.h"
 #include "nsDirectoryServiceUtils.h"
 #include "nsComponentManagerUtils.h"
 #include "nsXPCOM.h"
 #include "nsIFile.h"
 
@@ -309,17 +308,17 @@ static bool test_string_array() {
   }
   for (i = 0; i < strArray.Length(); ++i) {
     if (strArray.BinaryIndexOf(strArray[i]) != i)
       return false;
   }
   if (strArray.BinaryIndexOf(EmptyCString()) != strArray.NoIndex)
     return false;
 
-  nsCString rawArray[NS_ARRAY_LENGTH(kdata) - 1];
+  nsCString rawArray[MOZ_ARRAY_LENGTH(kdata) - 1];
   for (i = 0; i < ArrayLength(rawArray); ++i)
     rawArray[i].Assign(kdata + i);  // substrings of kdata
   return test_basic_array(rawArray, ArrayLength(rawArray),
                           nsCString("foopy"));
 }
 
 //----
 
@@ -434,22 +433,22 @@ static bool test_ptrarray() {
 
 //----
 
 // This test relies too heavily on the existence of DebugGetHeader to be
 // useful in non-debug builds.
 #ifdef DEBUG
 static bool test_autoarray() {
   uint32_t data[] = {4,6,8,2,4,1,5,7,3};
-  nsAutoTArray<uint32_t, NS_ARRAY_LENGTH(data)> array;
+  nsAutoTArray<uint32_t, MOZ_ARRAY_LENGTH(data)> array;
 
   void* hdr = array.DebugGetHeader();
   if (hdr == nsTArray<uint32_t>().DebugGetHeader())
     return false;
-  if (hdr == nsAutoTArray<uint32_t, NS_ARRAY_LENGTH(data)>().DebugGetHeader())
+  if (hdr == nsAutoTArray<uint32_t, MOZ_ARRAY_LENGTH(data)>().DebugGetHeader())
     return false;
 
   array.AppendElement(1u);
   if (hdr != array.DebugGetHeader())
     return false;
 
   array.RemoveElement(1u);
   array.AppendElements(data, ArrayLength(data));
@@ -481,17 +480,17 @@ static bool test_autoarray() {
       return false;
   }
   if (!array.IsEmpty())
     return false;
 
   array.Compact();
   array.AppendElements(data, ArrayLength(data));
   uint32_t data3[] = {5, 7, 11};
-  nsAutoTArray<uint32_t, NS_ARRAY_LENGTH(data3)> array3;
+  nsAutoTArray<uint32_t, MOZ_ARRAY_LENGTH(data3)> array3;
   array3.AppendElements(data3, ArrayLength(data3));  
   array.SwapElements(array3);
   for (i = 0; i < ArrayLength(data); ++i) {
     if (array3[i] != data[i])
       return false;
   }
   for (i = 0; i < ArrayLength(data3); ++i) {
     if (array[i] != data3[i])
--- a/xulrunner/stub/nsXULStub.cpp
+++ b/xulrunner/stub/nsXULStub.cpp
@@ -1,16 +1,15 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsXPCOMGlue.h"
 #include "nsINIParser.h"
 #include "nsXPCOMPrivate.h" // for XP MAXPATHLEN
-#include "nsMemory.h" // for NS_ARRAY_LENGTH
 #include "nsXULAppAPI.h"
 #include "nsIFile.h"
 
 #include <stdarg.h>
 
 #ifdef XP_WIN
 #include <windows.h>
 #include <io.h>