Skip to content

Commit 0b9fa22

Browse files
committedApr 2, 2021
Bug 1701942 - Use bitwise equality for font variation value comparisons. r=jfkthame
Just like we do for font sizes / size-adjust in gfxFontStyle. Differential Revision: https://phabricator.services.mozilla.com/D110519
1 parent f3949f0 commit 0b9fa22

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed
 

‎gfx/2d/FontVariation.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,21 @@
88
#define MOZILLA_GFX_FONTVARIATION_H_
99

1010
#include <stdint.h>
11+
#include "mozilla/FloatingPoint.h"
1112

12-
namespace mozilla {
13-
namespace gfx {
13+
namespace mozilla::gfx {
1414

1515
// An OpenType variation tag and value pair
1616
struct FontVariation {
1717
uint32_t mTag;
1818
float mValue;
1919

2020
bool operator==(const FontVariation& aOther) const {
21-
return mTag == aOther.mTag && mValue == aOther.mValue;
21+
return mTag == aOther.mTag &&
22+
NumbersAreBitwiseIdentical(mValue, aOther.mValue);
2223
}
2324
};
2425

25-
} // namespace gfx
26-
} // namespace mozilla
26+
} // namespace mozilla::gfx
2727

2828
#endif /* MOZILLA_GFX_FONTVARIATION_H_ */

‎gfx/thebes/gfxFont.h

+2-4
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,7 @@ struct gfxFontStyle {
219219
}
220220

221221
bool Equals(const gfxFontStyle& other) const {
222-
return (*reinterpret_cast<const uint64_t*>(&size) ==
223-
*reinterpret_cast<const uint64_t*>(&other.size)) &&
222+
return mozilla::NumbersAreBitwiseIdentical(size, other.size) &&
224223
(style == other.style) && (weight == other.weight) &&
225224
(stretch == other.stretch) && (variantCaps == other.variantCaps) &&
226225
(variantSubSuper == other.variantSubSuper) &&
@@ -230,8 +229,7 @@ struct gfxFontStyle {
230229
(printerFont == other.printerFont) &&
231230
(useGrayscaleAntialiasing == other.useGrayscaleAntialiasing) &&
232231
(baselineOffset == other.baselineOffset) &&
233-
(*reinterpret_cast<const uint32_t*>(&sizeAdjust) ==
234-
*reinterpret_cast<const uint32_t*>(&other.sizeAdjust)) &&
232+
mozilla::NumbersAreBitwiseIdentical(sizeAdjust, other.sizeAdjust) &&
235233
(featureSettings == other.featureSettings) &&
236234
(variantAlternates == other.variantAlternates) &&
237235
(featureValueLookup == other.featureValueLookup) &&

‎mfbt/FloatingPoint.h

+10-2
Original file line numberDiff line numberDiff line change
@@ -524,14 +524,22 @@ static MOZ_ALWAYS_INLINE T UnspecifiedNaN() {
524524
*/
525525
template <typename T>
526526
static inline bool NumbersAreIdentical(T aValue1, T aValue2) {
527-
typedef FloatingPoint<T> Traits;
528-
typedef typename Traits::Bits Bits;
527+
using Bits = typename FloatingPoint<T>::Bits;
529528
if (IsNaN(aValue1)) {
530529
return IsNaN(aValue2);
531530
}
532531
return BitwiseCast<Bits>(aValue1) == BitwiseCast<Bits>(aValue2);
533532
}
534533

534+
/**
535+
* Compare two floating point values for bit-wise equality.
536+
*/
537+
template <typename T>
538+
static inline bool NumbersAreBitwiseIdentical(T aValue1, T aValue2) {
539+
using Bits = typename FloatingPoint<T>::Bits;
540+
return BitwiseCast<Bits>(aValue1) == BitwiseCast<Bits>(aValue2);
541+
}
542+
535543
/**
536544
* Return true iff |aValue| and |aValue2| are equal (ignoring sign if both are
537545
* zero) or both NaN.

0 commit comments

Comments
 (0)
Please sign in to comment.