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

Conversation

@stephentoub
Copy link
Member

  • 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.

cc: @jkotas, @JeremyKuhne, @eerhardt, @tarekgh

- 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.
Copy link
Member

@jkotas jkotas 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 doing this

[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);
Copy link
Member

@eerhardt eerhardt Nov 20, 2018

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.

Copy link
Member

@eerhardt eerhardt left a comment

Choose a reason for hiding this comment

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

:shipit:

@stephentoub
Copy link
Member Author

@dotnet-bot test OSX10.12 x64 Checked Innerloop Build and Test please (vector-related failures)

@stephentoub stephentoub merged commit a9b57bd into dotnet:master Nov 20, 2018
@stephentoub stephentoub deleted the sbmarshaling branch November 20, 2018 22:03
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.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants