Skip to content

Commit

Permalink
create array directly bypassing conversions
Browse files Browse the repository at this point in the history
  • Loading branch information
lahma committed May 30, 2021
1 parent 12d8778 commit fd7e301
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
10 changes: 10 additions & 0 deletions Jint/Native/Array/ArrayConstructor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,16 @@ private ArrayInstance ConstructArrayFromIEnumerable(IEnumerable enumerable)
return jsArray;
}

internal ArrayInstance ConstructFast(List<JsValue> contents)
{
var instance = ConstructFast((ulong) contents.Count);
for (var i = 0; i < contents.Count; i++)
{
instance.SetIndexValue((uint) i, contents[i], updateLength: false);
}
return instance;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal ArrayInstance ConstructFast(ulong length)
{
Expand Down
5 changes: 2 additions & 3 deletions Jint/Native/Promise/PromiseConstructor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ internal sealed record PromiseCapability(
JsValue RejectObj
);


public sealed class PromiseConstructor : FunctionInstance, IConstructor
{
private static readonly JsString _functionName = new JsString("Promise");
Expand Down Expand Up @@ -230,8 +229,8 @@ void ResolveIfFinished()
// if "then" method is sync then it will be resolved BEFORE the next iteration cycle
if (results.TrueForAll(static x => x != null) && doneIterating)
{
resolve.Call(Undefined,
new JsValue[] {Engine.Array.Construct(results.ToArray())});
var array = _engine.Array.ConstructFast(results);
resolve.Call(Undefined, new JsValue[] { array });
}
}

Expand Down

0 comments on commit fd7e301

Please sign in to comment.