Skip to content

Commit 7224954

Browse files
committed
Avoided boxing/unboxing for common types in Int32Type
and use the previous implementation as a fallback for the rest types
1 parent 34b156b commit 7224954

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

src/NHibernate/Type/Int32Type.cs

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,33 @@ public override object Get(DbDataReader rs, int index, ISessionImplementor sessi
3333
{
3434
try
3535
{
36-
return rs[index] switch
36+
int value;
37+
38+
var fieldType = rs.GetFieldType(index);
39+
if (fieldType == typeof(int))
40+
{
41+
value = rs.GetInt32(index);
42+
}
43+
else if (fieldType == typeof(long))
44+
{
45+
value = Convert.ToInt32(rs.GetInt64(index));
46+
}
47+
else if (fieldType == typeof(decimal))
48+
{
49+
value = Convert.ToInt32(rs.GetDecimal(index));
50+
}
51+
else
3752
{
38-
BigInteger bi => (int) bi,
39-
var c => Convert.ToInt32(c)
40-
};
53+
// anything else we haven't thought of goes through boxing
54+
value = rs[index] switch
55+
{
56+
// BigInteger does not implement IConvertible, but implements explicit conversion
57+
BigInteger bi => (int) bi,
58+
var c => Convert.ToInt32(c)
59+
};
60+
}
61+
62+
return value;
4163
}
4264
catch (Exception ex)
4365
{

0 commit comments

Comments
 (0)