Skip to content

Commit bbeb9c7

Browse files
committed
Optimized DBNull -> CLR null process
1 parent b4d352a commit bbeb9c7

File tree

3 files changed

+8
-29
lines changed

3 files changed

+8
-29
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ test-results
1919
apply_config.bat
2020
NDependOut
2121
*.dotCover
22+
*_mm_cache.bin

Simple.Data.Ado/DataReaderExtensions.cs

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
namespace Simple.Data.Ado
77
{
8+
using System;
9+
810
public static class DataReaderExtensions
911
{
1012
public static IDictionary<string,object> ToDictionary(this IDataReader dataReader)
@@ -45,43 +47,19 @@ private static IEnumerable<IDictionary<string,object>> ToDictionariesImpl(IDataR
4547
{
4648
reader.GetValues(values);
4749

48-
for (var i = 0; i < reader.FieldCount; i++)
49-
{
50-
var value = values[i];
51-
if (value is DBNull)
52-
values[i] = null;
53-
}
50+
ReplaceDbNullsWithClrNulls(values);
5451

5552
yield return OptimizedDictionary.Create(index, values);
5653
}
5754
}
5855

59-
public static IEnumerable<object> ToDynamicList(this IDataReader reader)
60-
{
61-
var list = new List<object>();
62-
using (reader)
63-
{
64-
while (reader.Read())
65-
{
66-
list.Add(reader.ToDynamicRecord());
67-
}
68-
}
69-
70-
return list.AsEnumerable();
71-
}
72-
73-
public static IEnumerable<object> ToDynamicList(this IDataReader reader, Database database, string tableName)
56+
private static void ReplaceDbNullsWithClrNulls(object[] values)
7457
{
75-
var list = new List<object>();
76-
using (reader)
58+
int dbNullIndex;
59+
while ((dbNullIndex = Array.IndexOf(values, DBNull.Value)) > -1)
7760
{
78-
while (reader.Read())
79-
{
80-
list.Add(reader.ToDynamicRecord(tableName, database));
81-
}
61+
values[dbNullIndex] = null;
8262
}
83-
84-
return list.AsEnumerable();
8563
}
8664
}
8765
}

Simple.Data_mm_cache.bin

-30.8 MB
Binary file not shown.

0 commit comments

Comments
 (0)