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) {
// Compute modified Julian day from year, month, date.
// The missing days in 1582 are ignored for JavaScript compatibility.
function ToJulianDay(year, month, date) {
var jy = (month > 1) ? year : year - 1;
var jm = (month > 1) ? month + 2 : month + 14;
......@@ -568,10 +567,12 @@ function DatePrintString(time) {
// -------------------------------------------------------------------
// Reused output buffer.
var parse_buffer = $Array(7);
// ECMA 262 - 15.9.4.2
function DateParse(string) {
var arr = %DateParseString(ToString(string));
var arr = %DateParseString(ToString(string), parse_buffer);
if (IS_NULL(arr)) return $NaN;
var day = MakeDay(arr[0], arr[1], arr[2]);
......
......@@ -29,7 +29,7 @@ namespace v8 { namespace internal {
template <typename Char>
bool DateParser::Parse(Vector<Char> str, FixedArray* out) {
ASSERT(out->length() == OUTPUT_SIZE);
ASSERT(out->length() >= OUTPUT_SIZE);
InputReader<Char> in(str);
TimeZoneComposer tz;
TimeComposer time;
......
......@@ -48,7 +48,9 @@ class DateParser : public AllStatic {
template <typename Char>
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:
// Range testing
......
......@@ -4480,27 +4480,30 @@ static Object* Runtime_DateCurrentTime(Arguments args) {
static Object* Runtime_DateParseString(Arguments args) {
HandleScope scope;
ASSERT(args.length() == 1);
CONVERT_CHECKED(String, string_object, args[0]);
ASSERT(args.length() == 2);
Handle<String> str(string_object);
CONVERT_ARG_CHECKED(String, str, 0);
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;
{
AssertNoAllocation no_allocation;
if (StringShape(*str).IsAsciiRepresentation()) {
result = DateParser::Parse(str->ToAsciiVector(), *output);
} else {
ASSERT(StringShape(*str).IsTwoByteRepresentation());
result = DateParser::Parse(str->ToUC16Vector(), *output);
}
if (StringShape(*str).IsAsciiRepresentation()) {
result = DateParser::Parse(str->ToAsciiVector(), output_array);
} else {
ASSERT(StringShape(*str).IsTwoByteRepresentation());
result = DateParser::Parse(str->ToUC16Vector(), output_array);
}
if (result) {
return *Factory::NewJSArrayWithElements(output);
return *output;
} else {
return *Factory::null_value();
return Heap::null_value();
}
}
......
......@@ -185,7 +185,7 @@ namespace v8 { namespace internal {
\
/* Dates */ \
F(DateCurrentTime, 0) \
F(DateParseString, 1) \
F(DateParseString, 2) \
F(DateLocalTimezone, 1) \
F(DateLocalTimeOffset, 0) \
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