Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/corert.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/System.Private.CoreLib/src/System/Text/StringBuilderCache.cs')
-rw-r--r--src/System.Private.CoreLib/src/System/Text/StringBuilderCache.cs85
1 files changed, 0 insertions, 85 deletions
diff --git a/src/System.Private.CoreLib/src/System/Text/StringBuilderCache.cs b/src/System.Private.CoreLib/src/System/Text/StringBuilderCache.cs
deleted file mode 100644
index a1b1f50e3..000000000
--- a/src/System.Private.CoreLib/src/System/Text/StringBuilderCache.cs
+++ /dev/null
@@ -1,85 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-/*============================================================
-**
-**
-** Purpose: provide a cached reusable instance of stringbuilder
-** per thread it's an optimisation that reduces the
-** number of instances constructed and collected.
-**
-** Acquire - is used to get a string builder to use of a
-** particular size. It can be called any number of
-** times, if a stringbuilder is in the cache then
-** it will be returned and the cache emptied.
-** subsequent calls will return a new stringbuilder.
-**
-** A StringBuilder instance is cached in
-** Thread Local Storage and so there is one per thread
-**
-** Release - Place the specified builder in the cache if it is
-** not too big.
-** The stringbuilder should not be used after it has
-** been released.
-** Unbalanced Releases are perfectly acceptable. It
-** will merely cause the runtime to create a new
-** stringbuilder next time Acquire is called.
-**
-** GetStringAndRelease
-** - ToString() the stringbuilder, Release it to the
-** cache and return the resulting string
-**
-===========================================================*/
-
-using System.Threading;
-
-namespace System.Text
-{
- internal static class StringBuilderCache
- {
- private const int MAX_BUILDER_SIZE = 260;
-
- // 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;
-
- public static StringBuilder Acquire(int capacity = StringBuilder.DefaultCapacity)
- {
- if (capacity <= MAX_BUILDER_SIZE)
- {
- StringBuilder sb = StringBuilderCache.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)
- {
- StringBuilderCache.t_cachedInstance = null;
- sb.Clear();
- return sb;
- }
- }
- }
- return new StringBuilder(capacity);
- }
-
- public static void Release(StringBuilder sb)
- {
- if (sb.Capacity <= MAX_BUILDER_SIZE)
- {
- StringBuilderCache.t_cachedInstance = sb;
- }
- }
-
- public static string GetStringAndRelease(StringBuilder sb)
- {
- string result = sb.ToString();
- Release(sb);
- return result;
- }
- }
-}