@@ -7,6 +7,7 @@ namespace Internal.Utilities.Text.Parsing
77open Internal.Utilities .Text .Lexing
88
99open System
10+ open System.Buffers
1011
1112exception RecoverableParseError
1213exception Accept of obj
@@ -131,11 +132,7 @@ module internal Implementation =
131132 //-------------------------------------------------------------------------
132133 // Read the tables written by FSYACC.
133134
134- type AssocTable ( elemTab : uint16 [], offsetTab : uint16 []) =
135- let cacheSize = 7919 // the 1000'th prime
136- // Use a simpler hash table with faster lookup, but only one
137- // hash bucket per key.
138- let cache = Array.zeroCreate< int> ( cacheSize * 2 )
135+ type AssocTable ( elemTab : uint16 [], offsetTab : uint16 [], cache : int [], cacheSize : int ) =
139136
140137 member t.ReadAssoc ( minElemNum , maxElemNum , defaultValueOfAssoc , keyToFind ) =
141138 // do a binary chop on the table
@@ -234,8 +231,21 @@ module internal Implementation =
234231 let ruleValues = ( Array.zeroCreate 100 : obj[])
235232 let lhsPos = ( Array.zeroCreate 2 : Position[])
236233 let reductions = tables.reductions
237- let actionTable = new AssocTable( tables.actionTableElements, tables.actionTableRowOffsets)
238- let gotoTable = new AssocTable( tables.gotos, tables.sparseGotoTableRowOffsets)
234+ let cacheSize = 7919 // the 1000'th prime
235+ // Use a simpler hash table with faster lookup, but only one
236+ // hash bucket per key.
237+ let actionTableCache = ArrayPool< int>. Shared.Rent( cacheSize * 2 )
238+ let gotoTableCache = ArrayPool< int>. Shared.Rent( cacheSize * 2 )
239+ // Clear the arrays since ArrayPool does not
240+ Array.Clear( actionTableCache, 0 , actionTableCache.Length)
241+ Array.Clear( gotoTableCache, 0 , gotoTableCache.Length)
242+ use _cacheDisposal =
243+ { new IDisposable with
244+ member _.Dispose () =
245+ ArrayPool< int>. Shared.Return actionTableCache
246+ ArrayPool< int>. Shared.Return gotoTableCache }
247+ let actionTable = AssocTable( tables.actionTableElements, tables.actionTableRowOffsets, actionTableCache, cacheSize)
248+ let gotoTable = AssocTable( tables.gotos, tables.sparseGotoTableRowOffsets, gotoTableCache, cacheSize)
239249 let stateToProdIdxsTable = new IdxToIdxListTable( tables.stateToProdIdxsTableElements, tables.stateToProdIdxsTableRowOffsets)
240250
241251 let parseState =
0 commit comments