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

TimeZoneInfo.StringSerializer: Avoid some unnecessary allocations #8783

Merged
merged 1 commit into from
Jan 3, 2017

Conversation

justinvp
Copy link

@justinvp justinvp commented Jan 3, 2017

Instead of using multiple calls to string.Replace to escape reserved chars before appending to a StringBuilder, do the replacing while appending the chars directly to the StringBuilder.

Also, append numbers/dates directly instead of running it through the escape method, as these Invariant-formatted strings will not contain any chars that need to be escaped.

It's easiest to review ignoring whitespace (I removed an unnecessary null/length check to reduce indentation): https://github.com/dotnet/coreclr/pull/8783/files?w=1

Instead of using multiple calls to `string.Replace` to escape reserved
chars before appending to a `StringBuilder`, do the replacing while
appending the chars directly to the `StringBuilder`.

Also, append numbers/dates directly instead of running it through the
escape method, as these Invariant-formatted strings will not contain any
chars that need to be escaped.
@tarekgh
Copy link
Member

tarekgh commented Jan 3, 2017

LGTM.

@tarekgh
Copy link
Member

tarekgh commented Jan 3, 2017

test Ubuntu x64 Checked Build and Test please

@tarekgh tarekgh merged commit 1d15b16 into dotnet:master Jan 3, 2017
@justinvp justinvp deleted the tzi_serializer_allocs branch January 4, 2017 00:13
@karelz karelz modified the milestone: 2.0.0 Aug 28, 2017
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
…tnet/coreclr#8783)

Instead of using multiple calls to `string.Replace` to escape reserved
chars before appending to a `StringBuilder`, do the replacing while
appending the chars directly to the `StringBuilder`.

Also, append numbers/dates directly instead of running it through the
escape method, as these Invariant-formatted strings will not contain any
chars that need to be escaped.

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

Successfully merging this pull request may close these issues.

4 participants