Commit c918bec9 authored by lrn@chromium.org's avatar lrn@chromium.org

Reuse output array instead of creating a new one for each call in Date.parse


git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@1544 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent b37b9af1
...@@ -228,7 +228,6 @@ function TimeInYear(year) { ...@@ -228,7 +228,6 @@ function TimeInYear(year) {
// Compute modified Julian day from year, month, date. // Compute modified Julian day from year, month, date.
// The missing days in 1582 are ignored for JavaScript compatibility.
function ToJulianDay(year, month, date) { function ToJulianDay(year, month, date) {
var jy = (month > 1) ? year : year - 1; var jy = (month > 1) ? year : year - 1;
var jm = (month > 1) ? month + 2 : month + 14; var jm = (month > 1) ? month + 2 : month + 14;
...@@ -568,10 +567,12 @@ function DatePrintString(time) { ...@@ -568,10 +567,12 @@ function DatePrintString(time) {
// ------------------------------------------------------------------- // -------------------------------------------------------------------
// Reused output buffer.
var parse_buffer = $Array(7);
// ECMA 262 - 15.9.4.2 // ECMA 262 - 15.9.4.2
function DateParse(string) { function DateParse(string) {
var arr = %DateParseString(ToString(string)); var arr = %DateParseString(ToString(string), parse_buffer);
if (IS_NULL(arr)) return $NaN; if (IS_NULL(arr)) return $NaN;
var day = MakeDay(arr[0], arr[1], arr[2]); var day = MakeDay(arr[0], arr[1], arr[2]);
......
...@@ -29,7 +29,7 @@ namespace v8 { namespace internal { ...@@ -29,7 +29,7 @@ namespace v8 { namespace internal {
template <typename Char> template <typename Char>
bool DateParser::Parse(Vector<Char> str, FixedArray* out) { bool DateParser::Parse(Vector<Char> str, FixedArray* out) {
ASSERT(out->length() == OUTPUT_SIZE); ASSERT(out->length() >= OUTPUT_SIZE);
InputReader<Char> in(str); InputReader<Char> in(str);
TimeZoneComposer tz; TimeZoneComposer tz;
TimeComposer time; TimeComposer time;
......
...@@ -48,7 +48,9 @@ class DateParser : public AllStatic { ...@@ -48,7 +48,9 @@ class DateParser : public AllStatic {
template <typename Char> template <typename Char>
static bool Parse(Vector<Char> str, FixedArray* output); static bool Parse(Vector<Char> str, FixedArray* output);
enum {YEAR, MONTH, DAY, HOUR, MINUTE, SECOND, UTC_OFFSET, OUTPUT_SIZE}; enum {
YEAR, MONTH, DAY, HOUR, MINUTE, SECOND, UTC_OFFSET, OUTPUT_SIZE
};
private: private:
// Range testing // Range testing
......
...@@ -4480,27 +4480,30 @@ static Object* Runtime_DateCurrentTime(Arguments args) { ...@@ -4480,27 +4480,30 @@ static Object* Runtime_DateCurrentTime(Arguments args) {
static Object* Runtime_DateParseString(Arguments args) { static Object* Runtime_DateParseString(Arguments args) {
HandleScope scope; HandleScope scope;
ASSERT(args.length() == 1); ASSERT(args.length() == 2);
CONVERT_CHECKED(String, string_object, args[0]);
Handle<String> str(string_object); CONVERT_ARG_CHECKED(String, str, 0);
FlattenString(str); FlattenString(str);
Handle<FixedArray> output = Factory::NewFixedArray(DateParser::OUTPUT_SIZE);
CONVERT_ARG_CHECKED(JSArray, output, 1);
RUNTIME_ASSERT(output->HasFastElements());
AssertNoAllocation no_allocation;
FixedArray* output_array = output->elements();
RUNTIME_ASSERT(output_array->length() >= DateParser::OUTPUT_SIZE);
bool result; bool result;
{ if (StringShape(*str).IsAsciiRepresentation()) {
AssertNoAllocation no_allocation; result = DateParser::Parse(str->ToAsciiVector(), output_array);
if (StringShape(*str).IsAsciiRepresentation()) { } else {
result = DateParser::Parse(str->ToAsciiVector(), *output); ASSERT(StringShape(*str).IsTwoByteRepresentation());
} else { result = DateParser::Parse(str->ToUC16Vector(), output_array);
ASSERT(StringShape(*str).IsTwoByteRepresentation());
result = DateParser::Parse(str->ToUC16Vector(), *output);
}
} }
if (result) { if (result) {
return *Factory::NewJSArrayWithElements(output); return *output;
} else { } else {
return *Factory::null_value(); return Heap::null_value();
} }
} }
......
...@@ -185,7 +185,7 @@ namespace v8 { namespace internal { ...@@ -185,7 +185,7 @@ namespace v8 { namespace internal {
\ \
/* Dates */ \ /* Dates */ \
F(DateCurrentTime, 0) \ F(DateCurrentTime, 0) \
F(DateParseString, 1) \ F(DateParseString, 2) \
F(DateLocalTimezone, 1) \ F(DateLocalTimezone, 1) \
F(DateLocalTimeOffset, 0) \ F(DateLocalTimeOffset, 0) \
F(DateDaylightSavingsOffset, 1) \ F(DateDaylightSavingsOffset, 1) \
......
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