Commit 5889699e authored by dslomov@chromium.org's avatar dslomov@chromium.org

Avoid convertion to double when it is not needed.

R=rossberg@chromium.org

Review URL: https://codereview.chromium.org/15162002

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@14664 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 68eb1e50
......@@ -266,10 +266,12 @@ class Factory {
PretenureFlag pretenure = NOT_TENURED);
Handle<Object> NewNumberFromUint(uint32_t value,
PretenureFlag pretenure = NOT_TENURED);
inline Handle<Object> NewNumberFromSize(size_t value,
PretenureFlag pretenure = NOT_TENURED);
Handle<HeapNumber> NewHeapNumber(double value,
PretenureFlag pretenure = NOT_TENURED);
// These objects are used by the api to create env-independent data
// structures in the heap.
Handle<JSObject> NewNeanderObject();
......@@ -539,6 +541,18 @@ class Factory {
};
Handle<Object> Factory::NewNumberFromSize(size_t value,
PretenureFlag pretenure) {
if (Smi::IsValid(static_cast<intptr_t>(value))) {
return Handle<Object>(Smi::FromIntptr(static_cast<intptr_t>(value)),
isolate());
} else {
return NewNumber(static_cast<double>(value), pretenure);
}
}
} } // namespace v8::internal
#endif // V8_FACTORY_H_
......@@ -857,9 +857,9 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_TypedArrayInitialize) {
ASSERT(byte_length % elementSize == 0);
size_t length = byte_length / elementSize;
Handle<Object> length_obj =
isolate->factory()->NewNumber(static_cast<double>(length));
Handle<Object> length_obj = isolate->factory()->NewNumberFromSize(length);
holder->set_length(*length_obj);
Handle<ExternalArray> elements =
isolate->factory()->NewExternalArray(
static_cast<int>(length), arrayType,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment