This repository was archived by the owner on Jan 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Remove remaining StringBuilder marshaling use from Corelib #21120
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- Unix globalization functions were using StringBuilder. Replaced them with stackallocs, as the max sizes were all relatively small. - Registry methods were declared to use StringBuilder, but these weren't actually used by corelib, and in fact, corefx isn't using StringBuilder with them either. I've changed the definitions for now to use char[] instead (all the call sites are passing in null), and I'll fix up some corefx usage separately. - Resource-related functions were using StringBuilder, and have been replaced with stackallocs, given reasonably small max buffer sizes. - ExpandEnvironmentVariables was using a StringBuilder, but it's rewritten equivalent code in corefx is not. For now I've copied the corefx function over to coreclr to replace the different implementation, but we can look at subsequently consolidating them into one.
jkotas
approved these changes
Nov 20, 2018
Member
jkotas
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for doing this
src/System.Private.CoreLib/shared/Interop/Unix/System.Globalization.Native/Interop.Utils.cs
Outdated
Show resolved
Hide resolved
tarekgh
reviewed
Nov 20, 2018
src/System.Private.CoreLib/shared/Interop/Unix/System.Globalization.Native/Interop.Utils.cs
Outdated
Show resolved
Hide resolved
tarekgh
reviewed
Nov 20, 2018
src/System.Private.CoreLib/shared/Interop/Windows/User32/Interop.LoadString.cs
Outdated
Show resolved
Hide resolved
tarekgh
reviewed
Nov 20, 2018
eerhardt
reviewed
Nov 20, 2018
src/System.Private.CoreLib/shared/System.Private.CoreLib.Shared.projitems
Show resolved
Hide resolved
eerhardt
reviewed
Nov 20, 2018
src/System.Private.CoreLib/shared/System/Globalization/CultureData.Unix.cs
Outdated
Show resolved
Hide resolved
eerhardt
reviewed
Nov 20, 2018
| [DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_GetLocaleName")] | ||
| [return: MarshalAs(UnmanagedType.Bool)] | ||
| internal static extern unsafe bool GetLocaleName(string localeName, [Out] StringBuilder value, int valueLength); | ||
| internal static extern unsafe bool GetLocaleName(string localeName, char* value, int valueLength); |
Member
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(nit) I kind of like the documentation value that the [Out] attributes provides. But I'm totally fine with removing them here, since they can't be used with a pointer.
eerhardt
approved these changes
Nov 20, 2018
Member
eerhardt
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
![]()
JeremyKuhne
approved these changes
Nov 20, 2018
Member
Author
|
@dotnet-bot test OSX10.12 x64 Checked Innerloop Build and Test please (vector-related failures) |
picenka21
pushed a commit
to picenka21/runtime
that referenced
this pull request
Feb 18, 2022
…reclr#21120) * Remove remaining StringBuilder marshaling use from Corelib - Unix globalization functions were using StringBuilder. Replaced them with stackallocs, as the max sizes were all relatively small. - Registry methods were declared to use StringBuilder, but these weren't actually used by corelib, and in fact, corefx isn't using StringBuilder with them either. I've changed the definitions for now to use char[] instead (all the call sites are passing in null), and I'll fix up some corefx usage separately. - Resource-related functions were using StringBuilder, and have been replaced with stackallocs, given reasonably small max buffer sizes. - ExpandEnvironmentVariables was using a StringBuilder, but it's rewritten equivalent code in corefx is not. For now I've copied the corefx function over to coreclr to replace the different implementation, but we can look at subsequently consolidating them into one. * Address PR feedback Commit migrated from dotnet/coreclr@a9b57bd
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
cc: @jkotas, @JeremyKuhne, @eerhardt, @tarekgh