Bug 786533 - Replace NS_MIN/NS_MAX in xpcom/ with XPCOM_MIN/XPCOM_MAX to prevent accidental use. r=ehsan
authorMats Palmgren <matspal@gmail.com>
Tue, 15 Jan 2013 13:22:03 +0100
changeset 128757 b9d9fc98561becefc49f769a5587e659e87b5d88
parent 128756 037363fa02583ef1f37c80373e46c0a19cf73e64
child 128758 04fb583963dc5f696bdb997a1a21f8a5fa198f47
push id2323
push userbbajaj@mozilla.com
push dateMon, 01 Apr 2013 19:47:02 +0000
treeherdermozilla-beta@7712be144d91 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs786533
milestone21.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 786533 - Replace NS_MIN/NS_MAX in xpcom/ with XPCOM_MIN/XPCOM_MAX to prevent accidental use. r=ehsan
xpcom/build/FileLocation.cpp
xpcom/ds/StringBuilder.h
xpcom/ds/nsExpirationTracker.h
xpcom/glue/nsQuickSort.cpp
xpcom/glue/nsTArray-inl.h
xpcom/glue/nsVersionComparator.cpp
xpcom/glue/nsVoidArray.cpp
xpcom/glue/pldhash.cpp
xpcom/io/nsMultiplexInputStream.cpp
xpcom/io/nsPipe3.cpp
xpcom/io/nsScriptableInputStream.cpp
xpcom/io/nsStorageStream.cpp
xpcom/io/nsStreamUtils.cpp
xpcom/io/nsUnicharInputStream.cpp
xpcom/string/public/nsAlgorithm.h
xpcom/string/public/nsString.h
xpcom/string/public/nsStringIterator.h
xpcom/string/public/nsTString.h
xpcom/string/public/nsTSubstring.h
xpcom/string/src/nsReadableUtils.cpp
xpcom/string/src/nsStringObsolete.cpp
xpcom/string/src/nsTDependentSubstring.cpp
xpcom/string/src/nsTStringComparator.cpp
xpcom/string/src/nsTSubstring.cpp
xpcom/string/src/nsUTF8UtilsSSE2.cpp
xpcom/tests/TestPipes.cpp
--- a/xpcom/build/FileLocation.cpp
+++ b/xpcom/build/FileLocation.cpp
@@ -140,17 +140,17 @@ FileLocation::Data::GetSize(uint32_t *re
   return NS_ERROR_NOT_INITIALIZED;
 }
 
 nsresult
 FileLocation::Data::Copy(char *buf, uint32_t len)
 {
   if (mFd) {
     for (uint32_t totalRead = 0; totalRead < len; ) {
-      int32_t read = PR_Read(mFd, buf + totalRead, NS_MIN(len - totalRead, uint32_t(INT32_MAX)));
+      int32_t read = PR_Read(mFd, buf + totalRead, XPCOM_MIN(len - totalRead, uint32_t(INT32_MAX)));
       if (read < 0)
         return NS_ErrorAccordingToNSPR();
       totalRead += read;
     }
     return NS_OK;
   } else if (mItem) {
     nsZipCursor cursor(mItem, mZip, reinterpret_cast<uint8_t *>(buf), len, true);
     uint32_t readLen;
--- a/xpcom/ds/StringBuilder.h
+++ b/xpcom/ds/StringBuilder.h
@@ -58,17 +58,17 @@ public:
 
     size_t Length() {
         return mLength;
     }
 
     size_t EnsureCapacity(size_t capacity) {
         if (capacity > mCapacity) {
             // make sure we at least double in size
-            mCapacity = NS_MAX(capacity, mCapacity*2);
+            mCapacity = XPCOM_MAX(capacity, mCapacity*2);
             mBuffer = static_cast<char*>(realloc(mBuffer, mCapacity));
             mCapacity = moz_malloc_usable_size(mBuffer);
         }
         return mCapacity;
     }
 
     ~StringBuilder()
     {
--- a/xpcom/ds/nsExpirationTracker.h
+++ b/xpcom/ds/nsExpirationTracker.h
@@ -176,17 +176,17 @@ template <class T, uint32_t K> class nsE
       // generation. We depend on the fact that RemoveObject can only cause
       // the indexes of objects in this generation to *decrease*, not increase.
       // So if we start from the end and work our way backwards we are guaranteed
       // to see each object at least once.
       uint32_t index = generation.Length();
       for (;;) {
         // Objects could have been removed so index could be outside
         // the array
-        index = NS_MIN(index, generation.Length());
+        index = XPCOM_MIN(index, generation.Length());
         if (index == 0)
           break;
         --index;
         NotifyExpired(generation[index]);
       }
       // Any leftover objects from reapGeneration just end up in the new
       // newest-generation. This is bad form, though, so warn if there are any.
       if (!generation.IsEmpty()) {
--- a/xpcom/glue/nsQuickSort.cpp
+++ b/xpcom/glue/nsQuickSort.cpp
@@ -159,19 +159,19 @@ loop:	SWAPINIT(a, es);
 		for (pm = (char *)a + es; pm < (char *)a + n * es; pm += es)
 			for (pl = pm; pl > (char *)a && cmp(pl - es, pl, data) > 0;
 			     pl -= es)
 				swap(pl, pl - es);
 		return;
 	}
 
 	pn = (char *)a + n * es;
-	r = NS_MIN(pa - (char *)a, pb - pa);
+	r = XPCOM_MIN(pa - (char *)a, pb - pa);
 	vecswap(a, pb - r, r);
-	r = NS_MIN<size_t>(pd - pc, pn - pd - es);
+	r = XPCOM_MIN<size_t>(pd - pc, pn - pd - es);
 	vecswap(pb, pn - r, r);
 	if ((r = pb - pa) > (int)es)
         NS_QuickSort(a, r / es, es, cmp, data);
 	if ((r = pd - pc) > (int)es) {
 		/* Iterate rather than recurse to save stack space */
 		a = pn - r;
 		n = r / es;
 		goto loop;
--- a/xpcom/glue/nsTArray-inl.h
+++ b/xpcom/glue/nsTArray-inl.h
@@ -348,18 +348,18 @@ nsTArray_base<Alloc>::SwapArrayElements(
   }
 
   // The EnsureCapacity calls above shouldn't have caused *both* arrays to
   // switch from their auto buffers to malloc'ed space.
   NS_ABORT_IF_FALSE(UsesAutoArrayBuffer() ||
                     other.UsesAutoArrayBuffer(),
                     "One of the arrays should be using its auto buffer.");
 
-  size_type smallerLength = NS_MIN(Length(), other.Length());
-  size_type largerLength = NS_MAX(Length(), other.Length());
+  size_type smallerLength = XPCOM_MIN(Length(), other.Length());
+  size_type largerLength = XPCOM_MAX(Length(), other.Length());
   void *smallerElements, *largerElements;
   if (Length() <= other.Length()) {
     smallerElements = Hdr() + 1;
     largerElements = other.Hdr() + 1;
   }
   else {
     smallerElements = other.Hdr() + 1;
     largerElements = Hdr() + 1;
--- a/xpcom/glue/nsVersionComparator.cpp
+++ b/xpcom/glue/nsVersionComparator.cpp
@@ -253,17 +253,17 @@ CompareVP(VersionPart &v1, VersionPart &
 #ifdef XP_WIN
 static int32_t
 CompareVP(VersionPartW &v1, VersionPartW &v2)
 {
   int32_t r = ns_cmp(v1.numA, v2.numA);
   if (r)
     return r;
 
-  r = wcsncmp(v1.strB, v2.strB, NS_MIN(v1.strBlen,v2.strBlen));
+  r = wcsncmp(v1.strB, v2.strB, XPCOM_MIN(v1.strBlen,v2.strBlen));
   if (r)
     return r;
 
   r = ns_cmp(v1.numC, v2.numC);
   if (r)
     return r;
 
   if (!v1.extraD)
--- a/xpcom/glue/nsVoidArray.cpp
+++ b/xpcom/glue/nsVoidArray.cpp
@@ -228,17 +228,17 @@ bool nsVoidArray::GrowArrayBy(int32_t aG
   if (newSize >= (uint32_t) kLinearThreshold)
   {
     // newCount includes enough space for at least kMinGrowArrayBy new
     // slots. Select the next power-of-two size in bytes above or
     // equal to that.
     // Also, limit the increase in size to about a VM page or two.
     if (GetArraySize() >= kMaxGrowArrayBy)
     {
-      newCapacity = GetArraySize() + NS_MAX(kMaxGrowArrayBy,aGrowBy);
+      newCapacity = GetArraySize() + XPCOM_MAX(kMaxGrowArrayBy,aGrowBy);
       newSize = SIZEOF_IMPL(newCapacity);
     }
     else
     {
       PR_CEILING_LOG2(newSize, newSize);
       newCapacity = CAPACITYOF_IMPL(1u << newSize);
     }
   }
--- a/xpcom/glue/pldhash.cpp
+++ b/xpcom/glue/pldhash.cpp
@@ -268,30 +268,30 @@ PL_DHashTableSetAlphaBounds(PLDHashTable
      * Ensure that at least one entry will always be free.  If maxAlpha at
      * minimum size leaves no entries free, reduce maxAlpha based on minimum
      * size and the precision limit of maxAlphaFrac's fixed point format.
      */
     NS_ASSERTION(PL_DHASH_MIN_SIZE - (maxAlpha * PL_DHASH_MIN_SIZE) >= 1,
                  "PL_DHASH_MIN_SIZE - (maxAlpha * PL_DHASH_MIN_SIZE) >= 1");
     if (PL_DHASH_MIN_SIZE - (maxAlpha * PL_DHASH_MIN_SIZE) < 1) {
         maxAlpha = (float)
-                   (PL_DHASH_MIN_SIZE - NS_MAX(PL_DHASH_MIN_SIZE / 256, 1))
+                   (PL_DHASH_MIN_SIZE - XPCOM_MAX(PL_DHASH_MIN_SIZE / 256, 1))
                    / PL_DHASH_MIN_SIZE;
     }
 
     /*
      * Ensure that minAlpha is strictly less than half maxAlpha.  Take care
      * not to truncate an entry's worth of alpha when storing in minAlphaFrac
      * (8-bit fixed point format).
      */
     NS_ASSERTION(minAlpha < maxAlpha / 2,
                  "minAlpha < maxAlpha / 2");
     if (minAlpha >= maxAlpha / 2) {
         size = PL_DHASH_TABLE_SIZE(table);
-        minAlpha = (size * maxAlpha - NS_MAX(size / 256, 1u)) / (2 * size);
+        minAlpha = (size * maxAlpha - XPCOM_MAX(size / 256, 1u)) / (2 * size);
     }
 
     table->maxAlphaFrac = (uint8_t)(maxAlpha * 256);
     table->minAlphaFrac = (uint8_t)(minAlpha * 256);
 }
 
 /*
  * Double hashing needs the second hash code to be relatively prime to table
--- a/xpcom/io/nsMultiplexInputStream.cpp
+++ b/xpcom/io/nsMultiplexInputStream.cpp
@@ -398,17 +398,17 @@ nsMultiplexInputStream::Seek(int32_t aWh
                     remaining -= streamPos;
                     NS_ASSERTION(remaining >= 0, "Remaining invalid");
                 }
                 else {
                     uint64_t avail;
                     rv = mStreams[i]->Available(&avail);
                     NS_ENSURE_SUCCESS(rv, rv);
 
-                    int64_t newPos = NS_MIN(remaining, streamPos + (int64_t)avail);
+                    int64_t newPos = XPCOM_MIN(remaining, streamPos + (int64_t)avail);
 
                     rv = stream->Seek(NS_SEEK_SET, newPos);
                     NS_ENSURE_SUCCESS(rv, rv);
 
                     mCurrentStream = i;
                     mStartedReadingCurrent = true;
 
                     remaining -= newPos;
@@ -429,17 +429,17 @@ nsMultiplexInputStream::Seek(int32_t aWh
         for (uint32_t i = mCurrentStream; remaining && i < mStreams.Length(); ++i) {
             nsCOMPtr<nsISeekableStream> stream =
                 do_QueryInterface(mStreams[i]);
 
             uint64_t avail;
             rv = mStreams[i]->Available(&avail);
             NS_ENSURE_SUCCESS(rv, rv);
 
-            int64_t seek = NS_MIN((int64_t)avail, remaining);
+            int64_t seek = XPCOM_MIN((int64_t)avail, remaining);
 
             rv = stream->Seek(NS_SEEK_CUR, seek);
             NS_ENSURE_SUCCESS(rv, rv);
 
             mCurrentStream = i;
             mStartedReadingCurrent = true;
 
             remaining -= seek;
@@ -453,17 +453,17 @@ nsMultiplexInputStream::Seek(int32_t aWh
         for (uint32_t i = mCurrentStream; remaining && i != (uint32_t)-1; --i) {
             nsCOMPtr<nsISeekableStream> stream =
                 do_QueryInterface(mStreams[i]);
 
             int64_t pos;
             rv = stream->Tell(&pos);
             NS_ENSURE_SUCCESS(rv, rv);
 
-            int64_t seek = NS_MIN(pos, remaining);
+            int64_t seek = XPCOM_MIN(pos, remaining);
 
             rv = stream->Seek(NS_SEEK_CUR, -seek);
             NS_ENSURE_SUCCESS(rv, rv);
 
             mCurrentStream = i;
             mStartedReadingCurrent = seek != -pos;
 
             remaining -= seek;
@@ -524,17 +524,17 @@ nsMultiplexInputStream::Seek(int32_t aWh
                     (i == oldCurrentStream && !oldStartedReadingCurrent)) {
                     // We're already at start so no need to seek this stream
                     remaining += streamPos;
                 } else {
                     int64_t avail;
                     rv = stream->Tell(&avail);
                     NS_ENSURE_SUCCESS(rv, rv);
 
-                    int64_t newPos = streamPos + NS_MIN(avail, std::abs(remaining));
+                    int64_t newPos = streamPos + XPCOM_MIN(avail, std::abs(remaining));
 
                     rv = stream->Seek(NS_SEEK_END, -newPos);
                     NS_ENSURE_SUCCESS(rv, rv);
 
                     mCurrentStream = i;
                     mStartedReadingCurrent = true;
 
                     remaining += newPos;
--- a/xpcom/io/nsPipe3.cpp
+++ b/xpcom/io/nsPipe3.cpp
@@ -930,17 +930,17 @@ nsPipeInputStream::Search(const char *fo
             *found = false;
             *offsetSearchedTo = offset - strLen + 1;
             LOG(("  result [found=%u offset=%u]\n", *found, *offsetSearchedTo));
             return NS_OK;
         }
         len2 = limit2 - cursor2;
 
         // check if the string is straddling the next buffer segment
-        uint32_t lim = NS_MIN(strLen, len2 + 1);
+        uint32_t lim = XPCOM_MIN(strLen, len2 + 1);
         for (i = 0; i < lim; ++i) {
             uint32_t strPart1Len = strLen - i - 1;
             uint32_t strPart2Len = strLen - strPart1Len;
             const char* strPart2 = &forString[strLen - strPart2Len];
             uint32_t bufSeg1Offset = len1 - strPart1Len;
             if (COMPARE(&cursor1[bufSeg1Offset], forString, strPart1Len) == 0 &&
                 COMPARE(cursor2, strPart2, strPart2Len) == 0) {
                 *found = true;
--- a/xpcom/io/nsScriptableInputStream.cpp
+++ b/xpcom/io/nsScriptableInputStream.cpp
@@ -36,17 +36,17 @@ nsScriptableInputStream::Read(uint32_t a
     char *buffer = nullptr;
 
     if (!mInputStream) return NS_ERROR_NOT_INITIALIZED;
 
     rv = mInputStream->Available(&count64);
     if (NS_FAILED(rv)) return rv;
 
     // bug716556 - Ensure count+1 doesn't overflow
-    uint32_t count = NS_MIN((uint32_t)NS_MIN<uint64_t>(count64, aCount), UINT32_MAX - 1);
+    uint32_t count = XPCOM_MIN((uint32_t)XPCOM_MIN<uint64_t>(count64, aCount), UINT32_MAX - 1);
     buffer = (char*)nsMemory::Alloc(count+1); // make room for '\0'
     if (!buffer) return NS_ERROR_OUT_OF_MEMORY;
 
     uint32_t amtRead = 0;
     rv = mInputStream->Read(buffer, count, &amtRead);
     if (NS_FAILED(rv)) {
         nsMemory::Free(buffer);
         return rv;
--- a/xpcom/io/nsStorageStream.cpp
+++ b/xpcom/io/nsStorageStream.cpp
@@ -175,17 +175,17 @@ nsStorageStream::Write(const char *aBuff
             }
             mLastSegmentNum++;
             mSegmentEnd = mWriteCursor + mSegmentSize;
             availableInSegment = mSegmentEnd - mWriteCursor;
             LOG(("nsStorageStream [%p] Write (new seg) mWriteCursor=%x mSegmentEnd=%x\n",
                 this, mWriteCursor, mSegmentEnd));
         }
 	
-        count = NS_MIN(availableInSegment, remaining);
+        count = XPCOM_MIN(availableInSegment, remaining);
         memcpy(mWriteCursor, readCursor, count);
         remaining -= count;
         readCursor += count;
         mWriteCursor += count;
         LOG(("nsStorageStream [%p] Writing mWriteCursor=%x mSegmentEnd=%x count=%d\n",
             this, mWriteCursor, mSegmentEnd, count));
     };
 
@@ -413,22 +413,22 @@ nsStorageInputStream::ReadSegments(nsWri
         availableInSegment = mSegmentEnd - mReadCursor;
         if (!availableInSegment) {
             uint32_t available = mStorageStream->mLogicalLength - mLogicalCursor;
             if (!available)
                 goto out;
 
             mSegmentNum++;
             mReadCursor = 0;
-            mSegmentEnd = NS_MIN(mSegmentSize, available);
+            mSegmentEnd = XPCOM_MIN(mSegmentSize, available);
             availableInSegment = mSegmentEnd;
         }
         const char *cur = mStorageStream->mSegmentedBuffer->GetSegment(mSegmentNum);
 	
-        count = NS_MIN(availableInSegment, remainingCapacity);
+        count = XPCOM_MIN(availableInSegment, remainingCapacity);
         rv = writer(this, closure, cur + mReadCursor, aCount - remainingCapacity,
                     count, &bytesConsumed);
         if (NS_FAILED(rv) || (bytesConsumed == 0))
           break;
         remainingCapacity -= bytesConsumed;
         mReadCursor += bytesConsumed;
         mLogicalCursor += bytesConsumed;
     };
@@ -508,17 +508,17 @@ nsStorageInputStream::Seek(uint32_t aPos
         return NS_ERROR_INVALID_ARG;
 
     if (length == 0)
         return NS_OK;
 
     mSegmentNum = SegNum(aPosition);
     mReadCursor = SegOffset(aPosition);
     uint32_t available = length - aPosition;
-    mSegmentEnd = mReadCursor + NS_MIN(mSegmentSize - mReadCursor, available);
+    mSegmentEnd = mReadCursor + XPCOM_MIN(mSegmentSize - mReadCursor, available);
     mLogicalCursor = aPosition;
     return NS_OK;
 }
 
 nsresult
 NS_NewStorageStream(uint32_t segmentSize, uint32_t maxSize, nsIStorageStream **result)
 {
     NS_ENSURE_ARG(result);
--- a/xpcom/io/nsStreamUtils.cpp
+++ b/xpcom/io/nsStreamUtils.cpp
@@ -624,17 +624,17 @@ NS_ConsumeStream(nsIInputStream *stream,
         if (NS_FAILED(rv)) {
             if (rv == NS_BASE_STREAM_CLOSED)
                 rv = NS_OK;
             break;
         }
         if (avail64 == 0)
             break;
 
-        uint32_t avail = (uint32_t)NS_MIN<uint64_t>(avail64, maxCount);
+        uint32_t avail = (uint32_t)XPCOM_MIN<uint64_t>(avail64, maxCount);
 
         // resize result buffer
         uint32_t length = result.Length();
         if (avail > UINT32_MAX - length)
             return NS_ERROR_FILE_TOO_BIG;
         
         result.SetLength(length + avail);
         if (result.Length() != (length + avail))
--- a/xpcom/io/nsUnicharInputStream.cpp
+++ b/xpcom/io/nsUnicharInputStream.cpp
@@ -64,17 +64,17 @@ NS_IMETHODIMP
 StringUnicharInputStream::ReadSegments(nsWriteUnicharSegmentFun aWriter,
                                        void* aClosure,
                                        uint32_t aCount, uint32_t *aReadCount)
 {
   uint32_t bytesWritten;
   uint32_t totalBytesWritten = 0;
 
   nsresult rv;
-  aCount = NS_MIN(mString.Length() - mPos, aCount);
+  aCount = XPCOM_MIN(mString.Length() - mPos, aCount);
   
   nsAString::const_iterator iter;
   mString.BeginReading(iter);
   
   while (aCount) {
     rv = aWriter(this, aClosure, iter.get() + mPos,
                  totalBytesWritten, aCount, &bytesWritten);
     
--- a/xpcom/string/public/nsAlgorithm.h
+++ b/xpcom/string/public/nsAlgorithm.h
@@ -23,26 +23,26 @@ T
 NS_ROUNDUP( const T& a, const T& b )
   {
     return ((a + (b - 1)) / b) * b;
   }
 
 template <class T>
 inline
 const T&
-NS_MIN( const T& a, const T& b )
+XPCOM_MIN( const T& a, const T& b )
   {
     return b < a ? b : a;
   }
 
 // Must return b when a == b in case a is -0
 template <class T>
 inline
 const T&
-NS_MAX( const T& a, const T& b )
+XPCOM_MAX( const T& a, const T& b )
   {
     return a > b ? a : b;
   }
 
 #if defined(_MSC_VER) && (_MSC_VER < 1600)
 namespace std {
 inline
 long long
@@ -56,17 +56,17 @@ abs( const long long& a )
 namespace mozilla {
 
 template <class T>
 inline
 const T&
 clamped( const T& a, const T& min, const T& max )
   {
     NS_ABORT_IF_FALSE(max >= min, "clamped(): max must be greater than or equal to min");
-    return NS_MIN(NS_MAX(a, min), max);
+    return XPCOM_MIN(XPCOM_MAX(a, min), max);
   }
 
 }
 
 template <class InputIterator, class T>
 inline
 uint32_t
 NS_COUNT( InputIterator& first, const InputIterator& last, const T& value )
--- a/xpcom/string/public/nsString.h
+++ b/xpcom/string/public/nsString.h
@@ -183,22 +183,22 @@ typedef nsAutoString nsVoidableString;
 // need to include these for backwards compatibility
 #include "nsMemory.h"
 #include <string.h>
 #include <stdio.h>
 #include "plhash.h"
 
 inline int32_t MinInt(int32_t x, int32_t y)
   {
-    return NS_MIN(x, y);
+    return XPCOM_MIN(x, y);
   }
 
 inline int32_t MaxInt(int32_t x, int32_t y)
   {
-    return NS_MAX(x, y);
+    return XPCOM_MAX(x, y);
   }
 
 /**
  * Deprecated: don't use |Recycle|, just call |nsMemory::Free| directly
  *
  * Return the given buffer to the heap manager. Calls allocator::Free()
  */
 inline void Recycle( char* aBuffer) { nsMemory::Free(aBuffer); }
--- a/xpcom/string/public/nsStringIterator.h
+++ b/xpcom/string/public/nsStringIterator.h
@@ -129,25 +129,25 @@ class nsReadingIterator
           return mPosition - mStart;
         }
 
       self_type&
       advance( difference_type n )
         {
           if (n > 0)
             {
-              difference_type step = NS_MIN(n, size_forward());
+              difference_type step = XPCOM_MIN(n, size_forward());
 
               NS_ASSERTION(step>0, "can't advance a reading iterator beyond the end of a string");
 
               mPosition += step;
             }
           else if (n < 0)
             {
-              difference_type step = NS_MAX(n, -size_backward());
+              difference_type step = XPCOM_MAX(n, -size_backward());
 
               NS_ASSERTION(step<0, "can't advance (backward) a reading iterator beyond the end of a string");
 
               mPosition += step;
             }
           return *this;
         }
   };
@@ -263,25 +263,25 @@ class nsWritingIterator
           return mPosition - mStart;
         }
 
       self_type&
       advance( difference_type n )
         {
           if (n > 0)
             {
-              difference_type step = NS_MIN(n, size_forward());
+              difference_type step = XPCOM_MIN(n, size_forward());
 
               NS_ASSERTION(step>0, "can't advance a writing iterator beyond the end of a string");
 
               mPosition += step;
             }
           else if (n < 0)
             {
-              difference_type step = NS_MAX(n, -size_backward());
+              difference_type step = XPCOM_MAX(n, -size_backward());
 
               NS_ASSERTION(step<0, "can't advance (backward) a writing iterator beyond the end of a string");
 
               mPosition += step;
             }
           return *this;
         }
 
--- a/xpcom/string/public/nsTString.h
+++ b/xpcom/string/public/nsTString.h
@@ -281,17 +281,17 @@ class nsTString_CharT : public nsTSubstr
 
       size_type Left( self_type& aResult, size_type aCount ) const
         {
           return Mid(aResult, 0, aCount);
         }
 
       size_type Right( self_type& aResult, size_type aCount ) const
         {
-          aCount = NS_MIN(mLength, aCount);
+          aCount = XPCOM_MIN(mLength, aCount);
           return Mid(aResult, mLength - aCount, aCount);
         }
 
 
         /**
          * Set a char inside this string at given index
          *
          * @param aChar is the char you want to write into this string
--- a/xpcom/string/public/nsTSubstring.h
+++ b/xpcom/string/public/nsTSubstring.h
@@ -705,17 +705,17 @@ class nsTSubstring_CharT
          * modified.  this function will null-terminate mData upon return.
          * 
          * this function returns false if is unable to allocate sufficient
          * memory.
          */
       bool ReplacePrep(index_type cutStart, size_type cutLength,
                        size_type newLength) NS_WARN_UNUSED_RESULT
       {
-        cutLength = NS_MIN(cutLength, mLength - cutStart);
+        cutLength = XPCOM_MIN(cutLength, mLength - cutStart);
         uint32_t newTotalLen = mLength - cutLength + newLength;
         if (cutStart == mLength && Capacity() > newTotalLen) {
           mFlags &= ~F_VOIDED;
           mData[newTotalLen] = char_type(0);
           mLength = newTotalLen;
           return true;
         }
         return ReplacePrepInternal(cutStart, cutLength, newLength, newTotalLen);
--- a/xpcom/string/src/nsReadableUtils.cpp
+++ b/xpcom/string/src/nsReadableUtils.cpp
@@ -573,17 +573,17 @@ class CopyToUpperCase
       CopyToUpperCase( nsACString::iterator& aDestIter )
         : mIter(aDestIter)
         {
         }
 
       uint32_t
       write( const char* aSource, uint32_t aSourceLength )
         {
-          uint32_t len = NS_MIN(uint32_t(mIter.size_forward()), aSourceLength);
+          uint32_t len = XPCOM_MIN(uint32_t(mIter.size_forward()), aSourceLength);
           char* cp = mIter.get();
           const char* end = aSource + len;
           while (aSource != end) {
             char ch = *aSource;
             if ((ch >= 'a') && (ch <= 'z'))
               *cp = ch - ('a' - 'A');
             else
               *cp = ch;
@@ -652,17 +652,17 @@ class CopyToLowerCase
       CopyToLowerCase( nsACString::iterator& aDestIter )
         : mIter(aDestIter)
         {
         }
 
       uint32_t
       write( const char* aSource, uint32_t aSourceLength )
         {
-          uint32_t len = NS_MIN(uint32_t(mIter.size_forward()), aSourceLength);
+          uint32_t len = XPCOM_MIN(uint32_t(mIter.size_forward()), aSourceLength);
           char* cp = mIter.get();
           const char* end = aSource + len;
           while (aSource != end) {
             char ch = *aSource;
             if ((ch >= 'A') && (ch <= 'Z'))
               *cp = ch + ('a' - 'A');
             else
               *cp = ch;
--- a/xpcom/string/src/nsStringObsolete.cpp
+++ b/xpcom/string/src/nsStringObsolete.cpp
@@ -920,17 +920,17 @@ nsString::FindCharInSet( const PRUnichar
    * nsTString::Compare,CompareWithConversion,etc.
    */
 
 int32_t
 nsCString::Compare( const char* aString, bool aIgnoreCase, int32_t aCount ) const
   {
     uint32_t strLen = char_traits::length(aString);
 
-    int32_t maxCount = int32_t(NS_MIN(mLength, strLen));
+    int32_t maxCount = int32_t(XPCOM_MIN(mLength, strLen));
 
     int32_t compareCount;
     if (aCount < 0 || aCount > maxCount)
       compareCount = maxCount;
     else
       compareCount = aCount;
 
     int32_t result =
@@ -949,17 +949,17 @@ nsCString::Compare( const char* aString,
     return result;
   }
 
 bool
 nsString::EqualsIgnoreCase( const char* aString, int32_t aCount ) const
   {
     uint32_t strLen = nsCharTraits<char>::length(aString);
 
-    int32_t maxCount = int32_t(NS_MIN(mLength, strLen));
+    int32_t maxCount = int32_t(XPCOM_MIN(mLength, strLen));
 
     int32_t compareCount;
     if (aCount < 0 || aCount > maxCount)
       compareCount = maxCount;
     else
       compareCount = aCount;
 
     int32_t result =
--- a/xpcom/string/src/nsTDependentSubstring.cpp
+++ b/xpcom/string/src/nsTDependentSubstring.cpp
@@ -11,17 +11,17 @@ nsTDependentSubstring_CharT::Rebind( con
     Finalize();
 
     size_type strLength = str.Length();
 
     if (startPos > strLength)
       startPos = strLength;
 
     mData = const_cast<char_type*>(str.Data()) + startPos;
-    mLength = NS_MIN(length, strLength - startPos);
+    mLength = XPCOM_MIN(length, strLength - startPos);
 
     SetDataFlags(F_NONE);
   }
 
 void
 nsTDependentSubstring_CharT::Rebind( const char_type* data, size_type length )
   {
     NS_ASSERTION(data, "nsTDependentSubstring must wrap a non-NULL buffer");
--- a/xpcom/string/src/nsTStringComparator.cpp
+++ b/xpcom/string/src/nsTStringComparator.cpp
@@ -13,17 +13,17 @@ Compare( const nsTSubstring_CharT::base_
       return 0;
 
     nsTSubstring_CharT::const_iterator leftIter, rightIter;
     lhs.BeginReading(leftIter);
     rhs.BeginReading(rightIter);
 
     size_type lLength = leftIter.size_forward();
     size_type rLength = rightIter.size_forward();
-    size_type lengthToCompare = NS_MIN(lLength, rLength);
+    size_type lengthToCompare = XPCOM_MIN(lLength, rLength);
 
     int result;
     if ( (result = comp(leftIter.get(), rightIter.get(), lengthToCompare, lengthToCompare)) == 0 )
       {
         if ( lLength < rLength )
           result = -1;
         else if ( rLength < lLength )
           result = 1;
--- a/xpcom/string/src/nsTSubstring.cpp
+++ b/xpcom/string/src/nsTSubstring.cpp
@@ -70,19 +70,19 @@ nsTSubstring_CharT::MutatePrep( size_typ
           mFlags &= ~F_VOIDED;  // mutation clears voided flag
           return true;
         }
 
         // Use doubling algorithm when forced to increase available capacity.
         size_type temp = curCapacity;
         while (temp < capacity)
           temp <<= 1;
-        NS_ASSERTION(NS_MIN(temp, kMaxCapacity) >= capacity,
+        NS_ASSERTION(XPCOM_MIN(temp, kMaxCapacity) >= capacity,
                      "should have hit the early return at the top");
-        capacity = NS_MIN(temp, kMaxCapacity);
+        capacity = XPCOM_MIN(temp, kMaxCapacity);
       }
 
     //
     // several cases:
     //
     //  (1) we have a shared buffer (mFlags & F_SHARED)
     //  (2) we have an owned buffer (mFlags & F_OWNED)
     //  (3) we have a fixed buffer (mFlags & F_FIXED)
@@ -446,17 +446,17 @@ nsTSubstring_CharT::Adopt( char_type* da
       }
   }
 
 
   // This version of Replace is optimized for single-character replacement.
 void
 nsTSubstring_CharT::Replace( index_type cutStart, size_type cutLength, char_type c )
   {
-    cutStart = NS_MIN(cutStart, Length());
+    cutStart = XPCOM_MIN(cutStart, Length());
 
     if (ReplacePrep(cutStart, cutLength, 1))
       mData[cutStart] = c;
   }
 
 
 void
 nsTSubstring_CharT::Replace( index_type cutStart, size_type cutLength, const char_type* data, size_type length )
@@ -474,17 +474,17 @@ nsTSubstring_CharT::Replace( index_type 
         if (IsDependentOn(data, data + length))
           {
             nsTAutoString_CharT temp(data, length);
             Replace(cutStart, cutLength, temp);
             return;
           }
       }
 
-    cutStart = NS_MIN(cutStart, Length());
+    cutStart = XPCOM_MIN(cutStart, Length());
 
     if (ReplacePrep(cutStart, cutLength, length) && length > 0)
       char_traits::copy(mData + cutStart, data, length);
   }
 
 void
 nsTSubstring_CharT::ReplaceASCII( index_type cutStart, size_type cutLength, const char* data, size_type length )
   {
@@ -497,17 +497,17 @@ nsTSubstring_CharT::ReplaceASCII( index_
     if (IsDependentOn(data, data + length))
       {
         nsTAutoString_CharT temp(data, length);
         Replace(cutStart, cutLength, temp);
         return;
       }
 #endif
 
-    cutStart = NS_MIN(cutStart, Length());
+    cutStart = XPCOM_MIN(cutStart, Length());
 
     if (ReplacePrep(cutStart, cutLength, length) && length > 0)
       char_traits::copyASCII(mData + cutStart, data, length);
   }
 
 void
 nsTSubstring_CharT::Replace( index_type cutStart, size_type cutLength, const substring_tuple_type& tuple )
   {
@@ -515,17 +515,17 @@ nsTSubstring_CharT::Replace( index_type 
       {
         nsTAutoString_CharT temp(tuple);
         Replace(cutStart, cutLength, temp);
         return;
       }
 
     size_type length = tuple.Length();
 
-    cutStart = NS_MIN(cutStart, Length());
+    cutStart = XPCOM_MIN(cutStart, Length());
 
     if (ReplacePrep(cutStart, cutLength, length) && length > 0)
       tuple.WriteTo(mData + cutStart, length);
   }
 
 void
 nsTSubstring_CharT::SetCapacity( size_type capacity )
   {
@@ -549,17 +549,17 @@ nsTSubstring_CharT::SetCapacity( size_ty
       }
 
     char_type* oldData;
     uint32_t oldFlags;
     if (!MutatePrep(capacity, &oldData, &oldFlags))
       return false; // out-of-memory
 
     // compute new string length
-    size_type newLen = NS_MIN(mLength, capacity);
+    size_type newLen = XPCOM_MIN(mLength, capacity);
 
     if (oldData)
       {
         // preserve old data
         if (mLength > 0)
           char_traits::copy(mData, oldData, newLen);
 
         ::ReleaseData(oldData, oldFlags);
--- a/xpcom/string/src/nsUTF8UtilsSSE2.cpp
+++ b/xpcom/string/src/nsUTF8UtilsSSE2.cpp
@@ -11,17 +11,17 @@ void
 LossyConvertEncoding16to8::write_sse2(const PRUnichar* aSource,
                                       uint32_t aSourceLength)
 {
   char* dest = mDestination;
 
   // Align source to a 16-byte boundary.
   uint32_t i = 0;
   uint32_t alignLen =
-    NS_MIN<uint32_t>(aSourceLength, uint32_t(-NS_PTR_TO_INT32(aSource) & 0xf) / sizeof(PRUnichar));
+    XPCOM_MIN<uint32_t>(aSourceLength, uint32_t(-NS_PTR_TO_INT32(aSource) & 0xf) / sizeof(PRUnichar));
   for (; i < alignLen; i++) {
     dest[i] = static_cast<unsigned char>(aSource[i]);
   }
 
   // Walk 64 bytes (four XMM registers) at a time.
   __m128i vectmask = _mm_set1_epi16(0x00ff);
   for (; aSourceLength - i > 31; i += 32) {
     __m128i source1 = _mm_load_si128(reinterpret_cast<const __m128i*>(aSource + i));
@@ -64,17 +64,17 @@ LossyConvertEncoding8to16::write_sse2(co
 {
   PRUnichar *dest = mDestination;
 
   // Align source to a 16-byte boundary.  We choose to align source rather than
   // dest because we'd rather have our loads than our stores be fast. You have
   // to wait for a load to complete, but you can keep on moving after issuing a
   // store.
   uint32_t i = 0;
-  uint32_t alignLen = NS_MIN(aSourceLength, uint32_t(-NS_PTR_TO_INT32(aSource) & 0xf));
+  uint32_t alignLen = XPCOM_MIN(aSourceLength, uint32_t(-NS_PTR_TO_INT32(aSource) & 0xf));
   for (; i < alignLen; i++) {
     dest[i] = static_cast<unsigned char>(aSource[i]);
   }
 
   // Walk 32 bytes (two XMM registers) at a time.
   for (; aSourceLength - i > 31; i += 32) {
     __m128i source1 = _mm_load_si128(reinterpret_cast<const __m128i*>(aSource + i));
     __m128i source2 = _mm_load_si128(reinterpret_cast<const __m128i*>(aSource + i + 16));
--- a/xpcom/tests/TestPipes.cpp
+++ b/xpcom/tests/TestPipes.cpp
@@ -277,17 +277,17 @@ TestShortWrites(nsIInputStream* in, nsIO
     if (NS_FAILED(rv)) return rv;
 
     uint32_t total = 0;
     for (uint32_t i = 0; i < ITERATIONS; i++) {
         uint32_t writeCount;
         char* buf = PR_smprintf("%d %s", i, kTestPattern);
         uint32_t len = strlen(buf);
         len = len * rand() / RAND_MAX;
-        len = NS_MAX(1, len);
+        len = XPCOM_MAX(1, len);
         rv = WriteAll(out, buf, len, &writeCount);
         if (NS_FAILED(rv)) return rv;
         NS_ASSERTION(writeCount == len, "didn't write enough");
         total += writeCount;
 
         if (gTrace)
             printf("wrote %d bytes: %s\n", writeCount, buf);
         PR_smprintf_free(buf);
@@ -386,17 +386,17 @@ TestChainedPipes()
     if (NS_FAILED(rv)) return rv;
 
     uint32_t total = 0;
     for (uint32_t i = 0; i < ITERATIONS; i++) {
         uint32_t writeCount;
         char* buf = PR_smprintf("%d %s", i, kTestPattern);
         uint32_t len = strlen(buf);
         len = len * rand() / RAND_MAX;
-        len = NS_MAX(1, len);
+        len = XPCOM_MAX(1, len);
         rv = WriteAll(out1, buf, len, &writeCount);
         if (NS_FAILED(rv)) return rv;
         NS_ASSERTION(writeCount == len, "didn't write enough");
         total += writeCount;
 
         if (gTrace)
             printf("wrote %d bytes: %s\n", writeCount, buf);