Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ private unsafe void UnsafeParse(char* chars, int charCount)
}
}

public unsafe int ToCharArray(char[] chars, int offset)
public int ToCharArray(char[] chars, int offset)
{
int count = CharArrayLength;

Expand All @@ -213,17 +213,23 @@ public unsafe int ToCharArray(char[] chars, int offset)
if (count > chars.Length - offset)
throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(chars), SR.Format(SR.XmlArrayTooSmallOutput, count)));

ToSpan(chars.AsSpan(offset, count));
return count;
}

private unsafe void ToSpan(Span<char> chars)
{
if (_s != null)
{
_s.CopyTo(0, chars, offset, count);
_s.CopyTo(chars);
}
else
{
byte* bytes = stackalloc byte[guidLength];
UnsafeSetInt64(_idLow, bytes);
UnsafeSetInt64(_idHigh, &bytes[8]);

fixed (char* _pch = &chars[offset])
fixed (char* _pch = &chars[0])
{
char* pch = _pch;
pch[0] = 'u';
Expand Down Expand Up @@ -258,8 +264,6 @@ public unsafe int ToCharArray(char[] chars, int offset)
UnsafeEncode(bytes[15], &pch[43]);
}
}

return count;
}

public bool TryGetGuid(out Guid guid)
Expand Down Expand Up @@ -300,17 +304,8 @@ public unsafe bool TryGetGuid(byte[] buffer, int offset)
return true;
}

public unsafe override string ToString()
{
if (_s == null)
{
int length = CharArrayLength;
char[] chars = new char[length];
ToCharArray(chars, 0);
_s = new string(chars, 0, length);
}
return _s;
}
public override string ToString() =>
_s ??= string.Create(CharArrayLength, this, (destination, thisRef) => thisRef.ToSpan(destination));

public static bool operator ==(UniqueId? id1, UniqueId? id2)
{
Expand Down