Skip to content

Codegen: String.Concat called multiple times for concats of 3 and 4 strings #5560

@auduchinok

Description

@auduchinok

String.Concat is called multiple times in a row for 3 and 4 strings despite overloads taking these numbers of params are available.

3 strings:

let s a b =
    a + "." + b
IL_0000: ldarg.0      // a
IL_0001: ldstr        "."
IL_0006: call         string [System.Runtime]System.String::Concat(string, string)
IL_000b: ldarg.1      // b
IL_000c: call         string [System.Runtime]System.String::Concat(string, string)
IL_0011: ret        

4 strings:

let s1 a b c =
    a + "." + b + c
IL_0000: ldarg.0      // a
IL_0001: ldstr        "."
IL_0006: call         string [System.Runtime]System.String::Concat(string, string)
IL_000b: ldarg.1      // b
IL_000c: call         string [System.Runtime]System.String::Concat(string, string)
IL_0011: ldarg.2      // c
IL_0012: call         string [System.Runtime]System.String::Concat(string, string)
IL_0017: ret     

And the same in C#:

public static string S(string a, string b) => a + "." + b;
IL_0000: ldarg.0      // a
IL_0001: ldstr        "."
IL_0006: ldarg.1      // b
IL_0007: call         string [netstandard]System.String::Concat(string, string, string)
IL_000c: ret          
public static string S2(string a, string b, string c) => a + "." + b + c;
IL_0000: ldarg.0      // a
IL_0001: ldstr        "."
IL_0006: ldarg.1      // b
IL_0007: ldarg.2      // c
IL_0008: call         string [netstandard]System.String::Concat(string, string, string, string)
IL_000d: ret          

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions