未验证 提交 6230834b 编写于 作者: P Phillip Carter 提交者: GitHub

Use framework Queue (#7709)

上级 2ce2c9e7
......@@ -4,6 +4,7 @@ namespace Microsoft.FSharp.Control
open System
open System.Threading
open System.Collections.Generic
open Microsoft.FSharp.Core
open Microsoft.FSharp.Core.LanguagePrimitives.IntrinsicOperators
open Microsoft.FSharp.Control
......@@ -11,48 +12,6 @@ namespace Microsoft.FSharp.Control
open Microsoft.FSharp.Control.AsyncPrimitives
open Microsoft.FSharp.Collections
/// We use our own internal implementation of queues to avoid a dependency on System.dll
type Queue<'T>() =
let mutable array = [| |]
let mutable head = 0
let mutable size = 0
let mutable tail = 0
let SetCapacity capacity =
let destinationArray = Array.zeroCreate capacity
if (size > 0) then
if (head < tail) then
Array.Copy(array, head, destinationArray, 0, size)
else
Array.Copy(array, head, destinationArray, 0, array.Length - head)
Array.Copy(array, 0, destinationArray, array.Length - head, tail)
array <- destinationArray
head <- 0
tail <- if (size = capacity) then 0 else size
member x.Dequeue() =
if (size = 0) then
failwith "Dequeue"
let local = array.[head]
array.[head] <- Unchecked.defaultof<'T>
head <- (head + 1) % array.Length
size <- size - 1
local
member this.Enqueue item =
if (size = array.Length) then
let capacity = int ((int64 array.Length * 200L) / 100L)
let capacity = max capacity (array.Length + 4)
SetCapacity capacity
array.[tail] <- item
tail <- (tail + 1) % array.Length
size <- size + 1
member x.Count = size
module AsyncHelpers =
let awaitEither a1 a2 =
......@@ -93,7 +52,7 @@ namespace Microsoft.FSharp.Control
[<AutoSerializable(false)>]
type Mailbox<'Msg>(cancellationSupported: bool) =
let mutable inboxStore = null
let mutable arrivals = new Queue<'Msg>()
let arrivals = Queue<'Msg>()
let syncRoot = arrivals
// Control elements indicating the state of the reader. When the reader is "blocked" at an
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册