-
Notifications
You must be signed in to change notification settings - Fork 760
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(CurrencyFormatter): Implement FormatDouble and ParseDouble
chore: refactoring test: Adjust runtime tests inclusion for UWP chore: add nullability chore: using StringBuilder chore: add simple StringBuilderPool chore: use ThreadLocal<StringBuilder> chore: use ThreadLocal<StringBuilder> feat(CurrencyIdentifiers): Implement properties chore: add necessary projects to Uno.UI-Windows-only chore: import StringBuilderCache from dotnet/runtime chore: consider positive/negative currency pattern when parse/format double chore: use file scoped namespace chore: fix format zero chore: move StringBuilderCache to Uno.Foundation chore: change StringBuilderCache namespace chore: generate expected test value based on system settings chore: update format positive/negative numbers based on patterns
- Loading branch information
1 parent
51fc6bf
commit d5616ad
Showing
29 changed files
with
5,968 additions
and
4,466 deletions.
There are no files selected for viewing
71 changes: 71 additions & 0 deletions
71
src/Uno.Foundation/Uno.Core.Extensions/Uno.Core.Extensions/StringBuilderCache.cs
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// This file is imported from dotnet/runtime | ||
// Source Link: https://github.com/dotnet/runtime/blob/e63d21947e734db2da5093510a6636b5b7fb45b5/src/libraries/Common/src/System/Text/StringBuilderCache.cs | ||
// Commit: a9c5ead on Feb 10, 2021, https://github.com/dotnet/runtime/commit/a9c5eadd951dcba73167f72cc624eb790573663a | ||
// | ||
#nullable enable | ||
// | ||
|
||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System; | ||
using System.Text; | ||
|
||
namespace Uno; | ||
|
||
/// <summary>Provide a cached reusable instance of stringbuilder per thread.</summary> | ||
internal static class StringBuilderCache | ||
{ | ||
// The value 360 was chosen in discussion with performance experts as a compromise between using | ||
// as little memory per thread as possible and still covering a large part of short-lived | ||
// StringBuilder creations on the startup path of VS designers. | ||
internal const int MaxBuilderSize = 360; | ||
private const int DefaultCapacity = 16; // == StringBuilder.DefaultCapacity | ||
|
||
// WARNING: We allow diagnostic tools to directly inspect this member (t_cachedInstance). | ||
// See https://github.com/dotnet/corert/blob/master/Documentation/design-docs/diagnostics/diagnostics-tools-contract.md for more details. | ||
// Please do not change the type, the name, or the semantic usage of this member without understanding the implication for tools. | ||
// Get in touch with the diagnostics team if you have questions. | ||
[ThreadStatic] | ||
private static StringBuilder? t_cachedInstance; | ||
|
||
/// <summary>Get a StringBuilder for the specified capacity.</summary> | ||
/// <remarks>If a StringBuilder of an appropriate size is cached, it will be returned and the cache emptied.</remarks> | ||
public static StringBuilder Acquire(int capacity = DefaultCapacity) | ||
{ | ||
if (capacity <= MaxBuilderSize) | ||
{ | ||
StringBuilder? sb = t_cachedInstance; | ||
if (sb != null) | ||
{ | ||
// Avoid stringbuilder block fragmentation by getting a new StringBuilder | ||
// when the requested size is larger than the current capacity | ||
if (capacity <= sb.Capacity) | ||
{ | ||
t_cachedInstance = null; | ||
sb.Clear(); | ||
return sb; | ||
} | ||
} | ||
} | ||
|
||
return new StringBuilder(capacity); | ||
} | ||
|
||
/// <summary>Place the specified builder in the cache if it is not too big.</summary> | ||
public static void Release(StringBuilder sb) | ||
{ | ||
if (sb.Capacity <= MaxBuilderSize) | ||
{ | ||
t_cachedInstance = sb; | ||
} | ||
} | ||
|
||
/// <summary>ToString() the stringbuilder, Release it to the cache, and return the resulting string.</summary> | ||
public static string GetStringAndRelease(StringBuilder sb) | ||
{ | ||
string result = sb.ToString(); | ||
Release(sb); | ||
return result; | ||
} | ||
} |
This file contains 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
This file contains 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
Oops, something went wrong.