Skip to content

Commit 741c721

Browse files
committed
Change to possibly more efficient call.
1 parent 12ee95c commit 741c721

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/kOS/Suffixed/PartModuleField/PartModuleFields.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,12 +235,13 @@ public virtual BooleanValue HasField(StringValue fieldName)
235235
/// <returns>a BaseField - a KSP type that can be used to get the value, or its GUI name or its reflection info.</returns>
236236
protected BaseField GetField(string cookedGuiName)
237237
{
238-
// Conceptually this should be a FirstOrDefault(), because there should only be one Field
239-
// with the given GUI name. But Issue #2666 forced kOS to change it to a list of hits
238+
// Conceptually this should be a single hit using FirstOrDefault(), because there should only
239+
// be one Field with the given GUI name. But Issue #2666 forced kOS to change it to an array of hits
240240
// because KSP started naming two fields with the same gui name, only one of which is visible
241241
// at a time:
242242
BaseField[] allMatches = partModule.Fields.Cast<BaseField>().
243-
Where(field => string.Equals(GetFieldName(field), cookedGuiName, StringComparison.CurrentCultureIgnoreCase)).ToArray<BaseField>();
243+
Where(field => string.Equals(GetFieldName(field), cookedGuiName, StringComparison.CurrentCultureIgnoreCase)).
244+
ToArray<BaseField>();
244245
// When KSP is *not* doing the weird thing of two fields with the same name, there's just one hit and it's simple:
245246
if (allMatches.Count() == 1)
246247
return allMatches.First();

0 commit comments

Comments
 (0)