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
This commit is contained in:
dslomov@chromium.org 2013-05-14 15:03:27 +00:00
parent 68eb1e50ca
commit 5889699ecf
2 changed files with 17 additions and 3 deletions

View File

@ -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_

View File

@ -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,