Skip to content
Merged
Show file tree
Hide file tree
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 @@ -152,7 +152,11 @@ public void Reset()
ResetNodeStates();
ResetRemainingDependencies();

_completedResults.Clear();
while (_completedResults.TryDequeue(out _))
{
// do nothing, just clear the queue
}

ClearPendingMerges();
_mergeFailures?.Clear();
_activeNodes = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<RootNamespace>HotChocolate.Fusion</RootNamespace>
<LangVersion>preview</LangVersion>
<DefineConstants>$(DefineConstants);FUSION</DefineConstants>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ internal readonly DbRow Get(Cursor cursor)
{
AssertValidCursor(cursor);

return MemoryMarshal.Read<DbRow>(RowSpan(cursor));
return Unsafe.ReadUnaligned<DbRow>(ref RowRef(cursor));
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
Expand All @@ -437,16 +437,16 @@ internal readonly (Cursor, ElementTokenType) GetStartCursor(Cursor cursor)
{
AssertValidCursor(cursor);

var span = RowSpan(cursor);
var sourceAndType = MemoryMarshal.Read<int>(span[DbRow.SourceAndTypeOffset..]);
ref var row = ref RowRef(cursor);
var sourceAndType = Unsafe.ReadUnaligned<int>(ref Unsafe.Add(ref row, DbRow.SourceAndTypeOffset));
var tokenType = (ElementTokenType)((sourceAndType >>> 15) & 0x0F);

if (tokenType is ElementTokenType.Reference)
{
var value = MemoryMarshal.Read<int>(span[DbRow.LocationOrRowsOffset..]) & 0x1FFFFFFF;
var value = Unsafe.ReadUnaligned<int>(ref Unsafe.Add(ref row, DbRow.LocationOrRowsOffset)) & 0x1FFFFFFF;
cursor = new Cursor(value);
span = RowSpan(cursor);
sourceAndType = MemoryMarshal.Read<int>(span[DbRow.SourceAndTypeOffset..]);
row = ref RowRef(cursor);
sourceAndType = Unsafe.ReadUnaligned<int>(ref Unsafe.Add(ref row, DbRow.SourceAndTypeOffset));
tokenType = (ElementTokenType)((sourceAndType >>> 15) & 0x0F);
}

Expand All @@ -458,7 +458,7 @@ internal readonly int GetLocation(Cursor cursor)
{
AssertValidCursor(cursor);

var locationOrRows = MemoryMarshal.Read<int>(RowSpan(cursor)[DbRow.LocationOrRowsOffset..]);
var locationOrRows = Unsafe.ReadUnaligned<int>(ref Unsafe.Add(ref RowRef(cursor), DbRow.LocationOrRowsOffset));
return locationOrRows & 0x1FFFFFFF;
}

Expand All @@ -467,7 +467,7 @@ internal readonly Cursor GetLocationCursor(Cursor cursor)
{
AssertValidCursor(cursor);

var locationOrRows = MemoryMarshal.Read<int>(RowSpan(cursor)[DbRow.LocationOrRowsOffset..]);
var locationOrRows = Unsafe.ReadUnaligned<int>(ref Unsafe.Add(ref RowRef(cursor), DbRow.LocationOrRowsOffset));
return new Cursor(locationOrRows & 0x1FFFFFFF);
}

Expand All @@ -476,7 +476,7 @@ internal readonly int GetParent(Cursor cursor)
{
AssertValidCursor(cursor);

var parent = MemoryMarshal.Read<int>(RowSpan(cursor));
var parent = Unsafe.ReadUnaligned<int>(ref RowRef(cursor));
return parent & 0x1FFFFFFF;
}

Expand All @@ -485,7 +485,7 @@ internal readonly Cursor GetParentCursor(Cursor cursor)
{
AssertValidCursor(cursor);

var parent = MemoryMarshal.Read<int>(RowSpan(cursor)) & 0x1FFFFFFF;
var parent = Unsafe.ReadUnaligned<int>(ref RowRef(cursor)) & 0x1FFFFFFF;

return new Cursor(parent);
}
Expand All @@ -496,7 +496,7 @@ internal readonly int GetNumberOfRows(Cursor cursor)
AssertValidCursor(cursor);

// NumberOfRows shares storage with Location in int 3.
var value = MemoryMarshal.Read<int>(RowSpan(cursor)[DbRow.LocationOrRowsOffset..]);
var value = Unsafe.ReadUnaligned<int>(ref Unsafe.Add(ref RowRef(cursor), DbRow.LocationOrRowsOffset));
return value & 0x1FFFFFFF;
}

Expand All @@ -505,7 +505,7 @@ internal readonly ElementFlags GetFlags(Cursor cursor)
{
AssertValidCursor(cursor);

var selectionAndFlags = MemoryMarshal.Read<int>(RowSpan(cursor)[DbRow.SelectionAndFlagsOffset..]);
var selectionAndFlags = Unsafe.ReadUnaligned<int>(ref Unsafe.Add(ref RowRef(cursor), DbRow.SelectionAndFlagsOffset));
return (ElementFlags)((selectionAndFlags >> 17) & 0x7F);
}

Expand All @@ -530,7 +530,7 @@ internal readonly int GetSizeOrLength(Cursor cursor)
{
AssertValidCursor(cursor);

var value = MemoryMarshal.Read<int>(RowSpan(cursor)[DbRow.SizeOffset..]);
var value = Unsafe.ReadUnaligned<int>(ref Unsafe.Add(ref RowRef(cursor), DbRow.SizeOffset));

return value & int.MaxValue;
}
Expand Down Expand Up @@ -573,20 +573,31 @@ internal readonly ElementTokenType GetElementTokenType(Cursor cursor, bool resol
{
AssertValidCursor(cursor);

var sourceAndType = MemoryMarshal.Read<int>(RowSpan(cursor)[DbRow.SourceAndTypeOffset..]);
var sourceAndType = Unsafe.ReadUnaligned<int>(ref Unsafe.Add(ref RowRef(cursor), DbRow.SourceAndTypeOffset));
var tokenType = (ElementTokenType)((sourceAndType >>> 15) & 0x0F);

if (resolveReferences && tokenType == ElementTokenType.Reference)
{
var value = GetLocation(cursor);
var resolved = new Cursor(value);
sourceAndType = MemoryMarshal.Read<int>(RowSpan(resolved)[DbRow.SourceAndTypeOffset..]);
sourceAndType = Unsafe.ReadUnaligned<int>(ref Unsafe.Add(ref RowRef(resolved), DbRow.SourceAndTypeOffset));
tokenType = (ElementTokenType)((sourceAndType >>> 15) & 0x0F);
}

return tokenType;
}

/// <summary>
/// Returns a reference to the first byte of the row the cursor points to.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private readonly ref byte RowRef(Cursor cursor)
{
var chunk = _chunks[cursor.Chunk];
ref var data = ref MemoryMarshal.GetArrayDataReference(chunk.Buffer);
return ref Unsafe.Add(ref data, chunk.Offset + cursor.ByteOffset);
}
Comment on lines +593 to +599

/// <summary>
/// Returns the span that begins at the start of the row the cursor points to.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ internal int GetPropertyCount(Cursor current)
return row.SizeOrLength;
}

[SkipLocalsInit]
internal CompactPath CreateCompactPath(Cursor current)
{
var firstRow = _metaDb.Get(current);
Expand Down
Loading