Skip to content

Commit f7b3435

Browse files
committed
minor optimizations
1 parent 0d8fde2 commit f7b3435

2 files changed

Lines changed: 18 additions & 4 deletions

File tree

src/SQLProvider.Common/SqlRuntime.Common.fs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,11 @@ type SqlEntity(dc: ISqlDataContext, tableName, columns: ColumnLookup, activeColu
363363
for prop in fields do
364364
match dataMap.TryGetValue(clean prop) with
365365
| true, null when prop.PropertyType.Name.StartsWith "FSharpValueOption" ->
366+
#if NETSTANDARD21
367+
let typedNone = System.Runtime.CompilerServices.RuntimeHelpers.GetUninitializedObject prop.PropertyType
368+
#else
366369
let typedNone = FormatterServices.GetUninitializedObject prop.PropertyType
370+
#endif
367371
yield propertyTypeMapping (prop.Name, typedNone)
368372
| true, dataVal -> yield propertyTypeMapping (prop.Name, (Utilities.convertTypes dataVal prop.PropertyType))
369373
| false, _ -> ()
@@ -374,7 +378,11 @@ type SqlEntity(dc: ISqlDataContext, tableName, columns: ColumnLookup, activeColu
374378
for prop in typ.GetProperties() do
375379
match dataMap.TryGetValue(clean prop) with
376380
| true, null when prop.PropertyType.Name.StartsWith "FSharpValueOption" ->
381+
#if NETSTANDARD21
382+
let typedNone = System.Runtime.CompilerServices.RuntimeHelpers.GetUninitializedObject prop.PropertyType
383+
#else
377384
let typedNone = FormatterServices.GetUninitializedObject prop.PropertyType
385+
#endif
378386
prop.GetSetMethod().Invoke(instance, [|propertyTypeMapping (prop.Name, typedNone)|]) |> ignore
379387
| true, dataVal -> prop.GetSetMethod().Invoke(instance, [|propertyTypeMapping (prop.Name, (Utilities.convertTypes dataVal prop.PropertyType))|]) |> ignore
380388
| false, _ -> ()

src/SQLProvider.Common/SqlRuntime.Patterns.fs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,17 +105,23 @@ let (|SeqValues|_|) (e:Expression) =
105105

106106
// Working with untyped IEnumerable so need to do a lot manually instead of using Seq
107107
// Work out the size the sequence
108-
let mutable count = 0
109-
for obj in values do
110-
count <- count + 1
108+
109+
let count =
110+
match values with
111+
| :? System.Collections.ICollection as ic -> ic.Count
112+
| _ ->
113+
let mutable count = 0
114+
for obj in values do
115+
count <- count + 1
116+
count
111117
// Create and populate the array
112118
let array = Array.CreateInstance(typeof<System.Object>, count)
113119
let mutable i = 0
114120
for obj in values do
115121
array.SetValue(obj, i)
116122
i <- i + 1
117123
// Return the array
118-
Some(array)
124+
Some array
119125

120126

121127
let (|PropertyGet|_|) (e:Expression) =

0 commit comments

Comments
 (0)