OLD | NEW |
---|---|
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 Loading... | |
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 Loading... | |
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(); |
OLD | NEW |