Commit 9e612bc7 authored by benjamin@webkit.org's avatar benjamin@webkit.org

wtf/dtoa/* uses a confusing name to reference its buffers

https://bugs.webkit.org/show_bug.cgi?id=109709

Reviewed by Darin Adler.

The data structure Vector in wtf/dtoa has nothing to do with a traditional
vector, is it just a pointer and the length of the pointed buffer.

Rename it to BufferReference to avoid mistakes.

* wtf/dtoa/bignum-dtoa.cc:
* wtf/dtoa/bignum-dtoa.h:
* wtf/dtoa/bignum.cc:
* wtf/dtoa/bignum.h:
(Bignum):
* wtf/dtoa/double-conversion.cc:
* wtf/dtoa/fast-dtoa.cc:
* wtf/dtoa/fast-dtoa.h:
* wtf/dtoa/fixed-dtoa.cc:
* wtf/dtoa/fixed-dtoa.h:
(double_conversion):
* wtf/dtoa/strtod.cc:
* wtf/dtoa/strtod.h:
(double_conversion):
* wtf/dtoa/utils.h:
(double_conversion):
(WTF::double_conversion::BufferReference::BufferReference):
(WTF::double_conversion::BufferReference::SubBufferReference):
(StringBuilder):


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@147976 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 7afa0281
2013-04-08 Benjamin Poulain <benjamin@webkit.org>
wtf/dtoa/* uses a confusing name to reference its buffers
https://bugs.webkit.org/show_bug.cgi?id=109709
Reviewed by Darin Adler.
The data structure Vector in wtf/dtoa has nothing to do with a traditional
vector, is it just a pointer and the length of the pointed buffer.
Rename it to BufferReference to avoid mistakes.
* wtf/dtoa/bignum-dtoa.cc:
* wtf/dtoa/bignum-dtoa.h:
* wtf/dtoa/bignum.cc:
* wtf/dtoa/bignum.h:
(Bignum):
* wtf/dtoa/double-conversion.cc:
* wtf/dtoa/fast-dtoa.cc:
* wtf/dtoa/fast-dtoa.h:
* wtf/dtoa/fixed-dtoa.cc:
* wtf/dtoa/fixed-dtoa.h:
(double_conversion):
* wtf/dtoa/strtod.cc:
* wtf/dtoa/strtod.h:
(double_conversion):
* wtf/dtoa/utils.h:
(double_conversion):
(WTF::double_conversion::BufferReference::BufferReference):
(WTF::double_conversion::BufferReference::SubBufferReference):
(StringBuilder):
2013-04-08 Alberto Garcia <agarcia@igalia.com>
[BlackBerry] MathExtras: macros defined in math.h conflict with the real functions
......
......@@ -74,22 +74,22 @@ namespace double_conversion {
static void GenerateShortestDigits(Bignum* numerator, Bignum* denominator,
Bignum* delta_minus, Bignum* delta_plus,
bool is_even,
Vector<char> buffer, int* length);
BufferReference<char> buffer, int* length);
// Generates 'requested_digits' after the decimal point.
static void BignumToFixed(int requested_digits, int* decimal_point,
Bignum* numerator, Bignum* denominator,
Vector<char>(buffer), int* length);
BufferReference<char>(buffer), int* length);
// Generates 'count' digits of numerator/denominator.
// Once 'count' digits have been produced rounds the result depending on the
// remainder (remainders of exactly .5 round upwards). Might update the
// decimal_point when rounding up (for example for 0.9999).
static void GenerateCountedDigits(int count, int* decimal_point,
Bignum* numerator, Bignum* denominator,
Vector<char>(buffer), int* length);
BufferReference<char>(buffer), int* length);
void BignumDtoa(double v, BignumDtoaMode mode, int requested_digits,
Vector<char> buffer, int* length, int* decimal_point) {
BufferReference<char> buffer, int* length, int* decimal_point) {
ASSERT(v > 0);
ASSERT(!Double(v).IsSpecial());
uint64_t significand = Double(v).Significand();
......@@ -171,7 +171,7 @@ namespace double_conversion {
static void GenerateShortestDigits(Bignum* numerator, Bignum* denominator,
Bignum* delta_minus, Bignum* delta_plus,
bool is_even,
Vector<char> buffer, int* length) {
BufferReference<char> buffer, int* length) {
// Small optimization: if delta_minus and delta_plus are the same just reuse
// one of the two bignums.
if (Bignum::Equal(*delta_minus, *delta_plus)) {
......@@ -268,7 +268,7 @@ namespace double_conversion {
// exponent (decimal_point), when rounding upwards.
static void GenerateCountedDigits(int count, int* decimal_point,
Bignum* numerator, Bignum* denominator,
Vector<char>(buffer), int* length) {
BufferReference<char>(buffer), int* length) {
ASSERT(count >= 0);
for (int i = 0; i < count - 1; ++i) {
uint16_t digit;
......@@ -310,7 +310,7 @@ namespace double_conversion {
// Input verifies: 1 <= (numerator + delta) / denominator < 10.
static void BignumToFixed(int requested_digits, int* decimal_point,
Bignum* numerator, Bignum* denominator,
Vector<char>(buffer), int* length) {
BufferReference<char>(buffer), int* length) {
// Note that we have to look at more than just the requested_digits, since
// a number could be rounded up. Example: v=0.5 with requested_digits=0.
// Even though the power of v equals 0 we can't just stop here.
......
......@@ -77,7 +77,7 @@ namespace double_conversion {
// 'BignumDtoa' expects the given buffer to be big enough to hold all digits
// and a terminating null-character.
void BignumDtoa(double v, BignumDtoaMode mode, int requested_digits,
Vector<char> buffer, int* length, int* point);
BufferReference<char> buffer, int* length, int* point);
} // namespace double_conversion
......
......@@ -89,7 +89,7 @@ namespace double_conversion {
}
static uint64_t ReadUInt64(Vector<const char> buffer,
static uint64_t ReadUInt64(BufferReference<const char> buffer,
int from,
int digits_to_read) {
uint64_t result = 0;
......@@ -102,7 +102,7 @@ namespace double_conversion {
}
void Bignum::AssignDecimalString(Vector<const char> value) {
void Bignum::AssignDecimalString(BufferReference<const char> value) {
// 2^64 = 18446744073709551616 > 10^19
const int kMaxUint64DecimalDigits = 19;
Zero();
......@@ -132,7 +132,7 @@ namespace double_conversion {
}
void Bignum::AssignHexString(Vector<const char> value) {
void Bignum::AssignHexString(BufferReference<const char> value) {
Zero();
int length = value.length();
......
......@@ -46,8 +46,8 @@ namespace double_conversion {
void AssignUInt64(uint64_t value);
void AssignBignum(const Bignum& other);
void AssignDecimalString(Vector<const char> value);
void AssignHexString(Vector<const char> value);
void AssignDecimalString(BufferReference<const char> value);
void AssignHexString(BufferReference<const char> value);
void AssignPowerUInt16(uint16_t base, int exponent);
......@@ -130,7 +130,7 @@ namespace double_conversion {
Chunk bigits_buffer_[kBigitCapacity];
// A vector backed by bigits_buffer_. This way accesses to the array are
// checked for out-of-bounds errors.
Vector<Chunk> bigits_;
BufferReference<Chunk> bigits_;
int used_digits_;
// The Bignum's value equals value(bigits_) * 2^(exponent_ * kBigitSize).
int exponent_;
......
......@@ -360,7 +360,7 @@ namespace double_conversion {
bool* sign,
int* length,
int* point) {
Vector<char> vector(buffer, buffer_length);
BufferReference<char> vector(buffer, buffer_length);
ASSERT(!Double(v).IsSpecial());
ASSERT(mode == SHORTEST || requested_digits >= 0);
......@@ -596,7 +596,7 @@ namespace double_conversion {
ASSERT(buffer_pos < kBufferSize);
buffer[buffer_pos] = '\0';
double converted = Strtod(Vector<const char>(buffer, buffer_pos), exponent);
double converted = Strtod(BufferReference<const char>(buffer, buffer_pos), exponent);
*processed_characters_count = current - input;
return sign? -converted: converted;
}
......
......@@ -62,7 +62,7 @@ namespace double_conversion {
// Output: returns true if the buffer is guaranteed to contain the closest
// representable number to the input.
// Modifies the generated digits in the buffer to approach (round towards) w.
static bool RoundWeed(Vector<char> buffer,
static bool RoundWeed(BufferReference<char> buffer,
int length,
uint64_t distance_too_high_w,
uint64_t unsafe_interval,
......@@ -182,7 +182,7 @@ namespace double_conversion {
// unambiguously determined.
//
// Precondition: rest < ten_kappa.
static bool RoundWeedCounted(Vector<char> buffer,
static bool RoundWeedCounted(BufferReference<char> buffer,
int length,
uint64_t rest,
uint64_t ten_kappa,
......@@ -386,7 +386,7 @@ namespace double_conversion {
static bool DigitGen(DiyFp low,
DiyFp w,
DiyFp high,
Vector<char> buffer,
BufferReference<char> buffer,
int* length,
int* kappa) {
ASSERT(low.e() == w.e() && w.e() == high.e());
......@@ -511,7 +511,7 @@ namespace double_conversion {
// increases with higher requested_digits.
static bool DigitGenCounted(DiyFp w,
int requested_digits,
Vector<char> buffer,
BufferReference<char> buffer,
int* length,
int* kappa) {
ASSERT(kMinimalTargetExponent <= w.e() && w.e() <= kMaximalTargetExponent);
......@@ -599,7 +599,7 @@ namespace double_conversion {
// digits might correctly yield 'v' when read again, the closest will be
// computed.
static bool Grisu3(double v,
Vector<char> buffer,
BufferReference<char> buffer,
int* length,
int* decimal_exponent) {
DiyFp w = Double(v).AsNormalizedDiyFp();
......@@ -665,7 +665,7 @@ namespace double_conversion {
// therefore the rounding strategy for halfway cases is irrelevant.
static bool Grisu3Counted(double v,
int requested_digits,
Vector<char> buffer,
BufferReference<char> buffer,
int* length,
int* decimal_exponent) {
DiyFp w = Double(v).AsNormalizedDiyFp();
......@@ -710,7 +710,7 @@ namespace double_conversion {
bool FastDtoa(double v,
FastDtoaMode mode,
int requested_digits,
Vector<char> buffer,
BufferReference<char> buffer,
int* length,
int* decimal_point) {
ASSERT(v > 0);
......
......@@ -77,7 +77,7 @@ namespace double_conversion {
bool FastDtoa(double d,
FastDtoaMode mode,
int requested_digits,
Vector<char> buffer,
BufferReference<char> buffer,
int* length,
int* decimal_point);
......
......@@ -123,7 +123,7 @@ namespace double_conversion {
static void FillDigits32FixedLength(uint32_t number, int requested_length,
Vector<char> buffer, int* length) {
BufferReference<char> buffer, int* length) {
for (int i = requested_length - 1; i >= 0; --i) {
buffer[(*length) + i] = '0' + number % 10;
number /= 10;
......@@ -132,7 +132,7 @@ namespace double_conversion {
}
static void FillDigits32(uint32_t number, Vector<char> buffer, int* length) {
static void FillDigits32(uint32_t number, BufferReference<char> buffer, int* length) {
int number_length = 0;
// We fill the digits in reverse order and exchange them afterwards.
while (number != 0) {
......@@ -156,7 +156,7 @@ namespace double_conversion {
static void FillDigits64FixedLength(uint64_t number, int requested_length,
Vector<char> buffer, int* length) {
BufferReference<char> buffer, int* length) {
UNUSED_PARAM(requested_length);
const uint32_t kTen7 = 10000000;
// For efficiency cut the number into 3 uint32_t parts, and print those.
......@@ -171,7 +171,7 @@ namespace double_conversion {
}
static void FillDigits64(uint64_t number, Vector<char> buffer, int* length) {
static void FillDigits64(uint64_t number, BufferReference<char> buffer, int* length) {
const uint32_t kTen7 = 10000000;
// For efficiency cut the number into 3 uint32_t parts, and print those.
uint32_t part2 = static_cast<uint32_t>(number % kTen7);
......@@ -192,7 +192,7 @@ namespace double_conversion {
}
static void RoundUp(Vector<char> buffer, int* length, int* decimal_point) {
static void RoundUp(BufferReference<char> buffer, int* length, int* decimal_point) {
// An empty buffer represents 0.
if (*length == 0) {
buffer[0] = '1';
......@@ -234,7 +234,7 @@ namespace double_conversion {
// already contained "199" (thus yielding a buffer of "19999") then a
// rounding-up will change the contents of the buffer to "20000".
static void FillFractionals(uint64_t fractionals, int exponent,
int fractional_count, Vector<char> buffer,
int fractional_count, BufferReference<char> buffer,
int* length, int* decimal_point) {
ASSERT(-128 <= exponent && exponent <= 0);
// 'fractionals' is a fixed-point number, with binary point at bit
......@@ -292,7 +292,7 @@ namespace double_conversion {
// Removes leading and trailing zeros.
// If leading zeros are removed then the decimal point position is adjusted.
static void TrimZeros(Vector<char> buffer, int* length, int* decimal_point) {
static void TrimZeros(BufferReference<char> buffer, int* length, int* decimal_point) {
while (*length > 0 && buffer[(*length) - 1] == '0') {
(*length)--;
}
......@@ -312,7 +312,7 @@ namespace double_conversion {
bool FastFixedDtoa(double v,
int fractional_count,
Vector<char> buffer,
BufferReference<char> buffer,
int* length,
int* decimal_point) {
const uint32_t kMaxUInt32 = 0xFFFFFFFF;
......
......@@ -51,7 +51,7 @@ namespace double_conversion {
// This method only works for some parameters. If it can't handle the input it
// returns false. The output is null-terminated when the function succeeds.
bool FastFixedDtoa(double v, int fractional_count,
Vector<char> buffer, int* length, int* decimal_point);
BufferReference<char> buffer, int* length, int* decimal_point);
} // namespace double_conversion
......
......@@ -92,27 +92,27 @@ namespace double_conversion {
// we round up to 780.
static const int kMaxSignificantDecimalDigits = 780;
static Vector<const char> TrimLeadingZeros(Vector<const char> buffer) {
static BufferReference<const char> TrimLeadingZeros(BufferReference<const char> buffer) {
for (int i = 0; i < buffer.length(); i++) {
if (buffer[i] != '0') {
return buffer.SubVector(i, buffer.length());
return buffer.SubBufferReference(i, buffer.length());
}
}
return Vector<const char>(buffer.start(), 0);
return BufferReference<const char>(buffer.start(), 0);
}
static Vector<const char> TrimTrailingZeros(Vector<const char> buffer) {
static BufferReference<const char> TrimTrailingZeros(BufferReference<const char> buffer) {
for (int i = buffer.length() - 1; i >= 0; --i) {
if (buffer[i] != '0') {
return buffer.SubVector(0, i + 1);
return buffer.SubBufferReference(0, i + 1);
}
}
return Vector<const char>(buffer.start(), 0);
return BufferReference<const char>(buffer.start(), 0);
}
static void TrimToMaxSignificantDigits(Vector<const char> buffer,
static void TrimToMaxSignificantDigits(BufferReference<const char> buffer,
int exponent,
char* significant_buffer,
int* significant_exponent) {
......@@ -134,7 +134,7 @@ namespace double_conversion {
// When the string starts with "1844674407370955161" no further digit is read.
// Since 2^64 = 18446744073709551616 it would still be possible read another
// digit if it was less or equal than 6, but this would complicate the code.
static uint64_t ReadUint64(Vector<const char> buffer,
static uint64_t ReadUint64(BufferReference<const char> buffer,
int* number_of_read_digits) {
uint64_t result = 0;
int i = 0;
......@@ -152,7 +152,7 @@ namespace double_conversion {
// The returned DiyFp is not necessarily normalized.
// If remaining_decimals is zero then the returned DiyFp is accurate.
// Otherwise it has been rounded and has error of at most 1/2 ulp.
static void ReadDiyFp(Vector<const char> buffer,
static void ReadDiyFp(BufferReference<const char> buffer,
DiyFp* result,
int* remaining_decimals) {
int read_digits;
......@@ -173,7 +173,7 @@ namespace double_conversion {
}
static bool DoubleStrtod(Vector<const char> trimmed,
static bool DoubleStrtod(BufferReference<const char> trimmed,
int exponent,
double* result) {
#if !defined(DOUBLE_CONVERSION_CORRECT_DOUBLE_OPERATIONS)
......@@ -251,7 +251,7 @@ namespace double_conversion {
// If the function returns true then the result is the correct double.
// Otherwise it is either the correct double or the double that is just below
// the correct double.
static bool DiyFpStrtod(Vector<const char> buffer,
static bool DiyFpStrtod(BufferReference<const char> buffer,
int exponent,
double* result) {
DiyFp input;
......@@ -368,7 +368,7 @@ namespace double_conversion {
// buffer.length() + exponent <= kMaxDecimalPower + 1
// buffer.length() + exponent > kMinDecimalPower
// buffer.length() <= kMaxDecimalSignificantDigits
static double BignumStrtod(Vector<const char> buffer,
static double BignumStrtod(BufferReference<const char> buffer,
int exponent,
double guess) {
if (guess == Double::Infinity()) {
......@@ -413,9 +413,9 @@ namespace double_conversion {
}
double Strtod(Vector<const char> buffer, int exponent) {
Vector<const char> left_trimmed = TrimLeadingZeros(buffer);
Vector<const char> trimmed = TrimTrailingZeros(left_trimmed);
double Strtod(BufferReference<const char> buffer, int exponent) {
BufferReference<const char> left_trimmed = TrimLeadingZeros(buffer);
BufferReference<const char> trimmed = TrimTrailingZeros(left_trimmed);
exponent += left_trimmed.length() - trimmed.length();
if (trimmed.length() == 0) return 0.0;
if (trimmed.length() > kMaxSignificantDecimalDigits) {
......@@ -423,7 +423,7 @@ namespace double_conversion {
int significant_exponent;
TrimToMaxSignificantDigits(trimmed, exponent,
significant_buffer, &significant_exponent);
return Strtod(Vector<const char>(significant_buffer,
return Strtod(BufferReference<const char>(significant_buffer,
kMaxSignificantDecimalDigits),
significant_exponent);
}
......
......@@ -36,7 +36,7 @@ namespace double_conversion {
// The buffer must only contain digits in the range [0-9]. It must not
// contain a dot or a sign. It must not start with '0', and must not be empty.
double Strtod(Vector<const char> buffer, int exponent);
double Strtod(BufferReference<const char> buffer, int exponent);
} // namespace double_conversion
......
......@@ -136,23 +136,24 @@ namespace double_conversion {
ASSERT(length == static_cast<size_t>(static_cast<int>(length)));
return static_cast<int>(length);
}
// This is a simplified version of V8's Vector class.
// BufferReference abstract a memory buffer. It provides a pointer
// to the beginning of the buffer, and the available length.
template <typename T>
class Vector {
class BufferReference {
public:
Vector() : start_(NULL), length_(0) {}
Vector(T* data, int length) : start_(data), length_(length) {
BufferReference() : start_(NULL), length_(0) {}
BufferReference(T* data, int length) : start_(data), length_(length) {
ASSERT(length == 0 || (length > 0 && data != NULL));
}
// Returns a vector using the same backing storage as this one,
// spanning from and including 'from', to but not including 'to'.
Vector<T> SubVector(int from, int to) {
BufferReference<T> SubBufferReference(int from, int to) {
ASSERT(to <= length_);
ASSERT(from < to);
ASSERT(0 <= from);
return Vector<T>(start() + from, to - from);
return BufferReference<T>(start() + from, to - from);
}
// Returns the length of the vector.
......@@ -255,7 +256,7 @@ namespace double_conversion {
}
private:
Vector<char> buffer_;
BufferReference<char> buffer_;
int position_;
bool is_finalized() const { return position_ < 0; }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment