Skip to content

Commit

Permalink
Bug 835542 - Implement mozilla::Abs. r=Ms2ger
Browse files Browse the repository at this point in the history
--HG--
extra : rebase_source : a3e62ff76365d27cc4cb10e4fee942ddb8b10b79
  • Loading branch information
jswalden committed Feb 16, 2013
1 parent 793d063 commit 1871e9f
Showing 32 changed files with 215 additions and 142 deletions.
7 changes: 3 additions & 4 deletions content/canvas/src/CanvasRenderingContext2D.cpp
Original file line number Diff line number Diff line change
@@ -83,6 +83,7 @@
#include "mozilla/gfx/PathHelpers.h"
#include "mozilla/ipc/DocumentRendererParent.h"
#include "mozilla/ipc/PDocumentRendererParent.h"
#include "mozilla/MathAlgorithms.h"
#include "mozilla/Preferences.h"
#include "mozilla/Telemetry.h"
#include "mozilla/unused.h"
@@ -94,8 +95,6 @@
#include "mozilla/dom/HTMLImageElement.h"
#include "nsHTMLVideoElement.h"
#include "mozilla/dom/CanvasRenderingContext2DBinding.h"
#include <cstdlib> // for std::abs(int/long)
#include <cmath> // for std::abs(float/double)

#ifdef XP_WIN
#include "gfxWindowsPlatform.h"
@@ -3689,8 +3688,8 @@ CanvasRenderingContext2D::CreateImageData(JSContext* cx, double sw,
int32_t wi = JS_DoubleToInt32(sw);
int32_t hi = JS_DoubleToInt32(sh);

uint32_t w = std::abs(wi);
uint32_t h = std::abs(hi);
uint32_t w = Abs(wi);
uint32_t h = Abs(hi);
return mozilla::dom::CreateImageData(cx, this, w, h, error);
}

21 changes: 10 additions & 11 deletions content/events/src/nsEventStateManager.cpp
Original file line number Diff line number Diff line change
@@ -4,6 +4,8 @@
* 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/Attributes.h"
#include "mozilla/MathAlgorithms.h"
#include "mozilla/dom/TabParent.h"

#include "nsCOMPtr.h"
@@ -93,12 +95,9 @@

#include "mozilla/Preferences.h"
#include "mozilla/LookAndFeel.h"
#include "mozilla/Attributes.h"
#include "sampler.h"

#include "nsIDOMClientRect.h"
#include <cstdlib> // for std::abs(int/long)
#include <cmath> // for std::abs(float/double)

#ifdef XP_MACOSX
#import <ApplicationServices/ApplicationServices.h>
@@ -2053,8 +2052,8 @@ nsEventStateManager::GenerateDragGesture(nsPresContext* aPresContext,

// fire drag gesture if mouse has moved enough
nsIntPoint pt = aEvent->refPoint + aEvent->widget->WidgetToScreenOffset();
if (std::abs(pt.x - mGestureDownPoint.x) > pixelThresholdX ||
std::abs(pt.y - mGestureDownPoint.y) > pixelThresholdY) {
if (Abs(pt.x - mGestureDownPoint.x) > pixelThresholdX ||
Abs(pt.y - mGestureDownPoint.y) > pixelThresholdY) {
if (mClickHoldContextMenu) {
// stop the click-hold before we fire off the drag gesture, in case
// it takes a long time
@@ -2880,14 +2879,14 @@ nsEventStateManager::DoScrollText(nsIScrollableFrame* aScrollableFrame,
nsIntSize devPixelPageSize(pc->AppUnitsToDevPixels(pageSize.width),
pc->AppUnitsToDevPixels(pageSize.height));
if (!WheelPrefs::GetInstance()->IsOverOnePageScrollAllowedX(aEvent) &&
std::abs(actualDevPixelScrollAmount.x) > devPixelPageSize.width) {
Abs(actualDevPixelScrollAmount.x) > devPixelPageSize.width) {
actualDevPixelScrollAmount.x =
(actualDevPixelScrollAmount.x >= 0) ? devPixelPageSize.width :
-devPixelPageSize.width;
}

if (!WheelPrefs::GetInstance()->IsOverOnePageScrollAllowedY(aEvent) &&
std::abs(actualDevPixelScrollAmount.y) > devPixelPageSize.height) {
Abs(actualDevPixelScrollAmount.y) > devPixelPageSize.height) {
actualDevPixelScrollAmount.y =
(actualDevPixelScrollAmount.y >= 0) ? devPixelPageSize.height :
-devPixelPageSize.height;
@@ -5579,8 +5578,8 @@ nsEventStateManager::WheelPrefs::ComputeActionFor(widget::WheelEvent* aEvent)
Init(index);

bool deltaXPreferred =
(std::abs(aEvent->deltaX) > std::abs(aEvent->deltaY) &&
std::abs(aEvent->deltaX) > std::abs(aEvent->deltaZ));
(Abs(aEvent->deltaX) > Abs(aEvent->deltaY) &&
Abs(aEvent->deltaX) > Abs(aEvent->deltaZ));
Action* actions = deltaXPreferred ? mOverriddenActionsX : mActions;
if (actions[index] == ACTION_NONE || actions[index] == ACTION_SCROLL) {
return actions[index];
@@ -5614,7 +5613,7 @@ nsEventStateManager::WheelPrefs::IsOverOnePageScrollAllowedX(
{
Index index = GetIndexFor(aEvent);
Init(index);
return std::abs(mMultiplierX[index]) >=
return Abs(mMultiplierX[index]) >=
MIN_MULTIPLIER_VALUE_ALLOWING_OVER_ONE_PAGE_SCROLL;
}

@@ -5624,6 +5623,6 @@ nsEventStateManager::WheelPrefs::IsOverOnePageScrollAllowedY(
{
Index index = GetIndexFor(aEvent);
Init(index);
return std::abs(mMultiplierY[index]) >=
return Abs(mMultiplierY[index]) >=
MIN_MULTIPLIER_VALUE_ALLOWING_OVER_ONE_PAGE_SCROLL;
}
7 changes: 3 additions & 4 deletions content/html/content/src/nsHTMLMediaElement.cpp
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "nsHTMLMediaElement.h"
#include "mozilla/MathAlgorithms.h"
#include "mozilla/Util.h"

#include "base/basictypes.h"
@@ -72,8 +73,6 @@

#include "ImageContainer.h"
#include "nsIPowerManagerService.h"
#include <cstdlib> // for std::abs(int/long)
#include <cmath> // for std::abs(float/double)
#include <algorithm>

#ifdef MOZ_OGG
@@ -3520,10 +3519,10 @@ static double ClampPlaybackRate(double aPlaybackRate)
if (aPlaybackRate == 0.0) {
return aPlaybackRate;
}
if (std::abs(aPlaybackRate) < MIN_PLAYBACKRATE) {
if (Abs(aPlaybackRate) < MIN_PLAYBACKRATE) {
return aPlaybackRate < 0 ? -MIN_PLAYBACKRATE : MIN_PLAYBACKRATE;
}
if (std::abs(aPlaybackRate) > MAX_PLAYBACKRATE) {
if (Abs(aPlaybackRate) > MAX_PLAYBACKRATE) {
return aPlaybackRate < 0 ? -MAX_PLAYBACKRATE : MAX_PLAYBACKRATE;
}
return aPlaybackRate;
13 changes: 6 additions & 7 deletions content/media/MediaDecoder.cpp
Original file line number Diff line number Diff line change
@@ -5,6 +5,8 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "MediaDecoder.h"
#include "mozilla/FloatingPoint.h"
#include "mozilla/MathAlgorithms.h"
#include <limits>
#include "nsNetUtil.h"
#include "AudioStream.h"
@@ -20,10 +22,7 @@
#include "MediaResource.h"
#include "nsError.h"
#include "mozilla/Preferences.h"
#include <cstdlib> // for std::abs(int/long)
#include <cmath> // for std::abs(float/double)
#include <algorithm>
#include <mozilla/FloatingPoint.h>

#ifdef MOZ_WMF
#include "WMFDecoder.h"
@@ -595,11 +594,11 @@ nsresult MediaDecoder::Seek(double aTime)
NS_ENSURE_SUCCESS(res, NS_OK);
res = seekable.Start(range + 1, &rightBound);
NS_ENSURE_SUCCESS(res, NS_OK);
double distanceLeft = std::abs(leftBound - aTime);
double distanceRight = std::abs(rightBound - aTime);
double distanceLeft = Abs(leftBound - aTime);
double distanceRight = Abs(rightBound - aTime);
if (distanceLeft == distanceRight) {
distanceLeft = std::abs(leftBound - mCurrentTime);
distanceRight = std::abs(rightBound - mCurrentTime);
distanceLeft = Abs(leftBound - mCurrentTime);
distanceRight = Abs(rightBound - mCurrentTime);
}
aTime = (distanceLeft < distanceRight) ? leftBound : rightBound;
} else {
8 changes: 3 additions & 5 deletions docshell/shistory/src/nsSHistory.cpp
Original file line number Diff line number Diff line change
@@ -35,8 +35,7 @@

// For calculating max history entries and max cachable contentviewers
#include "nspr.h"
#include <cstdlib> // for std::abs(int/long)
#include <cmath> // for std::abs(float/double), and std::log(double)
#include "mozilla/MathAlgorithms.h"

using namespace mozilla;

@@ -1102,8 +1101,7 @@ nsSHistory::GloballyEvictContentViewers()
for (uint32_t j = 0; j < shTransactions.Length(); j++) {
TransactionAndDistance &container = shTransactions[j];
if (container.mViewer == contentViewer) {
container.mDistance = std::min(container.mDistance,
std::abs(i - shist->mIndex));
container.mDistance = std::min(container.mDistance, Abs(i - shist->mIndex));
found = true;
break;
}
@@ -1112,7 +1110,7 @@ nsSHistory::GloballyEvictContentViewers()
// If we didn't find a TransactionAndDistance for this content viewer, make a new
// one.
if (!found) {
TransactionAndDistance container(trans, std::abs(i - shist->mIndex));
TransactionAndDistance container(trans, Abs(i - shist->mIndex));
shTransactions.AppendElement(container);
}
}
7 changes: 3 additions & 4 deletions editor/libeditor/html/nsHTMLEditRules.cpp
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@
#include <stdlib.h>

#include "mozilla/Assertions.h"
#include "mozilla/MathAlgorithms.h"
#include "mozilla/Preferences.h"
#include "mozilla/Selection.h"
#include "mozilla/dom/Element.h"
@@ -54,8 +55,6 @@
#include "nsThreadUtils.h"
#include "nsUnicharUtils.h"
#include "nsWSRunObject.h"
#include <cstdlib> // for std::abs(int/long)
#include <cmath> // for std::abs(float/double)
#include <algorithm>

class nsISupports;
@@ -1929,7 +1928,7 @@ nsHTMLEditRules::WillDeleteSelection(Selection* aSelection,
res = nsWSRunObject::PrepareToDeleteRange(mHTMLEditor, address_of(visNode), &so, address_of(visNode), &eo);
NS_ENSURE_SUCCESS(res, res);
nsCOMPtr<nsIDOMCharacterData> nodeAsText(do_QueryInterface(visNode));
res = mHTMLEditor->DeleteText(nodeAsText, std::min(so, eo), std::abs(eo - so));
res = mHTMLEditor->DeleteText(nodeAsText, std::min(so, eo), Abs(eo - so));
*aHandled = true;
NS_ENSURE_SUCCESS(res, res);
res = InsertBRIfNeeded(aSelection);
@@ -4389,7 +4388,7 @@ nsHTMLEditRules::CreateStyleForInsertText(nsISelection *aSelection,
if (relFontSize) {
// dir indicated bigger versus smaller. 1 = bigger, -1 = smaller
int32_t dir = relFontSize > 0 ? 1 : -1;
for (int32_t j = 0; j < abs(relFontSize); j++) {
for (int32_t j = 0; j < Abs(relFontSize); j++) {
res = mHTMLEditor->RelativeFontChangeOnTextNode(dir, nodeAsText,
0, -1);
NS_ENSURE_SUCCESS(res, res);
7 changes: 3 additions & 4 deletions editor/libeditor/html/nsHTMLObjectResizer.cpp
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "mozilla/LookAndFeel.h"
#include "mozilla/MathAlgorithms.h"
#include "mozilla/Preferences.h"
#include "mozilla/mozalloc.h"
#include "nsAString.h"
@@ -42,8 +43,6 @@
#include "nsStringFwd.h"
#include "nsSubstringTuple.h"
#include "nscore.h"
#include <cstdlib> // for std::abs(int/long)
#include <cmath> // for std::abs(float/double)
#include <algorithm>

class nsISelection;
@@ -876,8 +875,8 @@ nsHTMLEditor::MouseMove(nsIDOMEvent* aMouseEvent)
int32_t yThreshold =
LookAndFeel::GetInt(LookAndFeel::eIntID_DragThresholdY, 1);

if (std::abs(clientX - mOriginalX ) * 2 >= xThreshold ||
std::abs(clientY - mOriginalY ) * 2 >= yThreshold) {
if (Abs(clientX - mOriginalX) * 2 >= xThreshold ||
Abs(clientY - mOriginalY) * 2 >= yThreshold) {
mGrabberClicked = false;
StartMoving(nullptr);
}
5 changes: 2 additions & 3 deletions gfx/layers/basic/BasicTiledThebesLayer.cpp
Original file line number Diff line number Diff line change
@@ -3,12 +3,11 @@
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "mozilla/layers/PLayersChild.h"
#include "mozilla/MathAlgorithms.h"
#include "BasicTiledThebesLayer.h"
#include "gfxImageSurface.h"
#include "sampler.h"
#include "gfxPlatform.h"
#include <cstdlib> // for std::abs(int/long)
#include <cmath> // for std::abs(float/double)

#ifdef GFX_TILEDLAYER_DEBUG_OVERLAY
#include "cairo.h"
@@ -377,7 +376,7 @@ BasicTiledThebesLayer::ComputeProgressiveUpdateRegion(BasicTiledLayerBuffer& aTi
if (!aRegionToPaint.IsEmpty()) {
break;
}
if (std::abs(scrollDiffY) >= std::abs(scrollDiffX)) {
if (Abs(scrollDiffY) >= Abs(scrollDiffX)) {
tileBounds.x += incX;
} else {
tileBounds.y += incY;
9 changes: 4 additions & 5 deletions gfx/thebes/gfxFont.cpp
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "mozilla/DebugOnly.h"
#include "mozilla/MathAlgorithms.h"

#ifdef MOZ_LOGGING
#define FORCE_PR_LOG /* Allow logging in the release build */
@@ -48,8 +49,6 @@
#include "sampler.h"

#include <algorithm>
#include <cstdlib> // for std::abs(int/long)
#include <cmath> // for std::abs(float/double)

using namespace mozilla;
using namespace mozilla::gfx;
@@ -788,7 +787,7 @@ CalcStyleMatch(gfxFontEntry *aFontEntry, const gfxFontStyle *aStyle)
}

// measure of closeness of weight to the desired value
rank += 9 - abs(aFontEntry->Weight() / 100 - aStyle->ComputeWeight());
rank += 9 - Abs(aFontEntry->Weight() / 100 - aStyle->ComputeWeight());
} else {
// if no font to match, prefer non-bold, non-italic fonts
if (!aFontEntry->IsItalic()) {
@@ -2964,8 +2963,8 @@ gfxFont::InitMetricsFromSfntTables(Metrics& aMetrics)
uint16_t(os2->version) >= 2) {
// version 2 and later includes the x-height field
SET_SIGNED(xHeight, os2->sxHeight);
// std::abs because of negative xHeight seen in Kokonor (Tibetan) font
aMetrics.xHeight = std::abs(aMetrics.xHeight);
// Abs because of negative xHeight seen in Kokonor (Tibetan) font
aMetrics.xHeight = Abs(aMetrics.xHeight);
}
// this should always be present
if (os2data.Length() >= offsetof(OS2Table, yStrikeoutPosition) +
11 changes: 7 additions & 4 deletions js/src/ion/RangeAnalysis.cpp
Original file line number Diff line number Diff line change
@@ -5,6 +5,8 @@
* 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/MathAlgorithms.h"

#include <math.h>
#include <stdio.h>

@@ -20,6 +22,8 @@
using namespace js;
using namespace js::ion;

using mozilla::Abs;

// This algorithm is based on the paper "Eliminating Range Checks Using
// Static Single Assignment Form" by Gough and Klaren.
//
@@ -668,8 +672,7 @@ MAbs::computeRange()
Range other(getOperand(0));

Range *range = new Range(0,
Max(Range::abs64((int64_t) other.lower()),
Range::abs64((int64_t) other.upper())),
Max(Abs<int64_t>(other.lower()), Abs<int64_t>(other.upper())),
other.isDecimal(),
other.exponent());
setRange(range);
@@ -716,8 +719,8 @@ MMod::computeRange()
return;
Range lhs(getOperand(0));
Range rhs(getOperand(1));
int64_t a = Range::abs64((int64_t) rhs.lower());
int64_t b = Range::abs64((int64_t) rhs.upper());
int64_t a = Abs<int64_t>(rhs.lower());
int64_t b = Abs<int64_t>(rhs.upper());
if (a == 0 && b == 0)
return;
int64_t bound = Max(1-a, b-1);
12 changes: 3 additions & 9 deletions js/src/ion/RangeAnalysis.h
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@
#define jsion_range_analysis_h__

#include "mozilla/FloatingPoint.h"
#include "mozilla/MathAlgorithms.h"

#include "wtf/Platform.h"
#include "MIR.h"
@@ -199,14 +200,6 @@ class Range : public TempObject {

static Range *Truncate(int64_t l, int64_t h);

static int64_t abs64(int64_t x) {
#ifdef WTF_OS_WINDOWS
return _abs64(x);
#else
return llabs(x);
#endif
}

void print(Sprinter &sp) const;
bool update(const Range *other);
bool update(const Range &other) {
@@ -351,7 +344,8 @@ class Range : public TempObject {
return;
}

uint32_t max = Max(abs64((int64_t) lower()), abs64((int64_t) upper()));
uint32_t max = Max(mozilla::Abs<int64_t>(lower()),
mozilla::Abs<int64_t>(upper()));
JS_ASSERT_IF(lower() == JSVAL_INT_MIN, max == (uint32_t) JSVAL_INT_MIN);
JS_ASSERT(max <= (uint32_t) JSVAL_INT_MIN);
// The number of bits needed to encode |max| is the power of 2 plus one.
Loading
Oops, something went wrong.

0 comments on commit 1871e9f

Please sign in to comment.