Skip to content

Commit

Permalink
Restore for cycle in JsonConverter Write
Browse files Browse the repository at this point in the history
  • Loading branch information
andreise committed Aug 14, 2023
1 parent 2722cf3 commit cd2f9dc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ public override void Write(Utf8JsonWriter writer, FlatArray<T> value, JsonSerial
Debug.Assert(options is not null);

writer.WriteStartArray();
value.InternalForEach(item => itemConverter.Write(writer, item, options));

for (int i = 0; i < value.length; i++)
{
itemConverter.Write(writer, value.items![i], options);
}

writer.WriteEndArray();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@ partial struct FlatArray<T>
{
public void ForEach(Action<T> action)
=>
InternalForEach(action ?? throw new ArgumentNullException(nameof(action)));
InnerForEach(action ?? throw new ArgumentNullException(nameof(action)));

public void ForEach(Action<int, T> action)
=>
InternalForEach(action ?? throw new ArgumentNullException(nameof(action)));
InnerForEach(action ?? throw new ArgumentNullException(nameof(action)));

[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal void InternalForEach(Action<T> action)
private void InnerForEach(Action<T> action)
{
for (int i = 0; i < length; i++) { action.Invoke(items![i]); }
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal void InternalForEach(Action<int, T> action)
private void InnerForEach(Action<int, T> action)
{
for (int i = 0; i < length; i++) { action.Invoke(i, items![i]); }
}
Expand Down

0 comments on commit cd2f9dc

Please sign in to comment.