From 4e8633e31f419922c094101b30a0fc632a3979cc Mon Sep 17 00:00:00 2001 From: Dean Ellis Date: Mon, 6 Jan 2025 12:54:45 +0000 Subject: [PATCH] Feedback changes --- .../Xamarin.Android.Resource.Designer.targets | 2 +- .../Tasks/GenerateResourceCaseMap.cs | 26 +++++++++++-------- .../Utilities/FileResourceParser.cs | 14 ++++++---- 3 files changed, 25 insertions(+), 17 deletions(-) diff --git a/src/Xamarin.Android.Build.Tasks/MSBuild/Xamarin/Android/Xamarin.Android.Resource.Designer.targets b/src/Xamarin.Android.Build.Tasks/MSBuild/Xamarin/Android/Xamarin.Android.Resource.Designer.targets index 421c2243d84..251ebf5b9b5 100644 --- a/src/Xamarin.Android.Build.Tasks/MSBuild/Xamarin/Android/Xamarin.Android.Resource.Designer.targets +++ b/src/Xamarin.Android.Build.Tasks/MSBuild/Xamarin/Android/Xamarin.Android.Resource.Designer.targets @@ -72,7 +72,7 @@ Copyright (C) 2016 Xamarin. All rights reserved. > diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/GenerateResourceCaseMap.cs b/src/Xamarin.Android.Build.Tasks/Tasks/GenerateResourceCaseMap.cs index cc64c46bb75..6cadd6479f6 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/GenerateResourceCaseMap.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/GenerateResourceCaseMap.cs @@ -83,17 +83,21 @@ public override bool RunTask () if (entry.FullName != resmap) continue; Log.LogDebugMessage ($"Found: {entry.FullName}"); - using var ms = new MemoryStream(); - entry.Extract (ms); - ms.Position = 0; - using var reader = new StreamReader (ms); - string line; - // Read each line until the end of the file - while ((line = reader.ReadLine()) != null) { - if (string.IsNullOrEmpty (line)) - continue; - string [] tok = line.Split (';'); - AddRename (tok [1].Replace ('/', Path.DirectorySeparatorChar), tok [0].Replace ('/', Path.DirectorySeparatorChar)); + var ms = MemoryStreamPool.Shared.Rent (); + try { + entry.Extract (ms); + ms.Position = 0; + using var reader = new StreamReader (ms); + string line; + // Read each line until the end of the file + while ((line = reader.ReadLine()) != null) { + if (string.IsNullOrEmpty (line)) + continue; + string [] tok = line.Split (';'); + AddRename (tok [1].Replace ('/', Path.DirectorySeparatorChar), tok [0].Replace ('/', Path.DirectorySeparatorChar)); + } + } finally { + MemoryStreamPool.Shared.Return (ms); } // no need to read the rest of the files we found the one we want break; diff --git a/src/Xamarin.Android.Build.Tasks/Utilities/FileResourceParser.cs b/src/Xamarin.Android.Build.Tasks/Utilities/FileResourceParser.cs index fea1c5a617b..709ae2a7dd8 100644 --- a/src/Xamarin.Android.Build.Tasks/Utilities/FileResourceParser.cs +++ b/src/Xamarin.Android.Build.Tasks/Utilities/FileResourceParser.cs @@ -90,11 +90,15 @@ public IList Parse (string resourceDirectory, IEnumerable additionalR var path = Directory.GetParent (entry.FullName).Name; if (ext == ".xml" || ext == ".axml") { if (string.Compare (path, "raw", StringComparison.OrdinalIgnoreCase) != 0) { - using var ms = new MemoryStream (); - entry.Extract (ms); - ms.Position = 0; - using XmlReader reader = XmlReader.Create (ms); - ProcessXmlFile (reader, resources); + var ms = MemoryStreamPool.Shared.Rent (); + try { + entry.Extract (ms); + ms.Position = 0; + using XmlReader reader = XmlReader.Create (ms); + ProcessXmlFile (reader, resources); + } finally { + MemoryStreamPool.Shared.Return (ms); + } } } ProcessResourceFile (entry.FullName, resources, processXml: false);