From 0c4aa523ed599753ca0fe9fcdc7f5c41d6ce1d57 Mon Sep 17 00:00:00 2001 From: h3xds1nz Date: Wed, 2 Oct 2024 00:08:08 +0200 Subject: [PATCH] Pre-allocate List from the retrieved Count --- .../Windows/Media/Imaging/BitmapMetadata.cs | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Imaging/BitmapMetadata.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Imaging/BitmapMetadata.cs index 3ac48a36f58..7e501b12286 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Imaging/BitmapMetadata.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Imaging/BitmapMetadata.cs @@ -265,24 +265,16 @@ public int InitializeFromBlockReader( { Invariant.Assert(pIBlockReader != IntPtr.Zero); - int hr = MS.Win32.NativeMethods.S_OK; - - UInt32 count = 0; - Guid guidVendor = new Guid(MILGuidData.GUID_VendorMicrosoft); - List metadataBlocks = new(); - - hr = UnsafeNativeMethods.WICMetadataBlockReader.GetCount( - pIBlockReader, - out count - ); - + int hr = UnsafeNativeMethods.WICMetadataBlockReader.GetCount(pIBlockReader, out UInt32 count); if (HRESULT.Succeeded(hr)) { + List metadataBlocks = new((int)count); + using (FactoryMaker factoryMaker = new FactoryMaker()) { - for (UInt32 i=0; i