Skip to content

Commit

Permalink
RavenDB-23220 - null check before materializing to string
Browse files Browse the repository at this point in the history
  • Loading branch information
grisha-kotler authored and ppekrol committed Jan 8, 2025
1 parent aedbe17 commit e2786df
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/Lucene.Net/Util/UnmanagedStringArray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,17 @@ public struct UnmanagedString : IComparable
{
public byte* Start;

public int Size => IsNull ? 0 : (*(int*)Start >> 1);
public int Size => *(int*)Start >> 1;
public bool StoredAsAscii => (*(int*)Start & 1) == 1;
public Span<byte> StringAsBytes => new Span<byte>(Start + sizeof(int), Size);
public Span<char> StringAsChars => new Span<char>(Start + sizeof(int), Size);
public bool IsNull => Start == default;

public override string ToString()
{
if (IsNull)
return string.Empty;

return StoredAsAscii ? Encoding.UTF8.GetString(StringAsBytes) : new string(StringAsChars);
}

Expand Down

0 comments on commit e2786df

Please sign in to comment.