Repository: dotnet/runtime
File: src/coreclr/tools/Common/JitInterface/WasmLowering.cs (C#)

Code before:
        /// <returns></returns>
        public static WasmFuncType GetSignature(MethodDesc method)
        {
            MethodSignature signature = method.Signature;
            TypeDesc returnType = signature.ReturnType;
            WasmValueType pointerType = (method.Context.Target.PointerSize == 4) ? WasmValueType.I32 : WasmValueType.I64;

            // Determine if the return value is via a return buffer
            //
            TypeDesc loweredReturnType = LowerToAbiType(returnType);
            bool hasReturnBuffer = false;
            bool returnIsVoid = false;
            bool hasThis = false;
            bool explicitThis = false;

            if (loweredReturnType == null)
            {
                hasReturnBuffer = true;
                returnIsVoid = true;
            }
            else if (loweredReturnType.IsVoid)
            {
                returnIsVoid = true;
            }

            System.Collections.Generic.List<WasmValueType> result = new(signature.Length + 4);

            if (!signature.IsStatic)
            {
                hasThis = true;

                if (signature.IsExplicitThis)
                {
                    explicitThis = true;
                }
                else
                {
                    // FIXME: implicit this
                }
            }

            if (method.IsUnmanagedCallersOnly) // reverse P/Invoke
            {
                if (hasReturnBuffer)
                {
                    result.Add(pointerType);
                }
            }
            else // managed call
            {
                result.Add(pointerType); // Stack pointer parameter

Review comment (suggestion):
We have an ArrayBuilder type that can be used to build arrays with less overhead than List.

Code after:
        /// <param name="method"></param>
        /// <returns></returns>
        public static WasmFuncType GetSignature(MethodDesc method)
        {
            MethodSignature signature = method.Signature;
            TypeDesc returnType = signature.ReturnType;
            WasmValueType pointerType = (method.Context.Target.PointerSize == 4) ? WasmValueType.I32 : WasmValueType.I64;

            // Determine if the return value is via a return buffer
            //
            TypeDesc loweredReturnType = LowerToAbiType(returnType);
            bool hasReturnBuffer = false;
            bool returnIsVoid = false;
            bool hasThis = false;
            bool explicitThis = false;

            if (loweredReturnType == null)
            {
                hasReturnBuffer = true;
                returnIsVoid = true;
            }
            else if (loweredReturnType.IsVoid)
            {
                returnIsVoid = true;
            }

            // Reserve space for potential implicit this, stack pointer parameter, portable entrypoint parameter, and return buffer
            ArrayBuilder<WasmValueType> result = new(signature.Length + 4);

            if (!signature.IsStatic)
            {
                hasThis = true;

                if (signature.IsExplicitThis)
                {
                    explicitThis = true;
                }
            }

            if (method.IsUnmanagedCallersOnly) // reverse P/Invoke
            {
                if (hasReturnBuffer)
                {
                    result.Add(pointerType);
                }
            }
            else // managed call
            {
                result.Add(pointerType); // Stack pointer parameter

                if (hasThis)