Skip to content

Commit

Permalink
Bug 786533 - Replace NS_MIN/NS_MAX with std::min/std::max and #includ…
Browse files Browse the repository at this point in the history
…e <algorithm> where needed. r=ehsan
  • Loading branch information
MatsPalmgren committed Jan 15, 2013
1 parent e5ca73c commit a4fba22
Show file tree
Hide file tree
Showing 337 changed files with 1,739 additions and 1,410 deletions.
7 changes: 4 additions & 3 deletions accessible/src/base/TextUpdater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "Accessible-inl.h"
#include "DocAccessible-inl.h"
#include "TextLeafAccessible.h"
#include <algorithm>

using namespace mozilla::a11y;

Expand All @@ -19,7 +20,7 @@ TextUpdater::Run(DocAccessible* aDocument, TextLeafAccessible* aTextLeaf,

const nsString& oldText = aTextLeaf->Text();
uint32_t oldLen = oldText.Length(), newLen = aNewText.Length();
uint32_t minLen = NS_MIN(oldLen, newLen);
uint32_t minLen = std::min(oldLen, newLen);

// Skip coinciding begin substrings.
uint32_t skipStart = 0;
Expand Down Expand Up @@ -55,7 +56,7 @@ TextUpdater::DoUpdate(const nsAString& aNewText, const nsAString& aOldText,
"Text leaf hasn't offset within hyper text!");

uint32_t oldLen = aOldText.Length(), newLen = aNewText.Length();
uint32_t minLen = NS_MIN(oldLen, newLen);
uint32_t minLen = std::min(oldLen, newLen);

// Trim coinciding substrings from the end.
uint32_t skipEnd = 0;
Expand Down Expand Up @@ -120,7 +121,7 @@ TextUpdater::DoUpdate(const nsAString& aNewText, const nsAString& aOldText,
uint32_t left = row[colIdx - 1];
uint32_t up = prevRow[colIdx];
uint32_t upleft = prevRow[colIdx - 1];
row[colIdx] = NS_MIN(upleft, NS_MIN(left, up)) + 1;
row[colIdx] = std::min(upleft, std::min(left, up)) + 1;
} else {
row[colIdx] = prevRow[colIdx - 1];
}
Expand Down
3 changes: 2 additions & 1 deletion accessible/src/generic/HyperTextAccessible.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "nsTextFragment.h"
#include "mozilla/Selection.h"
#include "gfxSkipChars.h"
#include <algorithm>

using namespace mozilla;
using namespace mozilla::a11y;
Expand Down Expand Up @@ -178,7 +179,7 @@ HyperTextAccessible::GetBoundsForString(nsIFrame* aFrame, uint32_t aStartRendere
frame->GetOffsets(startFrameTextOffset, endFrameTextOffset);
int32_t frameTotalTextLength = endFrameTextOffset - startFrameTextOffset;
int32_t seekLength = endContentOffset - startContentOffset;
int32_t frameSubStringLength = NS_MIN(frameTotalTextLength - startContentOffsetInFrame, seekLength);
int32_t frameSubStringLength = std::min(frameTotalTextLength - startContentOffsetInFrame, seekLength);

// Add the point where the string starts to the frameScreenRect
nsPoint frameTextStartPoint;
Expand Down
5 changes: 3 additions & 2 deletions browser/components/feeds/src/nsFeedSniffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "nsIMIMEHeaderParam.h"

#include "nsMimeTypes.h"
#include <algorithm>

#define TYPE_ATOM "application/atom+xml"
#define TYPE_RSS "application/rss+xml"
Expand Down Expand Up @@ -286,10 +287,10 @@ nsFeedSniffer::GetMIMETypeFromContent(nsIRequest* request,
const char* testData;
if (mDecodedData.IsEmpty()) {
testData = (const char*)data;
length = NS_MIN(length, MAX_BYTES);
length = std::min(length, MAX_BYTES);
} else {
testData = mDecodedData.get();
length = NS_MIN(mDecodedData.Length(), MAX_BYTES);
length = std::min(mDecodedData.Length(), MAX_BYTES);
}

// The strategy here is based on that described in:
Expand Down
7 changes: 4 additions & 3 deletions content/base/src/nsAttrValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "nsHTMLCSSStyleSheet.h"
#include "nsCSSParser.h"
#include "nsStyledElement.h"
#include <algorithm>

using namespace mozilla;

Expand Down Expand Up @@ -1451,7 +1452,7 @@ nsAttrValue::ParseSpecialIntValue(const nsAString& aString)
return false;
}

int32_t val = NS_MAX(originalVal, 0);
int32_t val = std::max(originalVal, 0);

// % (percent)
if (isPercent || tmp.RFindChar('%') >= 0) {
Expand Down Expand Up @@ -1481,8 +1482,8 @@ nsAttrValue::ParseIntWithBounds(const nsAString& aString,
return false;
}

int32_t val = NS_MAX(originalVal, aMin);
val = NS_MIN(val, aMax);
int32_t val = std::max(originalVal, aMin);
val = std::min(val, aMax);
strict = strict && (originalVal == val);
SetIntValueAndType(val, eInteger, strict ? nullptr : &aString);

Expand Down
3 changes: 2 additions & 1 deletion content/base/src/nsContentList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "mozilla/dom/BindingUtils.h"
#include "mozilla/Likely.h"
#include "nsGenericHTMLElement.h"
#include <algorithm>

// Form related includes
#include "nsIDOMHTMLFormElement.h"
Expand Down Expand Up @@ -567,7 +568,7 @@ nsContentList::Item(uint32_t aIndex, bool aDoFlush)
}

if (mState != LIST_UP_TO_DATE)
PopulateSelf(NS_MIN(aIndex, UINT32_MAX - 1) + 1);
PopulateSelf(std::min(aIndex, UINT32_MAX - 1) + 1);

ASSERT_IN_SYNC;
NS_ASSERTION(!mRootNode || mState != LIST_DIRTY,
Expand Down
11 changes: 6 additions & 5 deletions content/base/src/nsContentUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@
#include "nsILoadContext.h"
#include "nsTextFragment.h"
#include "mozilla/Selection.h"
#include <algorithm>

#ifdef IBMBIDI
#include "nsIBidiKeyboard.h"
Expand Down Expand Up @@ -1928,7 +1929,7 @@ nsContentUtils::GetCommonAncestor(nsINode* aNode1,
uint32_t pos2 = parents2.Length();
nsINode* parent = nullptr;
uint32_t len;
for (len = NS_MIN(pos1, pos2); len > 0; --len) {
for (len = std::min(pos1, pos2); len > 0; --len) {
nsINode* child1 = parents1.ElementAt(--pos1);
nsINode* child2 = parents2.ElementAt(--pos2);
if (child1 != child2) {
Expand Down Expand Up @@ -1979,7 +1980,7 @@ nsContentUtils::ComparePoints(nsINode* aParent1, int32_t aOffset1,
// Find where the parent chains differ
nsINode* parent = parents1.ElementAt(pos1);
uint32_t len;
for (len = NS_MIN(pos1, pos2); len > 0; --len) {
for (len = std::min(pos1, pos2); len > 0; --len) {
nsINode* child1 = parents1.ElementAt(--pos1);
nsINode* child2 = parents2.ElementAt(--pos2);
if (child1 != child2) {
Expand Down Expand Up @@ -4714,7 +4715,7 @@ nsContentUtils::GetLocalizedEllipsis()
static PRUnichar sBuf[4] = { 0, 0, 0, 0 };
if (!sBuf[0]) {
nsAdoptingString tmp = Preferences::GetLocalizedString("intl.ellipsis");
uint32_t len = NS_MIN(uint32_t(tmp.Length()),
uint32_t len = std::min(uint32_t(tmp.Length()),
uint32_t(ArrayLength(sBuf) - 1));
CopyUnicodeTo(tmp, 0, sBuf, len);
if (!sBuf[0])
Expand Down Expand Up @@ -6733,8 +6734,8 @@ nsContentUtils::GetSelectionInTextControl(Selection* aSelection,
}

// Make sure aOutStartOffset <= aOutEndOffset.
aOutStartOffset = NS_MIN(anchorOffset, focusOffset);
aOutEndOffset = NS_MAX(anchorOffset, focusOffset);
aOutStartOffset = std::min(anchorOffset, focusOffset);
aOutEndOffset = std::max(anchorOffset, focusOffset);
}

nsIEditor*
Expand Down
3 changes: 2 additions & 1 deletion content/base/src/nsCrossSiteListenerProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "nsHashKeys.h"
#include "nsStreamUtils.h"
#include "mozilla/Preferences.h"
#include <algorithm>

using namespace mozilla;

Expand Down Expand Up @@ -883,7 +884,7 @@ nsCORSPreflightListener::AddResultToCache(nsIRequest *aRequest)
}
age = age * 10 + (*iter - '0');
// Cap at 24 hours. This also avoids overflow
age = NS_MIN(age, 86400U);
age = std::min(age, 86400U);
++iter;
}

Expand Down
5 changes: 3 additions & 2 deletions content/base/src/nsDOMBlobBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "nsJSUtils.h"
#include "nsContentUtils.h"
#include "nsIScriptError.h"
#include <algorithm>

using namespace mozilla;
using namespace mozilla::dom;
Expand Down Expand Up @@ -94,7 +95,7 @@ nsDOMMultipartFile::CreateSlice(uint64_t aStart, uint64_t aLength,
NS_ENSURE_SUCCESS(rv, nullptr);

if (skipStart < l) {
uint64_t upperBound = NS_MIN<uint64_t>(l - skipStart, length);
uint64_t upperBound = std::min<uint64_t>(l - skipStart, length);

nsCOMPtr<nsIDOMBlob> firstBlob;
rv = blob->Slice(skipStart, skipStart + upperBound,
Expand Down Expand Up @@ -133,7 +134,7 @@ nsDOMMultipartFile::CreateSlice(uint64_t aStart, uint64_t aLength,
} else {
blobs.AppendElement(blob);
}
length -= NS_MIN<uint64_t>(l, length);
length -= std::min<uint64_t>(l, length);
}

// we can create our blob now
Expand Down
3 changes: 2 additions & 1 deletion content/base/src/nsDOMBlobBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include "mozilla/CheckedInt.h"
#include "mozilla/Attributes.h"
#include <algorithm>

class nsDOMMultipartFile : public nsDOMFile,
public nsIJSNativeInitializer
Expand Down Expand Up @@ -133,7 +134,7 @@ class BlobSet {

// Start at 1 or we'll loop forever.
CheckedUint32 bufferLen =
NS_MAX<uint32_t>(static_cast<uint32_t>(mDataBufferLen), 1);
std::max<uint32_t>(static_cast<uint32_t>(mDataBufferLen), 1);
while (bufferLen.isValid() && bufferLen.value() < mDataLen + aSize)
bufferLen *= 2;

Expand Down
29 changes: 15 additions & 14 deletions content/base/src/nsDocument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "mozilla/DebugOnly.h"
#include "mozilla/Util.h"
#include "mozilla/Likely.h"
#include <algorithm>

#ifdef MOZ_LOGGING
// so we can get logging even in release builds
Expand Down Expand Up @@ -6523,8 +6524,8 @@ nsDocument::GetViewportInfo(uint32_t aDisplayWidth,
mScaleMinFloat = kViewportMinScale;
}

mScaleMinFloat = NS_MIN((double)mScaleMinFloat, kViewportMaxScale);
mScaleMinFloat = NS_MAX((double)mScaleMinFloat, kViewportMinScale);
mScaleMinFloat = std::min((double)mScaleMinFloat, kViewportMaxScale);
mScaleMinFloat = std::max((double)mScaleMinFloat, kViewportMinScale);

nsAutoString maxScaleStr;
GetHeaderData(nsGkAtoms::viewport_maximum_scale, maxScaleStr);
Expand All @@ -6538,8 +6539,8 @@ nsDocument::GetViewportInfo(uint32_t aDisplayWidth,
mScaleMaxFloat = kViewportMaxScale;
}

mScaleMaxFloat = NS_MIN((double)mScaleMaxFloat, kViewportMaxScale);
mScaleMaxFloat = NS_MAX((double)mScaleMaxFloat, kViewportMinScale);
mScaleMaxFloat = std::min((double)mScaleMaxFloat, kViewportMaxScale);
mScaleMaxFloat = std::max((double)mScaleMaxFloat, kViewportMinScale);

nsAutoString scaleStr;
GetHeaderData(nsGkAtoms::viewport_initial_scale, scaleStr);
Expand Down Expand Up @@ -6626,26 +6627,26 @@ nsDocument::GetViewportInfo(uint32_t aDisplayWidth,
height = aDisplayHeight / pixelRatio;
}

width = NS_MIN(width, kViewportMaxWidth);
width = NS_MAX(width, kViewportMinWidth);
width = std::min(width, kViewportMaxWidth);
width = std::max(width, kViewportMinWidth);

// Also recalculate the default zoom, if it wasn't specified in the metadata,
// and the width is specified.
if (mScaleStrEmpty && !mWidthStrEmpty) {
scaleFloat = NS_MAX(scaleFloat, float(aDisplayWidth) / float(width));
scaleFloat = std::max(scaleFloat, float(aDisplayWidth) / float(width));
}

height = NS_MIN(height, kViewportMaxHeight);
height = NS_MAX(height, kViewportMinHeight);
height = std::min(height, kViewportMaxHeight);
height = std::max(height, kViewportMinHeight);

// We need to perform a conversion, but only if the initial or maximum
// scale were set explicitly by the user.
if (mValidScaleFloat) {
width = NS_MAX(width, (uint32_t)(aDisplayWidth / scaleFloat));
height = NS_MAX(height, (uint32_t)(aDisplayHeight / scaleFloat));
width = std::max(width, (uint32_t)(aDisplayWidth / scaleFloat));
height = std::max(height, (uint32_t)(aDisplayHeight / scaleFloat));
} else if (mValidMaxScale) {
width = NS_MAX(width, (uint32_t)(aDisplayWidth / scaleMaxFloat));
height = NS_MAX(height, (uint32_t)(aDisplayHeight / scaleMaxFloat));
width = std::max(width, (uint32_t)(aDisplayWidth / scaleMaxFloat));
height = std::max(height, (uint32_t)(aDisplayHeight / scaleMaxFloat));
}

nsViewportInfo ret(scaleFloat, scaleMinFloat, scaleMaxFloat, width, height,
Expand Down Expand Up @@ -6759,7 +6760,7 @@ nsDocument::FlushPendingNotifications(mozFlushType aType)
if (mParentDocument && IsSafeToFlush()) {
mozFlushType parentType = aType;
if (aType >= Flush_Style)
parentType = NS_MAX(Flush_Layout, aType);
parentType = std::max(Flush_Layout, aType);
mParentDocument->FlushPendingNotifications(parentType);
}

Expand Down
3 changes: 2 additions & 1 deletion content/base/src/nsFrameMessageManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "xpcpublic.h"
#include "mozilla/Preferences.h"
#include "mozilla/dom/StructuredCloneUtils.h"
#include <algorithm>

#ifdef ANDROID
#include <android/log.h>
Expand Down Expand Up @@ -949,7 +950,7 @@ nsFrameScriptExecutor::TryCacheLoadAndCompileScript(const nsAString& aURL,
return;
}
nsCString buffer;
uint32_t avail = (uint32_t)NS_MIN(avail64, (uint64_t)UINT32_MAX);
uint32_t avail = (uint32_t)std::min(avail64, (uint64_t)UINT32_MAX);
if (NS_FAILED(NS_ReadInputStreamToString(input, buffer, avail))) {
return;
}
Expand Down
3 changes: 2 additions & 1 deletion content/base/src/nsINode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
#include "nsWrapperCacheInlines.h"
#include "WrapperFactory.h"
#include "DocumentType.h"
#include <algorithm>

using namespace mozilla;
using namespace mozilla::dom;
Expand Down Expand Up @@ -806,7 +807,7 @@ nsINode::CompareDocumentPosition(nsINode& aOtherNode) const
// Find where the parent chain differs and check indices in the parent.
const nsINode* parent = top1;
uint32_t len;
for (len = NS_MIN(pos1, pos2); len > 0; --len) {
for (len = std::min(pos1, pos2); len > 0; --len) {
const nsINode* child1 = parents1.ElementAt(--pos1);
const nsINode* child2 = parents2.ElementAt(--pos2);
if (child1 != child2) {
Expand Down
5 changes: 3 additions & 2 deletions content/base/src/nsSyncLoadService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "nsAutoPtr.h"
#include "nsStreamUtils.h"
#include "nsCrossSiteListenerProxy.h"
#include <algorithm>

/**
* This class manages loading a single XML document
Expand Down Expand Up @@ -342,7 +343,7 @@ nsSyncLoadService::PushSyncStreamToListener(nsIInputStream* aIn,
if (NS_FAILED(rv)) {
chunkSize = 4096;
}
chunkSize = NS_MIN(int64_t(UINT16_MAX), chunkSize);
chunkSize = std::min(int64_t(UINT16_MAX), chunkSize);

rv = NS_NewBufferedInputStream(getter_AddRefs(bufferedStream), aIn,
chunkSize);
Expand Down Expand Up @@ -370,7 +371,7 @@ nsSyncLoadService::PushSyncStreamToListener(nsIInputStream* aIn,
readCount = UINT32_MAX;

rv = aListener->OnDataAvailable(aChannel, nullptr, aIn,
(uint32_t)NS_MIN(sourceOffset, (uint64_t)UINT32_MAX),
(uint32_t)std::min(sourceOffset, (uint64_t)UINT32_MAX),
(uint32_t)readCount);
if (NS_FAILED(rv)) {
break;
Expand Down
3 changes: 2 additions & 1 deletion content/base/src/nsTextFragment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "nsUTF8Utils.h"
#include "mozilla/SSE.h"
#include "nsTextFragmentImpl.h"
#include <algorithm>

#define TEXTFRAG_WHITE_AFTER_NEWLINE 50
#define TEXTFRAG_MAX_NEWLINES 7
Expand Down Expand Up @@ -127,7 +128,7 @@ FirstNon8BitUnvectorized(const PRUnichar *str, const PRUnichar *end)

// Align ourselves to a word boundary.
int32_t alignLen =
NS_MIN(len, int32_t(((-NS_PTR_TO_INT32(str)) & alignMask) / sizeof(PRUnichar)));
std::min(len, int32_t(((-NS_PTR_TO_INT32(str)) & alignMask) / sizeof(PRUnichar)));
for (; i < alignLen; i++) {
if (str[i] > 255)
return i;
Expand Down
3 changes: 2 additions & 1 deletion content/base/src/nsTextFragmentSSE2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "nscore.h"
#include "nsAlgorithm.h"
#include "nsTextFragmentImpl.h"
#include <algorithm>

namespace mozilla {
namespace SSE2 {
Expand All @@ -33,7 +34,7 @@ FirstNon8Bit(const PRUnichar *str, const PRUnichar *end)
// Align ourselves to a 16-byte boundary, as required by _mm_load_si128
// (i.e. MOVDQA).
int32_t alignLen =
NS_MIN(len, int32_t(((-NS_PTR_TO_INT32(str)) & 0xf) / sizeof(PRUnichar)));
std::min(len, int32_t(((-NS_PTR_TO_INT32(str)) & 0xf) / sizeof(PRUnichar)));
for (; i < alignLen; i++) {
if (str[i] > 255)
return i;
Expand Down
Loading

0 comments on commit a4fba22

Please sign in to comment.