From a6ca6ae1d7b9933d7ad285ee252463d1e25b46f5 Mon Sep 17 00:00:00 2001 From: carlossanlop <1175054+carlossanlop@users.noreply.github.com> Date: Tue, 4 Apr 2023 09:57:23 -0600 Subject: [PATCH] Use enumerator to iterate items in the specified enumeration, and insert them to the lazily created dictionary if they pass the validations. --- .../src/System/Formats/Tar/TarHeader.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarHeader.cs b/src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarHeader.cs index d576d3c850650..13081f2a75933 100644 --- a/src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarHeader.cs +++ b/src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarHeader.cs @@ -113,9 +113,13 @@ internal TarHeader(TarEntryFormat format, TarEntryType typeFlag, TarHeader other internal void InitializeExtendedAttributesWithExisting(IEnumerable> existing) { Debug.Assert(_ea == null); - _ea = new Dictionary(existing); - foreach (KeyValuePair kvp in _ea) + Debug.Assert(existing != null); + + using IEnumerator> enumerator = existing.GetEnumerator(); + while (enumerator.MoveNext()) { + KeyValuePair kvp = enumerator.Current; + int index = kvp.Key.IndexOfAny(new char[] { '=', '\n' }); if (index >= 0) { @@ -125,6 +129,10 @@ internal void InitializeExtendedAttributesWithExisting(IEnumerable(); + + _ea.Add(kvp.Key, kvp.Value); } }