@@ -15,31 +15,31 @@ public static string ComputeDisplayName(string name, Version? version, string? c
1515 const int PUBLIC_KEY_TOKEN_LEN = 8 ;
1616 Debug . Assert ( name . Length != 0 ) ;
1717
18- StringBuilder sb = new StringBuilder ( ) ;
19- sb . AppendQuoted ( name ) ;
18+ var vsb = new ValueStringBuilder ( stackalloc char [ 256 ] ) ;
19+ vsb . AppendQuoted ( name ) ;
2020
2121 if ( version != null )
2222 {
2323 Version canonicalizedVersion = version . CanonicalizeVersion ( ) ;
2424 if ( canonicalizedVersion . Major != ushort . MaxValue )
2525 {
26- sb . Append ( ", Version=" ) ;
27- sb . Append ( canonicalizedVersion . Major ) ;
26+ vsb . Append ( ", Version=" ) ;
27+ vsb . AppendSpanFormattable ( canonicalizedVersion . Major ) ;
2828
2929 if ( canonicalizedVersion . Minor != ushort . MaxValue )
3030 {
31- sb . Append ( '.' ) ;
32- sb . Append ( canonicalizedVersion . Minor ) ;
31+ vsb . Append ( '.' ) ;
32+ vsb . AppendSpanFormattable ( canonicalizedVersion . Minor ) ;
3333
3434 if ( canonicalizedVersion . Build != ushort . MaxValue )
3535 {
36- sb . Append ( '.' ) ;
37- sb . Append ( canonicalizedVersion . Build ) ;
36+ vsb . Append ( '.' ) ;
37+ vsb . AppendSpanFormattable ( canonicalizedVersion . Build ) ;
3838
3939 if ( canonicalizedVersion . Revision != ushort . MaxValue )
4040 {
41- sb . Append ( '.' ) ;
42- sb . Append ( canonicalizedVersion . Revision ) ;
41+ vsb . Append ( '.' ) ;
42+ vsb . AppendSpanFormattable ( canonicalizedVersion . Revision ) ;
4343 }
4444 }
4545 }
@@ -50,36 +50,38 @@ public static string ComputeDisplayName(string name, Version? version, string? c
5050 {
5151 if ( cultureName . Length == 0 )
5252 cultureName = "neutral" ;
53- sb . Append ( ", Culture=" ) ;
54- sb . AppendQuoted ( cultureName ) ;
53+ vsb . Append ( ", Culture=" ) ;
54+ vsb . AppendQuoted ( cultureName ) ;
5555 }
5656
5757 if ( pkt != null )
5858 {
5959 if ( pkt . Length > PUBLIC_KEY_TOKEN_LEN )
6060 throw new ArgumentException ( ) ;
6161
62- sb . Append ( ", PublicKeyToken=" ) ;
62+ vsb . Append ( ", PublicKeyToken=" ) ;
6363 if ( pkt . Length == 0 )
64- sb . Append ( "null" ) ;
64+ {
65+ vsb . Append ( "null" ) ;
66+ }
6567 else
6668 {
67- sb . Append ( HexConverter . ToString ( pkt , HexConverter . Casing . Lower ) ) ;
69+ HexConverter . EncodeToUtf16 ( pkt , vsb . AppendSpan ( pkt . Length * 2 ) , HexConverter . Casing . Lower ) ;
6870 }
6971 }
7072
7173 if ( 0 != ( flags & AssemblyNameFlags . Retargetable ) )
72- sb . Append ( ", Retargetable=Yes" ) ;
74+ vsb . Append ( ", Retargetable=Yes" ) ;
7375
7476 if ( contentType == AssemblyContentType . WindowsRuntime )
75- sb . Append ( ", ContentType=WindowsRuntime" ) ;
77+ vsb . Append ( ", ContentType=WindowsRuntime" ) ;
7678
7779 // NOTE: By design (desktop compat) AssemblyName.FullName and ToString() do not include ProcessorArchitecture.
7880
79- return sb . ToString ( ) ;
81+ return vsb . ToString ( ) ;
8082 }
8183
82- private static void AppendQuoted ( this StringBuilder sb , string s )
84+ private static void AppendQuoted ( this ref ValueStringBuilder vsb , string s )
8385 {
8486 bool needsQuoting = false ;
8587 const char quoteChar = '\" ' ;
@@ -90,7 +92,7 @@ private static void AppendQuoted(this StringBuilder sb, string s)
9092 needsQuoting = true ;
9193
9294 if ( needsQuoting )
93- sb . Append ( quoteChar ) ;
95+ vsb . Append ( quoteChar ) ;
9496
9597 for ( int i = 0 ; i < s . Length ; i ++ )
9698 {
@@ -101,24 +103,24 @@ private static void AppendQuoted(this StringBuilder sb, string s)
101103 case '=' :
102104 case '\' ' :
103105 case '"' :
104- sb . Append ( '\\ ' ) ;
106+ vsb . Append ( '\\ ' ) ;
105107 break ;
106108 case '\t ' :
107- sb . Append ( "\\ t" ) ;
109+ vsb . Append ( "\\ t" ) ;
108110 continue ;
109111 case '\r ' :
110- sb . Append ( "\\ r" ) ;
112+ vsb . Append ( "\\ r" ) ;
111113 continue ;
112114 case '\n ' :
113- sb . Append ( "\\ n" ) ;
115+ vsb . Append ( "\\ n" ) ;
114116 continue ;
115117 }
116118
117- sb . Append ( s [ i ] ) ;
119+ vsb . Append ( s [ i ] ) ;
118120 }
119121
120122 if ( needsQuoting )
121- sb . Append ( quoteChar ) ;
123+ vsb . Append ( quoteChar ) ;
122124 }
123125
124126 private static Version CanonicalizeVersion ( this Version version )
0 commit comments