updated linq calls to zero allocation zlinq

This commit is contained in:
Sebastian Bularca
2026-04-02 09:12:37 +02:00
parent 36d3f112ef
commit 530ffef338
16 changed files with 131 additions and 131 deletions

View File

@@ -1,6 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using ZLinq;
namespace Nox.Game {
public interface IPartyFactory {
@@ -28,7 +28,7 @@ namespace Nox.Game {
party.members.Add(protagonistClone);
if(companions != null) {
foreach(var companion in companions.Where(c => c != null)) {
foreach(var companion in companions.AsValueEnumerable().Where(c => c != null)) {
var companionClone = companion.Clone();
companionClone.Role = CharacterRole.Companion;
party.members.Add(companionClone);
@@ -44,12 +44,12 @@ namespace Nox.Game {
throw new ArgumentException($"Party size {party.members.Count} exceeds max {party.maxPartySize}.");
}
var protagonistCount = party.members.Count(m => m.Role == CharacterRole.Protagonist);
var protagonistCount = party.members.AsValueEnumerable().Count(m => m.Role == CharacterRole.Protagonist);
if(protagonistCount != 1) {
throw new ArgumentException($"Party must contain exactly one protagonist, found {protagonistCount}.");
}
var uniqueIds = party.members
var uniqueIds = party.members.AsValueEnumerable()
.Where(m => m.Id != Guid.Empty)
.Select(m => m.Id)
.Distinct()