Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(939)

Unified Diff: src/runtime.cc

Issue 661366: Rewrite MakeDay function from JS to C++. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 10 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« src/date-delay.js ('K') | « src/runtime.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/runtime.cc
===================================================================
--- src/runtime.cc (revision 3986)
+++ src/runtime.cc (working copy)
@@ -4930,6 +4930,38 @@
}
+static Object* Runtime_DateMakeDay(Arguments args) {
+ NoHandleAllocation ha;
+ ASSERT(args.length() == 3);
+
+ CONVERT_SMI_CHECKED(year, args[0]);
+ CONVERT_SMI_CHECKED(month, args[1]);
+ CONVERT_SMI_CHECKED(date, args[2]);
+
+ static const int day_from_month[] = {0, 31, 59, 90, 120, 151,
+ 181, 212, 243, 273, 304, 334};
+ static const int day_from_month_leap[] = {0, 31, 60, 91, 121, 152,
+ 182, 213, 244, 274, 305, 335};
+
+ year += month / 12;
+ month %= 12;
+ if (month < 0) {
+ year--;
+ month += 12;
+ }
+
+ static const int base_day = 365*1970 + 1969/4 - 1969/100 + 1969/400;
+
+ int day_from_year = 365*year + (year - 1)/4 - (year - 1)/100 + (year - 1)/400 - base_day;
Mads Ager (chromium) 2010/03/02 13:04:08 Line too long, please reformat. Also, please have
Oleg Eterevsky 2010/03/02 13:28:23 I tried to reformat it to make it more readable, a
+
+ if (year % 4 || (year % 100 == 0 && year % 400 != 0)) {
+ return Smi::FromInt(day_from_year + day_from_month[month] + date - 1);
+ } else {
+ return Smi::FromInt(day_from_year + day_from_month_leap[month] + date - 1);
+ }
+}
+
+
static Object* Runtime_NewArgumentsFast(Arguments args) {
NoHandleAllocation ha;
ASSERT(args.length() == 3);
« src/date-delay.js ('K') | « src/runtime.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698