Commit dd6f62e6 authored by verwaest's avatar verwaest Committed by Commit bot

[runtime] inline fast-path ToName, ToUint32 (used by ToArrayIndex)

This speeds up hasOwnProperty 5-10%

BUG=

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

Cr-Commit-Position: refs/heads/master@{#34362}
parent d1df58e8
......@@ -1003,6 +1003,24 @@ bool Object::FitsRepresentation(Representation representation) {
return true;
}
bool Object::ToUint32(uint32_t* value) {
if (IsSmi()) {
int num = Smi::cast(this)->value();
if (num < 0) return false;
*value = static_cast<uint32_t>(num);
return true;
}
if (IsHeapNumber()) {
double num = HeapNumber::cast(this)->value();
if (num < 0) return false;
uint32_t uint_value = FastD2UI(num);
if (FastUI2D(uint_value) == num) {
*value = uint_value;
return true;
}
}
return false;
}
// static
MaybeHandle<JSReceiver> Object::ToObject(Isolate* isolate,
......@@ -1012,6 +1030,12 @@ MaybeHandle<JSReceiver> Object::ToObject(Isolate* isolate,
}
// static
MaybeHandle<Name> Object::ToName(Isolate* isolate, Handle<Object> input) {
if (input->IsName()) return Handle<Name>::cast(input);
return ConvertToName(isolate, input);
}
// static
MaybeHandle<Object> Object::ToPrimitive(Handle<Object> input,
ToPrimitiveHint hint) {
......
......@@ -114,16 +114,6 @@ MaybeHandle<JSReceiver> Object::ToObject(Isolate* isolate,
}
// static
MaybeHandle<Name> Object::ToName(Isolate* isolate, Handle<Object> input) {
ASSIGN_RETURN_ON_EXCEPTION(
isolate, input, Object::ToPrimitive(input, ToPrimitiveHint::kString),
Name);
if (input->IsName()) return Handle<Name>::cast(input);
return ToString(isolate, input);
}
// static
MaybeHandle<Object> Object::ToNumber(Handle<Object> input) {
while (true) {
......@@ -174,6 +164,16 @@ MaybeHandle<Object> Object::ToUint32(Isolate* isolate, Handle<Object> input) {
}
// static
MaybeHandle<Name> Object::ConvertToName(Isolate* isolate,
Handle<Object> input) {
ASSIGN_RETURN_ON_EXCEPTION(
isolate, input, Object::ToPrimitive(input, ToPrimitiveHint::kString),
Name);
if (input->IsName()) return Handle<Name>::cast(input);
return ToString(isolate, input);
}
// static
MaybeHandle<String> Object::ToString(Isolate* isolate, Handle<Object> input) {
while (true) {
......@@ -892,26 +892,6 @@ bool Object::ToInt32(int32_t* value) {
}
bool Object::ToUint32(uint32_t* value) {
if (IsSmi()) {
int num = Smi::cast(this)->value();
if (num < 0) return false;
*value = static_cast<uint32_t>(num);
return true;
}
if (IsHeapNumber()) {
double num = HeapNumber::cast(this)->value();
if (num < 0) return false;
uint32_t uint_value = FastD2UI(num);
if (FastUI2D(uint_value) == num) {
*value = uint_value;
return true;
}
}
return false;
}
bool FunctionTemplateInfo::IsTemplateFor(Object* object) {
if (!object->IsHeapObject()) return false;
return IsTemplateFor(HeapObject::cast(object)->map());
......
......@@ -1068,7 +1068,7 @@ class Object {
INLINE(bool IsNaN() const);
INLINE(bool IsMinusZero() const);
bool ToInt32(int32_t* value);
bool ToUint32(uint32_t* value);
inline bool ToUint32(uint32_t* value);
inline Representation OptimalRepresentation();
......@@ -1120,8 +1120,8 @@ class Object {
Isolate* isolate, Handle<Object> object, Handle<Context> context);
// ES6 section 7.1.14 ToPropertyKey
MUST_USE_RESULT static MaybeHandle<Name> ToName(Isolate* isolate,
Handle<Object> input);
MUST_USE_RESULT static inline MaybeHandle<Name> ToName(Isolate* isolate,
Handle<Object> input);
// ES6 section 7.1.1 ToPrimitive
MUST_USE_RESULT static inline MaybeHandle<Object> ToPrimitive(
......@@ -1371,6 +1371,9 @@ class Object {
LookupIterator* it, Handle<Object> value, LanguageMode language_mode,
StoreFromKeyed store_mode, bool* found);
MUST_USE_RESULT static MaybeHandle<Name> ConvertToName(Isolate* isolate,
Handle<Object> input);
DISALLOW_IMPLICIT_CONSTRUCTORS(Object);
};
......
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