mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-16 15:24:10 +02:00
StringView.Intern
This commit is contained in:
parent
69f26e453d
commit
46fbba9712
1 changed files with 28 additions and 0 deletions
|
@ -3588,6 +3588,34 @@ namespace System
|
|||
return StringSplitEnumerator(Ptr, Length, separators, count, options);
|
||||
}
|
||||
|
||||
public String Intern()
|
||||
{
|
||||
using (String.[Friend]sMonitor.Enter())
|
||||
{
|
||||
bool needsLiteralPass = String.[Friend]sInterns.Count == 0;
|
||||
String* internalLinkPtr = *((String**)(String.[Friend]sStringLiterals));
|
||||
if (internalLinkPtr != String.[Friend]sPrevInternLinkPtr)
|
||||
{
|
||||
String.[Friend]sPrevInternLinkPtr = internalLinkPtr;
|
||||
needsLiteralPass = true;
|
||||
}
|
||||
if (needsLiteralPass)
|
||||
String.[Friend]CheckLiterals(String.[Friend]sStringLiterals);
|
||||
|
||||
String* entryPtr;
|
||||
if (String.[Friend]sInterns.TryAddAlt(this, out entryPtr))
|
||||
{
|
||||
String result = new String(mLength + 1);
|
||||
result.Append(this);
|
||||
result.EnsureNullTerminator();
|
||||
*entryPtr = result;
|
||||
String.[Friend]sOwnedInterns.Add(result);
|
||||
return result;
|
||||
}
|
||||
return *entryPtr;
|
||||
}
|
||||
}
|
||||
|
||||
public static operator StringView (String str)
|
||||
{
|
||||
StringView sv;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue