Commit 46fc2af0 authored by Camillo Bruni's avatar Camillo Bruni Committed by Commit Bot

[builtins] Speed up Array.prototype.forEach for dictionary elements

We can avoid the ToString conversion before doing the HasProperty check.
This avoid a costly Smi to String conversion which is unecessary for the
following lookups.
For very large dictionary elements this is a significant slow down as we
will no longer hit the GetNumberStringCache.

Change-Id: I5a0eb13470ab3d3d8a87ee36d28ce7be5cbc2b2e
Reviewed-on: https://chromium-review.googlesource.com/626056Reviewed-by: 's avatarCamillo Bruni <cbruni@chromium.org>
Reviewed-by: 's avatarIgor Sheludko <ishell@chromium.org>
Commit-Queue: Camillo Bruni <cbruni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47574}
parent a653d269
......@@ -543,11 +543,21 @@ class ArrayBuiltinCodeStubAssembler : public CodeStubAssembler {
Label done_element(this, &to_);
// a. Let Pk be ToString(k).
Node* p_k = ToString(context(), k());
// We never have to perform a ToString conversion for Smi keys because
// they are guaranteed to be stored as elements. We easily hit this case
// when using any iteration builtin on a dictionary elements Array.
VARIABLE(p_k, MachineRepresentation::kTagged, k());
{
Label continue_with_key(this);
GotoIf(TaggedIsSmi(p_k.value()), &continue_with_key);
p_k.Bind(ToString(context(), p_k.value()));
Goto(&continue_with_key);
BIND(&continue_with_key);
}
// b. Let kPresent be HasProperty(O, Pk).
// c. ReturnIfAbrupt(kPresent).
Node* k_present = HasProperty(o(), p_k, context(), kHasProperty);
Node* k_present = HasProperty(o(), p_k.value(), context(), kHasProperty);
// d. If kPresent is true, then
GotoIf(WordNotEqual(k_present, TrueConstant()), &done_element);
......
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