Revision: 4546
Author: [email protected]
Date: Thu Apr 29 05:15:02 2010
Log: Switch to vectors instead of bare char* arrays.
Review URL: http://codereview.chromium.org/1732019
http://code.google.com/p/v8/source/detail?r=4546
Modified:
/branches/bleeding_edge/src/conversions.cc
/branches/bleeding_edge/src/fast-dtoa.cc
/branches/bleeding_edge/src/fast-dtoa.h
/branches/bleeding_edge/test/cctest/test-fast-dtoa.cc
=======================================
--- /branches/bleeding_edge/src/conversions.cc Mon Apr 5 01:03:45 2010
+++ /branches/bleeding_edge/src/conversions.cc Thu Apr 29 05:15:02 2010
@@ -769,9 +769,11 @@
char* decimal_rep;
bool used_gay_dtoa = false;
- char fast_dtoa_buffer[kFastDtoaMaximalLength + 1];
+ const int kFastDtoaBufferCapacity = kFastDtoaMaximalLength + 1;
+ char fast_dtoa_buffer[kFastDtoaBufferCapacity];
int length;
- if (FastDtoa(v, fast_dtoa_buffer, &sign, &length, &decimal_point)) {
+ if (FastDtoa(v, Vector<char>(fast_dtoa_buffer,
kFastDtoaBufferCapacity),
+ &sign, &length, &decimal_point)) {
decimal_rep = fast_dtoa_buffer;
} else {
decimal_rep = dtoa(v, 0, 0, &decimal_point, &sign, NULL);
=======================================
--- /branches/bleeding_edge/src/fast-dtoa.cc Fri Mar 19 05:15:24 2010
+++ /branches/bleeding_edge/src/fast-dtoa.cc Thu Apr 29 05:15:02 2010
@@ -61,7 +61,7 @@
// 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.
-bool RoundWeed(char* buffer,
+bool RoundWeed(Vector<char> buffer,
int length,
uint64_t distance_too_high_w,
uint64_t unsafe_interval,
@@ -324,7 +324,7 @@
bool DigitGen(DiyFp low,
DiyFp w,
DiyFp high,
- char* buffer,
+ Vector<char> buffer,
int* length,
int* kappa) {
ASSERT(low.e() == w.e() && w.e() == high.e());
@@ -437,7 +437,7 @@
// The last digit will be closest to the actual v. That is, even if several
// digits might correctly yield 'v' when read again, the closest will be
// computed.
-bool grisu3(double v, char* buffer, int* length, int* decimal_exponent) {
+bool grisu3(double v, Vector<char> buffer, int* length, int*
decimal_exponent) {
DiyFp w = Double(v).AsNormalizedDiyFp();
// boundary_minus and boundary_plus are the boundaries between v and its
// closest floating-point neighbors. Any number strictly between
@@ -488,7 +488,11 @@
}
-bool FastDtoa(double v, char* buffer, int* sign, int* length, int* point) {
+bool FastDtoa(double v,
+ Vector<char> buffer,
+ int* sign,
+ int* length,
+ int* point) {
ASSERT(v != 0);
ASSERT(!Double(v).IsSpecial());
=======================================
--- /branches/bleeding_edge/src/fast-dtoa.h Thu Mar 18 06:19:59 2010
+++ /branches/bleeding_edge/src/fast-dtoa.h Thu Apr 29 05:15:02 2010
@@ -48,7 +48,11 @@
// one closest to v.
// The variable 'sign' will be '0' if the given number is positive, and '1'
// otherwise.
-bool FastDtoa(double d, char* buffer, int* sign, int* length, int* point);
+bool FastDtoa(double d,
+ Vector<char> buffer,
+ int* sign,
+ int* length,
+ int* point);
} } // namespace v8::internal
=======================================
--- /branches/bleeding_edge/test/cctest/test-fast-dtoa.cc Fri Mar 19
05:15:24 2010
+++ /branches/bleeding_edge/test/cctest/test-fast-dtoa.cc Thu Apr 29
05:15:02 2010
@@ -16,7 +16,8 @@
static const int kBufferSize = 100;
TEST(FastDtoaVariousDoubles) {
- char buffer[kBufferSize];
+ char buffer_container[kBufferSize];
+ Vector<char> buffer(buffer_container, kBufferSize);
int sign;
int length;
int point;
@@ -26,43 +27,43 @@
status = FastDtoa(min_double, buffer, &sign, &length, &point);
CHECK(status);
CHECK_EQ(0, sign);
- CHECK_EQ("5", buffer);
+ CHECK_EQ("5", buffer.start());
CHECK_EQ(-323, point);
double max_double = 1.7976931348623157e308;
status = FastDtoa(max_double, buffer, &sign, &length, &point);
CHECK(status);
CHECK_EQ(0, sign);
- CHECK_EQ("17976931348623157", buffer);
+ CHECK_EQ("17976931348623157", buffer.start());
CHECK_EQ(309, point);
status = FastDtoa(4294967272.0, buffer, &sign, &length, &point);
CHECK(status);
CHECK_EQ(0, sign);
- CHECK_EQ("4294967272", buffer);
+ CHECK_EQ("4294967272", buffer.start());
CHECK_EQ(10, point);
status = FastDtoa(4.1855804968213567e298, buffer, &sign, &length,
&point);
CHECK(status);
CHECK_EQ(0, sign);
- CHECK_EQ("4185580496821357", buffer);
+ CHECK_EQ("4185580496821357", buffer.start());
CHECK_EQ(299, point);
status = FastDtoa(5.5626846462680035e-309, buffer, &sign, &length,
&point);
CHECK(status);
CHECK_EQ(0, sign);
- CHECK_EQ("5562684646268003", buffer);
+ CHECK_EQ("5562684646268003", buffer.start());
CHECK_EQ(-308, point);
status = FastDtoa(2147483648.0, buffer, &sign, &length, &point);
CHECK(status);
CHECK_EQ(0, sign);
- CHECK_EQ("2147483648", buffer);
+ CHECK_EQ("2147483648", buffer.start());
CHECK_EQ(10, point);
status = FastDtoa(3.5844466002796428e+298, buffer, &sign, &length,
&point);
if (status) { // Not all FastDtoa variants manage to compute this
number.
- CHECK_EQ("35844466002796428", buffer);
+ CHECK_EQ("35844466002796428", buffer.start());
CHECK_EQ(0, sign);
CHECK_EQ(299, point);
}
@@ -72,7 +73,7 @@
status = FastDtoa(v, buffer, &sign, &length, &point);
if (status) {
CHECK_EQ(0, sign);
- CHECK_EQ("22250738585072014", buffer);
+ CHECK_EQ("22250738585072014", buffer.start());
CHECK_EQ(-307, point);
}
@@ -81,14 +82,15 @@
status = FastDtoa(v, buffer, &sign, &length, &point);
if (status) {
CHECK_EQ(0, sign);
- CHECK_EQ("2225073858507201", buffer);
+ CHECK_EQ("2225073858507201", buffer.start());
CHECK_EQ(-307, point);
}
}
TEST(FastDtoaGayShortest) {
- char buffer[kBufferSize];
+ char buffer_container[kBufferSize];
+ Vector<char> buffer(buffer_container, kBufferSize);
bool status;
int sign;
int length;
@@ -109,7 +111,7 @@
succeeded++;
CHECK_EQ(0, sign); // All precomputed numbers are positive.
CHECK_EQ(current_test.decimal_point, point);
- CHECK_EQ(current_test.representation, buffer);
+ CHECK_EQ(current_test.representation, buffer.start());
}
CHECK_GT(succeeded*1.0/total, 0.99);
CHECK(needed_max_length);
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev