Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Add StringBuilder Span-based APIs #22852

Merged
merged 3 commits into from
Aug 11, 2017

Conversation

kevingosse
Copy link

Contributes to https://github.com/dotnet/corefx/issues/22430

Depends on dotnet/coreclr#13163

  • Add span-based Append/Insert/CopyTo methods to StringBuilder
  • Add unit tests for the new methods

@stephentoub stephentoub added the blocked Issue/PR is blocked on something - see comments label Aug 2, 2017
@karelz
Copy link
Member

karelz commented Aug 6, 2017

@kookiz thanks for your contribution! I sent you collaborator invite, so that we can assign work items to you in future. Once you accept, I recommend to disable CoreFX notifications, otherwise you will be DoS'd.

@stephentoub what is the PR blocked on? API review? Something else?

@stephentoub
Copy link
Member

@stephentoub what is the PR blocked on? API review? Something else?

@karelz, as the PR description says, this "depends on dotnet/coreclr#13163", which hasn't been merged yet.

@dnfclas
Copy link

dnfclas commented Aug 6, 2017

@kookiz, thanks for signing the contribution license agreement. We will now validate the agreement and then the pull request.

Thanks, .NET Foundation Pull Request Bot

@kevingosse
Copy link
Author

@dotnet-bot test this please

@danmoseley
Copy link
Member

@kookiz it is pointing out that you added types that aren't in UAP yet. I see the changes got into the coreRT repo in 3390e457df151e8481b63197b91f0f0b147c70ab so we just need to wait a day or two for corefx to see them, then we can reset this CI.

It is also possible to update system.runtime\src\apicompatbaseline.* but no point just for a day or two.

@stephentoub
Copy link
Member

so we just need to wait a day or two for corefx to see them

FYI, @danmosemsft, there's still a manual step involved... someone needs to kick off the mirror that pushes corert to the internal N branch.

@@ -7054,6 +7054,7 @@ public sealed partial class StringBuilder : System.Runtime.Serialization.ISerial
public System.Text.StringBuilder Append(uint value) { throw null; }
[System.CLSCompliantAttribute(false)]
public System.Text.StringBuilder Append(ulong value) { throw null; }
public System.Text.StringBuilder Append(ReadOnlySpan<char> value) { throw null; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: generally we use the full namespace, so System.ReadOnlySpan rather than just ReadOnlySpan. This applies to the other cases as well.

Copy link
Author

@kevingosse kevingosse Aug 11, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright

[InlineData("Hello", new char[] { 'a' }, "Helloa")]
[InlineData("Hello", new char[] { 'b', 'c', 'd' }, "Hellobcd")]
[InlineData("", new char[] { 'e', 'f', 'g' }, "efg")]
[InlineData("Hello", new char[0], "Hello")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be worthwhile adding a case that has a '\0' in the middle of it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do

var builder = new StringBuilder(original);
builder.Append(new ReadOnlySpan<char>(value));
Assert.Equal(expected, builder.ToString());
Assert.Equal(expected, builder.ToString());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reason for the duplicated line? Validating that ToString is idempotent? I'd hope that'd be covered in some test elsewhere, in which case it shouldn't also be necessary in this test focused on Append(Span)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wish it was something so smart, but I'm afraid I just slipped on my keyboard

Copy link
Member

@stephentoub stephentoub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding these.

@danmoseley
Copy link
Member

It is in the N branch.

@danmoseley
Copy link
Member

should work now #23092

@dotnet-bot test UWP NETNative x86 Release Build please
@dotnet-bot test UWP NETNative x86 Release Build please

however to fix the netfx failure you will need to make the tests exclude netfx

System\Text\StringBuilderTests.cs(1042,21): error CS7036: There is no argument given that corresponds to the required formal parameter 'count' of 'StringBuilder.CopyTo(int, char[], int, int)' [D:\j\workspace\windows-TGrou---2a8f9c29\src\System.Runtime\tests\System.Runtime.Tests.csproj]

[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "Not ported to Desktop")]

@danmoseley
Copy link
Member

@dotnet-bot test Packaging All Configurations x64 Debug Build please

@stephentoub
Copy link
Member

however to fix the netfx failure you will need to make the tests exclude netfx

The tests will actually need to not be built in to the netfx test library. They should be moved to https://github.com/KooKiz/corefx/blob/c76b0dd4876ad21b7d4971e9f2bbe47ad20975e6/src/System.Runtime/tests/System/Text/StringBuilderTests.netcoreapp.cs.

@danmoseley
Copy link
Member

Better still.

@danmoseley danmoseley removed the blocked Issue/PR is blocked on something - see comments label Aug 10, 2017
Copy link
Member

@stephentoub stephentoub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @kookiz!

@stephentoub stephentoub merged commit e2262cc into dotnet:master Aug 11, 2017
@kevingosse kevingosse deleted the stringbuilder_span branch August 11, 2017 20:32
@karelz karelz added this to the 2.1.0 milestone Aug 14, 2017
@karelz karelz added this to the 2.1.0 milestone Aug 14, 2017
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
* Add StringBuilder Span-based APIs

* Address PR feedback

* Move tests to netcoreapp


Commit migrated from dotnet/corefx@e2262cc
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants