Skip to content

Commit f2d1fa5

Browse files
committed
reduce unneeded internal use of IEnumerable<T>
1 parent d9c62b9 commit f2d1fa5

31 files changed

Lines changed: 97 additions & 89 deletions

src/SMAPI.Mods.ConsoleCommands/Framework/Commands/ArgumentParser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public bool TryGetInt(int index, string name, out int value, bool required = tru
111111
/// <returns>An enumerator that can be used to iterate through the collection.</returns>
112112
public IEnumerator<string> GetEnumerator()
113113
{
114-
return ((IEnumerable<string>)this.Values).GetEnumerator();
114+
return ((IReadOnlyList<string>)this.Values).GetEnumerator();
115115
}
116116

117117
/// <summary>Returns an enumerator that iterates through a collection.</summary>

src/SMAPI.Mods.ConsoleCommands/Framework/Commands/ConsoleCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ protected void LogArgumentNotInt(IMonitor monitor)
7373
/// <param name="data">The data to display.</param>
7474
/// <param name="header">The table header.</param>
7575
/// <param name="getRow">Returns a set of fields for a data value.</param>
76-
protected string GetTableString<T>(IEnumerable<T> data, string[] header, Func<T, string[]> getRow)
76+
protected string GetTableString<T>(T[] data, string[] header, Func<T, string[]> getRow)
7777
{
7878
// get table data
7979
int[] widths = header.Select(p => p.Length).ToArray();

src/SMAPI.Tests/Utilities/KeybindListTests.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,9 @@ public SButtonState GetState(string input, string stateMap)
121121
** Private methods
122122
*********/
123123
/// <summary>Get all defined buttons.</summary>
124-
private static IEnumerable<SButton> GetAllButtons()
124+
private static SButton[] GetAllButtons()
125125
{
126-
foreach (SButton button in Enum.GetValues<SButton>())
127-
yield return button;
126+
return Enum.GetValues<SButton>();
128127
}
129128

130129
/// <summary>Get the button state defined by a mapping string.</summary>

src/SMAPI.Toolkit/Framework/ModData/ModDataModel.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,17 @@ public IEnumerable<ModDataField> GetFields()
109109
}
110110

111111
/// <summary>Get the former mod IDs.</summary>
112-
public IEnumerable<string> GetFormerIds()
112+
public string[] GetFormerIds()
113113
{
114-
if (this.FormerIds != null)
115-
{
116-
foreach (string id in this.FormerIds.Split('|'))
117-
yield return id.Trim();
118-
}
114+
#if NET6_0_OR_GREATER
115+
return
116+
this.FormerIds?.Split('|', StringSplitOptions.TrimEntries)
117+
?? [];
118+
#else
119+
return this.FormerIds != null
120+
? this.FormerIds.Split('|').Select(id => id.Trim()).ToArray()
121+
: [];
122+
#endif
119123
}
120124

121125

src/SMAPI.Toolkit/Framework/ModData/ModDataRecord.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ internal ModDataRecord(string displayName, ModDataModel model)
3939
{
4040
this.DisplayName = displayName;
4141
this.ID = model.Id;
42-
this.FormerIDs = model.GetFormerIds().ToArray();
42+
this.FormerIDs = model.GetFormerIds();
4343
this.SuppressWarnings = model.SuppressWarnings;
4444
this.IgnoreDependencies = model.IgnoreDependencies;
4545
this.Fields = model.GetFields().ToArray();

src/SMAPI.Toolkit/Framework/ModData/ModDatabase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public ModDatabase(ModDataRecord[] records, Func<string, string?> getUpdateUrl)
3434
}
3535

3636
/// <summary>Get all mod data records.</summary>
37-
public IEnumerable<ModDataRecord> GetAll()
37+
public IReadOnlyList<ModDataRecord> GetAll()
3838
{
3939
return this.Records;
4040
}

src/SMAPI.Toolkit/Framework/ModScanning/ModFolder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public ModFolder(string displayName, string directoryPath, ModType type, Manifes
9090

9191
/// <summary>Get the update keys for a mod.</summary>
9292
/// <param name="manifest">The mod manifest.</param>
93-
public IEnumerable<string> GetUpdateKeys(Manifest manifest)
93+
public IReadOnlyList<string> GetUpdateKeys(Manifest manifest)
9494
{
9595
return
9696
manifest.UpdateKeys

src/SMAPI/Events/BuildingListChangedEventArgs.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public class BuildingListChangedEventArgs : EventArgs
3232
/// <param name="location">The location which changed.</param>
3333
/// <param name="added">The buildings added to the location.</param>
3434
/// <param name="removed">The buildings removed from the location.</param>
35-
internal BuildingListChangedEventArgs(GameLocation location, IEnumerable<Building> added, IEnumerable<Building> removed)
35+
internal BuildingListChangedEventArgs(GameLocation location, IReadOnlyList<Building> added, IReadOnlyList<Building> removed)
3636
{
3737
this.Location = location;
3838
this.Added = added.ToArray();

src/SMAPI/Events/DebrisListChangedEventArgs.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public class DebrisListChangedEventArgs : EventArgs
3131
/// <param name="location">The location which changed.</param>
3232
/// <param name="added">The debris added to the location.</param>
3333
/// <param name="removed">The debris removed from the location.</param>
34-
internal DebrisListChangedEventArgs(GameLocation location, IEnumerable<Debris> added, IEnumerable<Debris> removed)
34+
internal DebrisListChangedEventArgs(GameLocation location, IReadOnlyList<Debris> added, IReadOnlyList<Debris> removed)
3535
{
3636
this.Location = location;
3737
this.Added = added.ToArray();

src/SMAPI/Events/FurnitureListChangedEventArgs.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public class FurnitureListChangedEventArgs : EventArgs
3232
/// <param name="location">The location which changed.</param>
3333
/// <param name="added">The furniture added to the location.</param>
3434
/// <param name="removed">The furniture removed from the location.</param>
35-
internal FurnitureListChangedEventArgs(GameLocation location, IEnumerable<Furniture> added, IEnumerable<Furniture> removed)
35+
internal FurnitureListChangedEventArgs(GameLocation location, IReadOnlyList<Furniture> added, IReadOnlyList<Furniture> removed)
3636
{
3737
this.Location = location;
3838
this.Added = added.ToArray();

0 commit comments

Comments
 (0)