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

Side by Side Diff: src/v8natives.js

Issue 384132: Small parseInt optimizations (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
« no previous file with comments | « src/runtime.cc ('k') | test/mjsunit/parse-int-float.js » ('j') | 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 (-1e9 < string && string < -0.01))) {
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 460 matching lines...) Expand 10 before | Expand all | Expand 10 after
570 570
571 // ---------------------------------------------------------------------------- 571 // ----------------------------------------------------------------------------
572 572
573 function SetupFunction() { 573 function SetupFunction() {
574 InstallFunctions($Function.prototype, DONT_ENUM, $Array( 574 InstallFunctions($Function.prototype, DONT_ENUM, $Array(
575 "toString", FunctionToString 575 "toString", FunctionToString
576 )); 576 ));
577 } 577 }
578 578
579 SetupFunction(); 579 SetupFunction();
OLDNEW
« no previous file with comments | « src/runtime.cc ('k') | test/mjsunit/parse-int-float.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698