From 94efe299b9b417a950093fdafb565931dc68cf9e Mon Sep 17 00:00:00 2001 From: Alexander Yumashev <33555768+alex-jitbit@users.noreply.github.com> Date: Mon, 28 Nov 2022 11:06:07 +0200 Subject: [PATCH] Revert "Cache name-hashes in a static var, makes subsequent calls much faster" This reverts commit e11abf25ebf06311472d07fa1affbd1f72a11d1e. --- MapDataReader/MapperGenerator.cs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/MapDataReader/MapperGenerator.cs b/MapDataReader/MapperGenerator.cs index ed90cd3..de38d46 100644 --- a/MapDataReader/MapperGenerator.cs +++ b/MapDataReader/MapperGenerator.cs @@ -70,7 +70,6 @@ private static void SetPropertyByName(this {typeNodeSymbol.FullName()} target, i if (typeNodeSymbol.InstanceConstructors.Any(c => !c.Parameters.Any())) //has a constructor without parameters? { src += $@" - private static int[] _columnNameHashes{typeNode.Identifier} = null; public static List<{typeNodeSymbol.FullName()}> To{typeNode.Identifier}(this IDataReader dr) {{ @@ -78,14 +77,12 @@ private static void SetPropertyByName(this {typeNodeSymbol.FullName()} target, i if (dr.Read()) {{ - if(_columnNameHashes{typeNode.Identifier} == null) - _columnNameHashes{typeNode.Identifier} = Enumerable.Range(0, dr.FieldCount).Select(i => MapperGenerator.GetDeterministicHashCode(dr.GetName(i))).ToArray(); - + int[] columnNameHashes = Enumerable.Range(0, dr.FieldCount).Select(i => MapperGenerator.GetDeterministicHashCode(dr.GetName(i))).ToArray(); do {{ var result = new {typeNodeSymbol.FullName()}(); int i = 0; - foreach (var col in _columnNameHashes{typeNode.Identifier}) + foreach (var col in columnNameHashes) {{ var value = dr[i]; if (value is DBNull) value = null;