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

Unified Diff: src/heap.cc

Issue 1694004: Simplify double to number convertion. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 10 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/heap.h ('k') | src/runtime.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/heap.cc
===================================================================
--- src/heap.cc (revision 4544)
+++ src/heap.cc (working copy)
@@ -1761,41 +1761,6 @@
}
-Object* Heap::SmiOrNumberFromDouble(double value,
- bool new_object,
- PretenureFlag pretenure) {
- // We need to distinguish the minus zero value and this cannot be
- // done after conversion to int. Doing this by comparing bit
- // patterns is faster than using fpclassify() et al.
- static const DoubleRepresentation plus_zero(0.0);
- static const DoubleRepresentation minus_zero(-0.0);
- static const DoubleRepresentation nan(OS::nan_value());
- ASSERT(minus_zero_value() != NULL);
- ASSERT(sizeof(plus_zero.value) == sizeof(plus_zero.bits));
-
- DoubleRepresentation rep(value);
- if (rep.bits == plus_zero.bits) return Smi::FromInt(0); // not uncommon
- if (rep.bits == minus_zero.bits) {
- return new_object ? AllocateHeapNumber(-0.0, pretenure)
- : minus_zero_value();
- }
- if (rep.bits == nan.bits) {
- return new_object
- ? AllocateHeapNumber(OS::nan_value(), pretenure)
- : nan_value();
- }
-
- // Try to represent the value as a tagged small integer.
- int int_value = FastD2I(value);
- if (value == FastI2D(int_value) && Smi::IsValid(int_value)) {
- return Smi::FromInt(int_value);
- }
-
- // Materialize the value in the heap.
- return AllocateHeapNumber(value, pretenure);
-}
-
-
Object* Heap::NumberToString(Object* number, bool check_number_string_cache) {
Counters::number_to_string_runtime.Increment();
if (check_number_string_cache) {
@@ -1853,17 +1818,24 @@
}
-Object* Heap::NewNumberFromDouble(double value, PretenureFlag pretenure) {
- return SmiOrNumberFromDouble(value,
- true /* number object must be new */,
- pretenure);
-}
+Object* Heap::NumberFromDouble(double value, PretenureFlag pretenure) {
+ // We need to distinguish the minus zero value and this cannot be
+ // done after conversion to int. Doing this by comparing bit
+ // patterns is faster than using fpclassify() et al.
+ static const DoubleRepresentation minus_zero(-0.0);
+ DoubleRepresentation rep(value);
+ if (rep.bits == minus_zero.bits) {
+ return AllocateHeapNumber(-0.0, pretenure);
+ }
-Object* Heap::NumberFromDouble(double value, PretenureFlag pretenure) {
- return SmiOrNumberFromDouble(value,
- false /* use preallocated NaN, -0.0 */,
- pretenure);
+ int int_value = FastD2I(value);
+ if (value == int_value && Smi::IsValid(int_value)) {
+ return Smi::FromInt(int_value);
+ }
+
+ // Materialize the value in the heap.
+ return AllocateHeapNumber(value, pretenure);
}
« no previous file with comments | « src/heap.h ('k') | src/runtime.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698