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

Side by Side Diff: src/v8natives.js

Issue 391014: Small optimizations to parseInt (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 11 years, 1 month 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/runtime.cc ('K') | « src/runtime.cc ('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-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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 // ECMA-262 - 15.1.2.2 88 // ECMA-262 - 15.1.2.2
89 function GlobalParseInt(string, radix) { 89 function GlobalParseInt(string, radix) {
90 if (radix === void 0) { 90 if (radix === void 0) {
91 // Some people use parseInt instead of Math.floor. This 91 // Some people use parseInt instead of Math.floor. This
92 // optimization makes parseInt on a Smi 12 times faster (60ns 92 // optimization makes parseInt on a Smi 12 times faster (60ns
93 // vs 800ns). The following optimization makes parseInt on a 93 // vs 800ns). The following optimization makes parseInt on a
94 // non-Smi number 9 times faster (230ns vs 2070ns). Together 94 // non-Smi number 9 times faster (230ns vs 2070ns). Together
95 // they make parseInt on a string 1.4% slower (274ns vs 270ns). 95 // they make parseInt on a string 1.4% slower (274ns vs 270ns).
96 if (%_IsSmi(string)) return string; 96 if (%_IsSmi(string)) return string;
97 if (IS_NUMBER(string) && 97 if (IS_NUMBER(string) &&
98 ((string < -0.01 && -1e9 < string) || 98 ((0.01 < string && string < 1e9) ||
99 (0.01 < string && string < 1e9))) { 99 (string < -0.01 && -1e9 < string))) {
Lasse Reichstein 2009/11/11 11:43:34 Just for readability, could you swap the terms of
100 // Truncate number. 100 // Truncate number.
101 return string | 0; 101 return string | 0;
102 } 102 }
103 radix = 0; 103 radix = 0;
104 } else { 104 } else {
105 radix = TO_INT32(radix); 105 radix = TO_INT32(radix);
106 if (!(radix == 0 || (2 <= radix && radix <= 36))) 106 if (!(radix == 0 || (2 <= radix && radix <= 36)))
107 return $NaN; 107 return $NaN;
108 } 108 }
109 return %StringParseInt(ToString(string), radix); 109 return %StringParseInt(ToString(string), radix);
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 573
574 // ---------------------------------------------------------------------------- 574 // ----------------------------------------------------------------------------
575 575
576 function SetupFunction() { 576 function SetupFunction() {
577 InstallFunctions($Function.prototype, DONT_ENUM, $Array( 577 InstallFunctions($Function.prototype, DONT_ENUM, $Array(
578 "toString", FunctionToString 578 "toString", FunctionToString
579 )); 579 ));
580 } 580 }
581 581
582 SetupFunction(); 582 SetupFunction();
OLDNEW
« src/runtime.cc ('K') | « src/runtime.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698