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

Tiny improvement ofStringBuilder.Append(StringBuilder)#101020

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
tannergooding merged 5 commits intodotnet:mainfromskyoxZ:patch-1
Jun 5, 2024

Conversation

@skyoxZ
Copy link
Contributor

it is guaranteed thatm_ChunkLength == 0 andm_ChunkChars.Length >= count afterExpandByABlock(count);.

@ghostghost added the needs-area-labelAn area label is needed to ensure this gets routed to the appropriate area owners labelApr 14, 2024
@dotnet-policy-servicedotnet-policy-servicebot added the community-contributionIndicates that the PR has been added by a community member labelApr 14, 2024
@jkotasjkotas added area-System.Runtime and removed needs-area-labelAn area label is needed to ensure this gets routed to the appropriate area owners labelsApr 14, 2024
@danmoseley
Copy link
Member

Worth an assert to self document?

MichalPetryka reacted with thumbs up emoji

@skyoxZ
Copy link
ContributorAuthor

Worth an assert to self document?

My answer would rather be no. PerhapsExpandByABlock had been something more complicated but at the moment its responsibility is quite straightforward and well documented: asserting current chunk is full and moving to a new chunk with a minimum size ofminBlockCharCount.

/// <summary>
/// Transfers the character buffer from this chunk to a new chunk, and allocates a new buffer with a minimum size for this chunk.
/// </summary>
/// <param name="minBlockCharCount">The minimum size of the new buffer to be allocated for this chunk.</param>
/// <remarks>
/// This method requires that the current chunk is full. Otherwise, there's no point in shifting the characters over.
/// It also assumes that 'this' is the last chunk in the linked list.
/// </remarks>
privatevoidExpandByABlock(intminBlockCharCount)

@tannergooding
Copy link
Member

If we're making an assumption, we should add an assert to validate that assumption holds true long term. Otherwise, it is trivially possible for a bug to be introduced due to a later refactoring or change.

danmoseley reacted with thumbs up emoji

@danmoseley
Copy link
Member

Also relevant, in some places StringBuilder relies on use of unsafe code such that bounds mistakes could cause and in the past have caused heap corruption. It's another reason to assert assumptions a little more than you might in some other code.

@danmoseley
Copy link
Member

timeouts, let's try again

Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.

Reviewers

@stephentoubstephentoubstephentoub approved these changes

@danmoseleydanmoseleydanmoseley approved these changes

Assignees

No one assigned

Labels

area-System.Runtimecommunity-contributionIndicates that the PR has been added by a community member

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

5 participants

@skyoxZ@danmoseley@tannergooding@stephentoub@jkotas

[8]ページ先頭

©2009-2025 Movatter.jp