Commit 155a392b authored by verwaest's avatar verwaest Committed by Commit bot

Speed up common ObjectProtoToString cases

1) avoid the builder
2) by precomputing the result we're guaranteed to have a flat string
avoiding extra cost later of using the string

BUG=

Review-Url: https://codereview.chromium.org/1988023004
Cr-Commit-Position: refs/heads/master@{#36352}
parent 9c15c055
......@@ -12,6 +12,10 @@
V(arguments_string, "arguments") \
V(Arguments_string, "Arguments") \
V(Array_string, "Array") \
V(array_to_string, "[object Array]") \
V(object_to_string, "[object Object]") \
V(string_to_string, "[object String]") \
V(function_to_string, "[object Function]") \
V(bind_string, "bind") \
V(bool16x8_string, "bool16x8") \
V(Bool16x8_string, "Bool16x8") \
......
......@@ -15236,8 +15236,12 @@ bool JSObject::WasConstructedFromApiFunction() {
MaybeHandle<String> Object::ObjectProtoToString(Isolate* isolate,
Handle<Object> object) {
if (object->IsUndefined()) return isolate->factory()->undefined_to_string();
if (object->IsNull()) return isolate->factory()->null_to_string();
if (*object == isolate->heap()->undefined_value()) {
return isolate->factory()->undefined_to_string();
}
if (*object == isolate->heap()->null_value()) {
return isolate->factory()->null_to_string();
}
Handle<JSReceiver> receiver =
Object::ToObject(isolate, object).ToHandleChecked();
......@@ -15258,6 +15262,18 @@ MaybeHandle<String> Object::ObjectProtoToString(Isolate* isolate,
JSReceiver::BuiltinStringTag(receiver), String);
}
if (*tag == isolate->heap()->Object_string()) {
return isolate->factory()->object_to_string();
}
if (*tag == isolate->heap()->String_string()) {
return isolate->factory()->string_to_string();
}
if (*tag == isolate->heap()->Array_string()) {
return isolate->factory()->array_to_string();
}
if (*tag == isolate->heap()->Function_string()) {
return isolate->factory()->function_to_string();
}
IncrementalStringBuilder builder(isolate);
builder.AppendCString("[object ");
builder.AppendString(tag);
......
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