@@ -177,9 +177,13 @@ function allocBindingsChunk(prev: i32): i32 {
177177 return ptr ;
178178}
179179
180+ @inline function chunkNext ( chunk : i32 ) : i32 {
181+ return load < i32 > ( < usize > ( chunk + 4 ) ) ;
182+ }
183+
180184// Called when current chunk is full.
181185export function bindingsAdvanceChunk ( ) : void {
182- let next = load < i32 > ( < usize > ( bindingsChunk + 4 ) ) ;
186+ let next = chunkNext ( bindingsChunk ) ;
183187 if ( next === 0 ) {
184188 next = allocBindingsChunk ( bindingsChunk ) ;
185189 }
@@ -207,12 +211,6 @@ export function bindingsAdvanceChunk(): void {
207211 return load < i32 > ( < usize > ( chunk + BINDINGS_CHUNK_HEADER + ( idx << 2 ) ) ) ;
208212}
209213
210- // Write a binding at a specific chunk + index position.
211- @inline function bindingsWrite ( chunk : i32 , idx : i32 , value : i32 ) : void {
212- if ( ! useChunkedBindings ) { unchecked ( bindingsArr [ idx ] = value ) ; return ; }
213- store < i32 > ( < usize > ( chunk + BINDINGS_CHUNK_HEADER + ( idx << 2 ) ) , value ) ;
214- }
215-
216214@inline function memoEntryForFailure ( failureOffset : i32 ) : MemoEntry {
217215 return ( failureOffset << 1 ) | MEMO_FAILURE_FLAG ;
218216}
@@ -366,7 +364,10 @@ export function evalSpacesFull(targetPos: i32): i32 {
366364@inline function restoreBindings ( chunk : i32 , idx : i32 ) : void {
367365 bindingsChunk = chunk ;
368366 bindingsIdx = idx ;
369- if ( ! useChunkedBindings ) bindingsArr . length = idx ;
367+ if ( ! useChunkedBindings ) {
368+ bindingsChunk = 0 ;
369+ bindingsArr . length = idx ;
370+ }
370371}
371372
372373function resetParsingState ( ) : void {
@@ -656,7 +657,7 @@ export function newTerminalNode(startIdx: i32, endIdx: i32): i32 {
656657 store < i32 > ( < usize > ( ptr + CST_NODE_OVERHEAD + i * 4 ) , bindingsRead ( chunk , idx ) ) ;
657658 idx ++ ;
658659 if ( useChunkedBindings && idx === BINDINGS_CHUNK_CAPACITY ) {
659- chunk = load < i32 > ( < usize > ( chunk + 4 ) ) ; // next
660+ chunk = chunkNext ( chunk ) ;
660661 idx = 0 ;
661662 }
662663 }
@@ -702,7 +703,7 @@ export function getBindingsLength(): i32 {
702703 let chunk = bindingsFirstChunk ;
703704 while ( chunk !== bindingsChunk ) {
704705 count += BINDINGS_CHUNK_CAPACITY ;
705- chunk = load < i32 > ( < usize > ( chunk + 4 ) ) ; // next
706+ chunk = chunkNext ( chunk ) ;
706707 }
707708 return count + bindingsIdx ;
708709}
@@ -716,7 +717,7 @@ export function setBindingsLength(len: i32): void {
716717 // Walk from first chunk to find the right chunk+idx.
717718 let chunk = bindingsFirstChunk ;
718719 while ( len >= BINDINGS_CHUNK_CAPACITY ) {
719- chunk = load < i32 > ( < usize > ( chunk + 4 ) ) ; // next
720+ chunk = chunkNext ( chunk ) ;
720721 len -= BINDINGS_CHUNK_CAPACITY ;
721722 }
722723 bindingsChunk = chunk ;
@@ -727,7 +728,7 @@ export function bindingsAt(i: i32): i32 {
727728 if ( ! useChunkedBindings ) return unchecked ( bindingsArr [ i ] ) ;
728729 let chunk = bindingsFirstChunk ;
729730 while ( i >= BINDINGS_CHUNK_CAPACITY ) {
730- chunk = load < i32 > ( < usize > ( chunk + 4 ) ) ; // next
731+ chunk = chunkNext ( chunk ) ;
731732 i -= BINDINGS_CHUNK_CAPACITY ;
732733 }
733734 return bindingsRead ( chunk , i ) ;
0 commit comments