Skip to content

Commit 12ee95c

Browse files
committed
Response to reviewi
Explicitly tell it I want an array instead of leaving it unspecified which kind of Ienumerable it ends up being, to guarantee faster calculation of Count() calls. (I don't know if this is really needed, given that partModule.Fields is of type BaseFields, which already does implement a quick Count() get, but I admit I have no idea what C# does when it executes a When clause, whether the subset it returns something of exactly the same type as the original collection or whether it makes a new IEnumerable collection out of it that might not be the same kind.)
1 parent b2bb206 commit 12ee95c

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/kOS/Suffixed/PartModuleField/PartModuleFields.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,8 @@ protected BaseField GetField(string cookedGuiName)
239239
// with the given GUI name. But Issue #2666 forced kOS to change it to a list of hits
240240
// because KSP started naming two fields with the same gui name, only one of which is visible
241241
// at a time:
242-
IEnumerable<BaseField> allMatches = partModule.Fields.Cast<BaseField>().
243-
Where(field => string.Equals(GetFieldName(field), cookedGuiName, StringComparison.CurrentCultureIgnoreCase));
242+
BaseField[] allMatches = partModule.Fields.Cast<BaseField>().
243+
Where(field => string.Equals(GetFieldName(field), cookedGuiName, StringComparison.CurrentCultureIgnoreCase)).ToArray<BaseField>();
244244
// When KSP is *not* doing the weird thing of two fields with the same name, there's just one hit and it's simple:
245245
if (allMatches.Count() == 1)
246246
return allMatches.First();

0 commit comments

Comments
 (0)