From 62328e438487a55cb84ee09ef966092572b2252e Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Thu, 2 Jun 2022 01:28:04 -0400 Subject: [PATCH] tweak new code, update release notes --- docs/release-notes.md | 1 + src/SMAPI/Framework/Content/ContentCache.cs | 12 ++++-------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/docs/release-notes.md b/docs/release-notes.md index db229ecf..66447b3d 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -6,6 +6,7 @@ See [release highlights](https://www.patreon.com/posts/66986798). * For players: * Optimized mod image file loading. + * Minor optimizations (thanks to Michael Kuklinski / Ameisen!). * For mod authors: * Added a new `IRawTextureData` asset type. _You can now load image files through `helper.ModContent` as `IRawTextureData` instead of `Texture2D`. This provides the image size and raw pixel data, which you can pass into other SMAPI APIs like `asset.AsImage().PatchImage`. This is much more efficient when you don't need a full `Texture2D` instance, since it bypasses the GPU operations needed to create one._ diff --git a/src/SMAPI/Framework/Content/ContentCache.cs b/src/SMAPI/Framework/Content/ContentCache.cs index 959d4fb3..bf42812b 100644 --- a/src/SMAPI/Framework/Content/ContentCache.cs +++ b/src/SMAPI/Framework/Content/ContentCache.cs @@ -106,23 +106,19 @@ namespace StardewModdingAPI.Framework.Content /// Returns any removed keys. public IEnumerable Remove(Func predicate, bool dispose) { - List removed = new List(); + List removed = new(); foreach ((string key, object value) in this.Cache) { if (predicate(key, value)) - { removed.Add(key); - } } foreach (string key in removed) - { this.Remove(key, dispose); - } - // If `removed` is empty, return an empty `Enumerable` instead so that `removed` - // can be quickly collected in Gen0 instead of potentially living longer. - return removed.Count == 0 ? Enumerable.Empty() : removed; + return removed.Count == 0 + ? Enumerable.Empty() // let GC collect the list in gen0 instead of potentially living longer + : removed; } } }