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

Side by Side 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, 9 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
« src/date-delay.js ('K') | « src/runtime.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2006-2009 the V8 project authors. All rights reserved. 1 // Copyright 2006-2009 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 4912 matching lines...) Expand 10 before | Expand all | Expand 10 after
4923 static Object* Runtime_Math_tan(Arguments args) { 4923 static Object* Runtime_Math_tan(Arguments args) {
4924 NoHandleAllocation ha; 4924 NoHandleAllocation ha;
4925 ASSERT(args.length() == 1); 4925 ASSERT(args.length() == 1);
4926 Counters::math_tan.Increment(); 4926 Counters::math_tan.Increment();
4927 4927
4928 CONVERT_DOUBLE_CHECKED(x, args[0]); 4928 CONVERT_DOUBLE_CHECKED(x, args[0]);
4929 return TranscendentalCache::Get(TranscendentalCache::TAN, x); 4929 return TranscendentalCache::Get(TranscendentalCache::TAN, x);
4930 } 4930 }
4931 4931
4932 4932
4933 static Object* Runtime_DateMakeDay(Arguments args) {
4934 NoHandleAllocation ha;
4935 ASSERT(args.length() == 3);
4936
4937 CONVERT_SMI_CHECKED(year, args[0]);
4938 CONVERT_SMI_CHECKED(month, args[1]);
4939 CONVERT_SMI_CHECKED(date, args[2]);
4940
4941 static const int day_from_month[] = {0, 31, 59, 90, 120, 151,
4942 181, 212, 243, 273, 304, 334};
4943 static const int day_from_month_leap[] = {0, 31, 60, 91, 121, 152,
4944 182, 213, 244, 274, 305, 335};
4945
4946 year += month / 12;
4947 month %= 12;
4948 if (month < 0) {
4949 year--;
4950 month += 12;
4951 }
4952
4953 static const int base_day = 365*1970 + 1969/4 - 1969/100 + 1969/400;
4954
4955 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
4956
4957 if (year % 4 || (year % 100 == 0 && year % 400 != 0)) {
4958 return Smi::FromInt(day_from_year + day_from_month[month] + date - 1);
4959 } else {
4960 return Smi::FromInt(day_from_year + day_from_month_leap[month] + date - 1);
4961 }
4962 }
4963
4964
4933 static Object* Runtime_NewArgumentsFast(Arguments args) { 4965 static Object* Runtime_NewArgumentsFast(Arguments args) {
4934 NoHandleAllocation ha; 4966 NoHandleAllocation ha;
4935 ASSERT(args.length() == 3); 4967 ASSERT(args.length() == 3);
4936 4968
4937 JSFunction* callee = JSFunction::cast(args[0]); 4969 JSFunction* callee = JSFunction::cast(args[0]);
4938 Object** parameters = reinterpret_cast<Object**>(args[1]); 4970 Object** parameters = reinterpret_cast<Object**>(args[1]);
4939 const int length = Smi::cast(args[2])->value(); 4971 const int length = Smi::cast(args[2])->value();
4940 4972
4941 Object* result = Heap::AllocateArgumentsObject(callee, length); 4973 Object* result = Heap::AllocateArgumentsObject(callee, length);
4942 if (result->IsFailure()) return result; 4974 if (result->IsFailure()) return result;
(...skipping 3404 matching lines...) Expand 10 before | Expand all | Expand 10 after
8347 } else { 8379 } else {
8348 // Handle last resort GC and make sure to allow future allocations 8380 // Handle last resort GC and make sure to allow future allocations
8349 // to grow the heap without causing GCs (if possible). 8381 // to grow the heap without causing GCs (if possible).
8350 Counters::gc_last_resort_from_js.Increment(); 8382 Counters::gc_last_resort_from_js.Increment();
8351 Heap::CollectAllGarbage(false); 8383 Heap::CollectAllGarbage(false);
8352 } 8384 }
8353 } 8385 }
8354 8386
8355 8387
8356 } } // namespace v8::internal 8388 } } // namespace v8::internal
OLDNEW
« 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