Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit bde50b1

Browse files
committed
calculating IsIntEnum is expensive so calculate it
1 parent c68abdd commit bde50b1

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/ServiceStack.OrmLite/Converters/SpecialConverters.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections;
3+
using System.Collections.Concurrent;
34
using System.Collections.Generic;
45
using System.Data;
56
using ServiceStack.DataAnnotations;
@@ -66,11 +67,17 @@ public override object ToDbValue(Type fieldType, object value)
6667
: value.ToString();
6768
}
6869

70+
//cache expensive to calculate operation
71+
static readonly ConcurrentDictionary<Type, bool> intEnums = new ConcurrentDictionary<Type, bool>();
72+
6973
public static bool IsIntEnum(Type fieldType)
7074
{
71-
var isIntEnum = fieldType.IsEnumFlags() ||
72-
fieldType.HasAttribute<EnumAsIntAttribute>() ||
73-
(!fieldType.IsEnum && fieldType.IsNumericType()); //i.e. is real int && not Enum
75+
var isIntEnum = intEnums.GetOrAdd(fieldType, type =>
76+
type.IsEnumFlags() ||
77+
type.HasAttribute<EnumAsIntAttribute>() ||
78+
!type.IsEnum &&
79+
type.IsNumericType()); //i.e. is real int && not Enum)
80+
7481
return isIntEnum;
7582
}
7683

0 commit comments

Comments
 (0)