Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite3d5a65

Browse files
authored
Replaced string concatenation by StringBuilder usage in System.Net.Mail (#95760)
* Replaced string concatenation by StringBuilder usage* Collapsed invocation of Append and constructor* Used ValueStringBuilder* Added ValueStringBuilder to unit tests
1 parent2944aec commite3d5a65

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

‎src/libraries/System.Net.Mail/src/System.Net.Mail.csproj‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@
6868
<CompileInclude="System\Net\Mail\SmtpFailedRecipientsException.cs" />
6969
<CompileInclude="System\Net\Mail\SmtpStatusCode.cs" />
7070
<CompileInclude="System\Net\DelegatedStream.cs" />
71+
<CompileInclude="$(CommonPath)System\Text\ValueStringBuilder.cs"
72+
Link="Common\System\Text\ValueStringBuilder.cs" />
7173
<CompileInclude="$(CommonPath)DisableRuntimeMarshalling.cs"
7274
Link="Common\DisableRuntimeMarshalling.cs" />
7375
<CompileInclude="$(CommonPath)System\Net\LazyAsyncResult.cs"

‎src/libraries/System.Net.Mail/src/System/Net/Mail/MailAddressCollection.cs‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,25 +51,26 @@ internal void ParseValue(string addresses)
5151

5252
internalstringEncode(intcharsConsumed,boolallowUnicode)
5353
{
54-
stringencodedAddresses=string.Empty;
54+
varencodedAddresses=newValueStringBuilder(stackallocchar[256]);
5555

5656
//encode each address individually (except the first), fold and separate with a comma
5757
foreach(MailAddressaddressinthis)
5858
{
59-
if(string.IsNullOrEmpty(encodedAddresses))
59+
if(encodedAddresses.Length==0)
6060
{
6161
//no need to append a comma to the first one because it may be the only one.
62-
encodedAddresses=address.Encode(charsConsumed,allowUnicode);
62+
encodedAddresses.Append(address.Encode(charsConsumed,allowUnicode));
6363
}
6464
else
6565
{
6666
//appending another one, append a comma to separate and then fold and add the encoded address
6767
//the charsConsumed will be 1 because only the first line needs to account for the header itself for
6868
//line length; subsequent lines have a single whitespace character because they are folded here
69-
encodedAddresses+=", "+address.Encode(1,allowUnicode);
69+
encodedAddresses.Append(", ");
70+
encodedAddresses.Append(address.Encode(1,allowUnicode));
7071
}
7172
}
72-
returnencodedAddresses;
73+
returnencodedAddresses.ToString();
7374
}
7475
}
7576
}

‎src/libraries/System.Net.Mail/tests/Unit/System.Net.Mail.Unit.Tests.csproj‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@
142142
Link="Common\System\HexConverter.cs" />
143143
<CompileInclude="$(CommonPath)System\Obsoletions.cs"
144144
Link="Common\System\Obsoletions.cs" />
145+
<CompileInclude="$(CommonPath)System\Text\ValueStringBuilder.cs"
146+
Link="Common\System\Text\ValueStringBuilder.cs" />
145147
</ItemGroup>
146148
<!-- Unix specific files-->
147149
<ItemGroupCondition="'$(TargetPlatformIdentifier)' == 'unix'">

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp