Skip to content

Commit 782451a

Browse files
libozKevinRansom
authored andcommitted
deferencing only once per function call (#1532)
1 parent 588ab10 commit 782451a

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/fsharp/FSharp.Core/prim-types.fs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5324,12 +5324,13 @@ namespace Microsoft.FSharp.Core
53245324
// is undefined prior to the first call of MoveNext and post called to MoveNext
53255325
// that return false (see https://msdn.microsoft.com/en-us/library/58e146b7%28v=vs.110%29.aspx)
53265326
// so we should be able to just return value here, which would be faster
5327-
if !value < n then
5327+
let derefValue = !value
5328+
if derefValue < n then
53285329
notStarted ()
5329-
elif !value > m then
5330+
elif derefValue > m then
53305331
alreadyFinished ()
53315332
else
5332-
!value
5333+
derefValue
53335334

53345335
{ new IEnumerator<'T> with
53355336
member __.Dispose () = ()
@@ -5339,11 +5340,12 @@ namespace Microsoft.FSharp.Core
53395340
member __.Current = box (current ())
53405341
member __.Reset () = value := n - LanguagePrimitives.GenericOne
53415342
member __.MoveNext () =
5342-
if !value < m then
5343-
value := !value + LanguagePrimitives.GenericOne
5343+
let derefValue = !value
5344+
if derefValue < m then
5345+
value := derefValue + LanguagePrimitives.GenericOne
53445346
true
5345-
elif !value = m then
5346-
value := m + LanguagePrimitives.GenericOne
5347+
elif derefValue = m then
5348+
value := derefValue + LanguagePrimitives.GenericOne
53475349
false
53485350
else false }
53495351

0 commit comments

Comments
 (0)