Bug 1931425 - Limit how often moz-label's #setStyles runs r=reusable-components-revie...
[gecko.git] / mozglue / misc / decimal / to-moz-dependencies.patch
blobbf19a6da96cb3572bd6773cfb5ede5b057106f96
1 diff --git a/mozglue/misc/decimal/Decimal.cpp b/mozglue/misc/decimal/Decimal.cpp
2 --- a/mozglue/misc/decimal/Decimal.cpp
3 +++ b/mozglue/misc/decimal/Decimal.cpp
4 @@ -23,22 +23,20 @@
5 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
6 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
7 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
8 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
9 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
10 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
13 -#include "platform/Decimal.h"
14 +#include "Decimal.h"
15 +#include "moz-decimal-utils.h"
17 -#include "wtf/Allocator.h"
18 -#include "wtf/MathExtras.h"
19 -#include "wtf/Noncopyable.h"
20 -#include "wtf/text/StringBuilder.h"
21 +using namespace moz_decimal_utils;
23 #include <algorithm>
24 #include <float.h>
26 namespace blink {
28 namespace DecimalPrivate {
30 @@ -690,17 +688,17 @@ Decimal Decimal::floor() const
31 if (isNegative() && !isMultiplePowersOfTen(m_data.coefficient(), numberOfDropDigits))
32 ++result;
33 return Decimal(sign(), 0, result);
36 Decimal Decimal::fromDouble(double doubleValue)
38 if (std::isfinite(doubleValue))
39 - return fromString(String::numberToStringECMAScript(doubleValue));
40 + return fromString(mozToString(doubleValue));
42 if (std::isinf(doubleValue))
43 return infinity(doubleValue < 0 ? Negative : Positive);
45 return nan();
48 Decimal Decimal::fromString(const String& str)
49 @@ -931,17 +929,17 @@ Decimal Decimal::round() const
50 result /= 10;
51 return Decimal(sign(), 0, result);
54 double Decimal::toDouble() const
56 if (isFinite()) {
57 bool valid;
58 - const double doubleValue = toString().toDouble(&valid);
59 + const double doubleValue = mozToDouble(toString(), &valid);
60 return valid ? doubleValue : std::numeric_limits<double>::quiet_NaN();
63 if (isInfinity())
64 return isNegative() ? -std::numeric_limits<double>::infinity() : std::numeric_limits<double>::infinity();
66 return std::numeric_limits<double>::quiet_NaN();
68 @@ -984,17 +982,17 @@ String Decimal::toString() const
69 ++coefficient;
71 while (originalExponent < 0 && coefficient && !(coefficient % 10)) {
72 coefficient /= 10;
73 ++originalExponent;
77 - const String digits = String::number(coefficient);
78 + const String digits = mozToString(coefficient);
79 int coefficientLength = static_cast<int>(digits.length());
80 const int adjustedExponent = originalExponent + coefficientLength - 1;
81 if (originalExponent <= 0 && adjustedExponent >= -6) {
82 if (!originalExponent) {
83 builder.append(digits);
84 return builder.toString();
87 @@ -1026,14 +1024,27 @@ String Decimal::toString() const
88 if (adjustedExponent) {
89 builder.append(adjustedExponent < 0 ? "e" : "e+");
90 builder.appendNumber(adjustedExponent);
93 return builder.toString();
96 +bool Decimal::toString(char* strBuf, size_t bufLength) const
98 + ASSERT(bufLength > 0);
99 + String str = toString();
100 + size_t length = str.copy(strBuf, bufLength);
101 + if (length < bufLength) {
102 + strBuf[length] = '\0';
103 + return true;
105 + strBuf[bufLength - 1] = '\0';
106 + return false;
109 Decimal Decimal::zero(Sign sign)
111 return Decimal(EncodedData(sign, EncodedData::ClassZero));
114 } // namespace blink
115 diff --git a/mozglue/misc/decimal/Decimal.h b/mozglue/misc/decimal/Decimal.h
116 --- a/mozglue/misc/decimal/Decimal.h
117 +++ b/mozglue/misc/decimal/Decimal.h
118 @@ -23,26 +23,49 @@
119 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
120 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
121 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
122 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
123 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
124 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
127 +/**
128 + * Imported from:
129 + * https://chromium.googlesource.com/chromium/src.git/+/master/third_party/WebKit/Source/platform/Decimal.h
130 + * Check UPSTREAM-GIT-SHA for the commit ID of the last update from Blink core.
131 + */
133 #ifndef Decimal_h
134 #define Decimal_h
136 +#include "mozilla/Assertions.h"
137 +#include <stdint.h>
138 #include "mozilla/Types.h"
140 -#include "platform/PlatformExport.h"
141 -#include "wtf/Allocator.h"
142 -#include "wtf/Assertions.h"
143 -#include "wtf/text/WTFString.h"
144 -#include <stdint.h>
145 +#include <string>
147 +#ifndef ASSERT
148 +#define DEFINED_ASSERT_FOR_DECIMAL_H 1
149 +#define ASSERT MOZ_ASSERT
150 +#endif
152 +#define PLATFORM_EXPORT
154 +// To use USING_FAST_MALLOC we'd need:
155 +// https://chromium.googlesource.com/chromium/src.git/+/master/third_party/WebKit/Source/wtf/Allocator.h
156 +// Since we don't allocate Decimal objects, no need.
157 +#define USING_FAST_MALLOC(type) \
158 + void ignore_this_dummy_method() = delete
160 +#define DISALLOW_NEW() \
161 + private: \
162 + void* operator new(size_t) = delete; \
163 + void* operator new(size_t, void*) = delete; \
164 + public:
166 namespace blink {
168 namespace DecimalPrivate {
169 class SpecialValueHandler;
172 // This class represents decimal base floating point number.
173 @@ -139,27 +162,28 @@ public:
174 MFBT_API Decimal abs() const;
175 MFBT_API Decimal ceil() const;
176 MFBT_API Decimal floor() const;
177 MFBT_API Decimal remainder(const Decimal&) const;
178 MFBT_API Decimal round() const;
180 MFBT_API double toDouble() const;
181 // Note: toString method supports infinity and nan but fromString not.
182 - MFBT_API String toString() const;
183 + MFBT_API std::string toString() const;
184 + MFBT_API bool toString(char* strBuf, size_t bufLength) const;
186 static MFBT_API Decimal fromDouble(double);
187 // fromString supports following syntax EBNF:
188 // number ::= sign? digit+ ('.' digit*) (exponent-marker sign? digit+)?
189 // | sign? '.' digit+ (exponent-marker sign? digit+)?
190 // sign ::= '+' | '-'
191 // exponent-marker ::= 'e' | 'E'
192 // digit ::= '0' | '1' | ... | '9'
193 // Note: fromString doesn't support "infinity" and "nan".
194 - static MFBT_API Decimal fromString(const String&);
195 + static MFBT_API Decimal fromString(const std::string& aValue);
196 static MFBT_API Decimal infinity(Sign);
197 static MFBT_API Decimal nan();
198 static MFBT_API Decimal zero(Sign);
200 // You should not use below methods. We expose them for unit testing.
201 MFBT_API explicit Decimal(const EncodedData&);
202 const EncodedData& value() const { return m_data; }
204 @@ -178,9 +202,20 @@ private:
206 Sign sign() const { return m_data.sign(); }
208 EncodedData m_data;
211 } // namespace blink
213 +namespace mozilla {
214 +typedef blink::Decimal Decimal;
215 +} // namespace mozilla
217 +#undef USING_FAST_MALLOC
219 +#ifdef DEFINED_ASSERT_FOR_DECIMAL_H
220 +#undef DEFINED_ASSERT_FOR_DECIMAL_H
221 +#undef ASSERT
222 +#endif
224 #endif // Decimal_h