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

Side by Side Diff: src/date-delay.js

Issue 21507: Experimental: port bleeding_edge r1276 (a grab bag of optimizations)... (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/toiger/
Patch Set: Created 11 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 function TimeInYear(year) { 225 function TimeInYear(year) {
226 return DaysInYear(year) * msPerDay; 226 return DaysInYear(year) * msPerDay;
227 } 227 }
228 228
229 229
230 // Compute modified Julian day from year, month, date. 230 // Compute modified Julian day from year, month, date.
231 // The missing days in 1582 are ignored for JavaScript compatibility. 231 // The missing days in 1582 are ignored for JavaScript compatibility.
232 function ToJulianDay(year, month, date) { 232 function ToJulianDay(year, month, date) {
233 var jy = (month > 1) ? year : year - 1; 233 var jy = (month > 1) ? year : year - 1;
234 var jm = (month > 1) ? month + 2 : month + 14; 234 var jm = (month > 1) ? month + 2 : month + 14;
235 var ja = FLOOR(0.01*jy); 235 var ja = FLOOR(jy / 100);
236 return FLOOR(FLOOR(365.25*jy) + FLOOR(30.6001*jm) + date + 1720995) + 2 - ja + FLOOR(0.25*ja); 236 return FLOOR(FLOOR(365.25*jy) + FLOOR(30.6001*jm) + date + 1720995) + 2 - ja + FLOOR(0.25*ja);
237 } 237 }
238 238
239 var four_year_cycle_table = CalculateDateTable(); 239 var four_year_cycle_table = CalculateDateTable();
240 240
241 241
242 function CalculateDateTable() { 242 function CalculateDateTable() {
243 var month_lengths = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; 243 var month_lengths = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
244 var four_year_cycle_table = new $Array(1461); 244 var four_year_cycle_table = new $Array(1461);
245 245
246 var cumulative = 0; 246 var cumulative = 0;
247 var position = 0; 247 var position = 0;
248 var leap_position = 0; 248 var leap_position = 0;
249 for (var month = 0; month < 12; month++) { 249 for (var month = 0; month < 12; month++) {
250 var month_bits = month << kMonthShift;
250 var length = month_lengths[month]; 251 var length = month_lengths[month];
251 for (var day = 1; day <= length; day++) { 252 for (var day = 1; day <= length; day++) {
252 four_year_cycle_table[leap_position] = 253 four_year_cycle_table[leap_position] =
253 (month << kMonthShift) + day; 254 month_bits + day;
254 four_year_cycle_table[366 + position] = 255 four_year_cycle_table[366 + position] =
255 (1 << kYearShift) + (month << kMonthShift) + day; 256 (1 << kYearShift) + month_bits + day;
256 four_year_cycle_table[731 + position] = 257 four_year_cycle_table[731 + position] =
257 (2 << kYearShift) + (month << kMonthShift) + day; 258 (2 << kYearShift) + month_bits + day;
258 four_year_cycle_table[1096 + position] = 259 four_year_cycle_table[1096 + position] =
259 (3 << kYearShift) + (month << kMonthShift) + day; 260 (3 << kYearShift) + month_bits + day;
260 leap_position++; 261 leap_position++;
261 position++; 262 position++;
262 } 263 }
263 if (month == 1) { 264 if (month == 1) {
264 four_year_cycle_table[leap_position++] = 265 four_year_cycle_table[leap_position++] = month_bits + 29;
265 (month << kMonthShift) + 29;
266 } 266 }
267 } 267 }
268 return four_year_cycle_table; 268 return four_year_cycle_table;
269 } 269 }
270 270
271 271
272 // Constructor for creating objects holding year, month, and date. 272 // Constructor for creating objects holding year, month, and date.
273 // Introduced to ensure the two return points in FromJulianDay match same map. 273 // Introduced to ensure the two return points in FromJulianDay match same map.
274 function DayTriplet(year, month, date) { 274 function DayTriplet(year, month, date) {
275 this.year = year; 275 this.year = year;
276 this.month = month; 276 this.month = month;
277 this.date = date; 277 this.date = date;
278 } 278 }
279 279
280 var julian_day_cache_triplet;
281 var julian_day_cache_day = $NaN;
280 282
281 // Compute year, month, and day from modified Julian day. 283 // Compute year, month, and day from modified Julian day.
282 // The missing days in 1582 are ignored for JavaScript compatibility. 284 // The missing days in 1582 are ignored for JavaScript compatibility.
283 function FromJulianDay(julian) { 285 function FromJulianDay(julian) {
286 if (julian_day_cache_day == julian) {
287 return julian_day_cache_triplet;
288 }
289 var result;
284 // Avoid floating point and non-Smi maths in common case. This is also a peri od of 290 // Avoid floating point and non-Smi maths in common case. This is also a peri od of
285 // time where leap years are very regular. The range is not too large to avoi d overflow 291 // time where leap years are very regular. The range is not too large to avoi d overflow
286 // when doing the multiply-to-divide trick. 292 // when doing the multiply-to-divide trick.
287 if (julian > kDayZeroInJulianDay && 293 if (julian > kDayZeroInJulianDay &&
288 (julian - kDayZeroInJulianDay) < 40177) { // 1970 - 2080 294 (julian - kDayZeroInJulianDay) < 40177) { // 1970 - 2080
289 var jsimple = (julian - kDayZeroInJulianDay) + 731; // Day 0 is 1st January 1968 295 var jsimple = (julian - kDayZeroInJulianDay) + 731; // Day 0 is 1st January 1968
290 var y = 1968; 296 var y = 1968;
291 // Divide by 1461 by multiplying with 22967 and shifting down by 25! 297 // Divide by 1461 by multiplying with 22967 and shifting down by 25!
292 var after_1968 = (jsimple * 22967) >> 25; 298 var after_1968 = (jsimple * 22967) >> 25;
293 y += after_1968 << 2; 299 y += after_1968 << 2;
294 jsimple -= 1461 * after_1968; 300 jsimple -= 1461 * after_1968;
295 var four_year_cycle = four_year_cycle_table[jsimple]; 301 var four_year_cycle = four_year_cycle_table[jsimple];
296 return new DayTriplet(y + (four_year_cycle >> kYearShift), 302 result = new DayTriplet(y + (four_year_cycle >> kYearShift),
297 (four_year_cycle & kMonthMask) >> kMonthShift, 303 (four_year_cycle & kMonthMask) >> kMonthShift,
298 four_year_cycle & kDayMask); 304 four_year_cycle & kDayMask);
305 } else {
306 var jalpha = FLOOR((julian - 1867216.25) / 36524.25);
307 var jb = julian + 1 + jalpha - FLOOR(0.25 * jalpha) + 1524;
308 var jc = FLOOR(6680.0 + ((jb-2439870) - 122.1)/365.25);
309 var jd = FLOOR(365 * jc + (0.25 * jc));
310 var je = FLOOR((jb - jd)/30.6001);
311 var m = je - 1;
312 if (m > 12) m -= 13;
313 var y = jc - 4715;
314 if (m > 2) { --y; --m; }
315 var d = jb - jd - FLOOR(30.6001 * je);
316 result = new DayTriplet(y, m, d);
299 } 317 }
300 var jalpha = FLOOR((julian - 1867216.25) / 36524.25); 318 julian_day_cache_day = julian;
301 var jb = julian + 1 + jalpha - FLOOR(0.25 * jalpha) + 1524; 319 julian_day_cache_triplet = result;
302 var jc = FLOOR(6680.0 + ((jb-2439870) - 122.1)/365.25); 320 return result;
303 var jd = FLOOR(365 * jc + (0.25 * jc));
304 var je = FLOOR((jb - jd)/30.6001);
305 var m = je - 1;
306 if (m > 12) m -= 13;
307 var y = jc - 4715;
308 if (m > 2) { --y; --m; }
309 var d = jb - jd - FLOOR(30.6001 * je);
310 return new DayTriplet(y, m, d);
311 } 321 }
312 322
313 323
314 // Compute number of days given a year, month, date. 324 // Compute number of days given a year, month, date.
315 // Note that month and date can lie outside the normal range. 325 // Note that month and date can lie outside the normal range.
316 // For example: 326 // For example:
317 // MakeDay(2007, -4, 20) --> MakeDay(2006, 8, 20) 327 // MakeDay(2007, -4, 20) --> MakeDay(2006, 8, 20)
318 // MakeDay(2007, -33, 1) --> MakeDay(2004, 3, 1) 328 // MakeDay(2007, -33, 1) --> MakeDay(2004, 3, 1)
319 // MakeDay(2007, 14, -50) --> MakeDay(2007, 8, 11) 329 // MakeDay(2007, 14, -50) --> MakeDay(2007, 8, 11)
320 function MakeDay(year, month, date) { 330 function MakeDay(year, month, date) {
(...skipping 710 matching lines...) Expand 10 before | Expand all | Expand 10 after
1031 "setFullYear", DateSetFullYear, 1041 "setFullYear", DateSetFullYear,
1032 "setUTCFullYear", DateSetUTCFullYear, 1042 "setUTCFullYear", DateSetUTCFullYear,
1033 "toGMTString", DateToGMTString, 1043 "toGMTString", DateToGMTString,
1034 "toUTCString", DateToUTCString, 1044 "toUTCString", DateToUTCString,
1035 "getYear", DateGetYear, 1045 "getYear", DateGetYear,
1036 "setYear", DateSetYear 1046 "setYear", DateSetYear
1037 )); 1047 ));
1038 } 1048 }
1039 1049
1040 SetupDate(); 1050 SetupDate();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698