Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/System.Management.Automation/engine/parser/Compiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ internal static class CachedReflectionInfo
internal static readonly MethodInfo ObjectList_ToArray =
typeof(List<object>).GetMethod(nameof(List<object>.ToArray), Type.EmptyTypes);

internal static readonly MethodInfo ArrayOps_AddObject =
typeof(ArrayOps).GetMethod(nameof(ArrayOps.AddObjectArray), StaticFlags);

internal static readonly MethodInfo ArrayOps_GetMDArrayValue =
typeof(ArrayOps).GetMethod(nameof(ArrayOps.GetMDArrayValue), StaticFlags);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2717,6 +2717,14 @@ private DynamicMetaObject BinaryAdd(DynamicMetaObject target, DynamicMetaObject
lhsEnumerator.Expression.Cast(typeof(IEnumerator)),
rhsEnumerator.Expression.Cast(typeof(IEnumerator)));
}
else if (target.Value is object[] targetArray)
{
// Adding 1 item to an object[]
// This is an optimisation over the default EnumerableOps_AddObject.
call = Expression.Call(CachedReflectionInfo.ArrayOps_AddObject,
target.Expression.Cast(typeof(object[])),
arg.Expression.Cast(typeof(object)));
}
else
{
// Adding 1 item to a list
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ namespace System.Management.Automation
{
internal static class ArrayOps
{
internal static object AddObjectArray(object[] lhs, object rhs)
{
int newIdx = lhs.Length;
Array.Resize(ref lhs, newIdx + 1);
Comment thread
iSazonov marked this conversation as resolved.
Resolved
lhs[newIdx] = rhs;

return lhs;
}

internal static object[] SlicingIndex(object target, object[] indexes, Func<object, object, object> indexer)
{
var result = new object[indexes.Length];
Expand Down