@@ -28,6 +28,8 @@ export interface StringEntryDTO {
2828 readonly value : string ;
2929}
3030
31+ import { allocateBuffer , isSharedBuffer } from 'src/app/store/domain/types' ;
32+
3133/**
3234 * Represents an entry defining a set of field path names.
3335 */
@@ -47,8 +49,8 @@ export interface FieldPathSetEntryDTO {
4749 * This can be transferred to a WebWorker via postMessage.
4850 */
4951export interface InternPoolSharedData {
50- readonly bufferSabs : readonly SharedArrayBuffer [ ] ;
51- readonly metadataSab : SharedArrayBuffer ;
52+ readonly bufferSabs : readonly ( SharedArrayBuffer | ArrayBuffer ) [ ] ;
53+ readonly metadataSab : SharedArrayBuffer | ArrayBuffer ;
5254 readonly capacity : number ;
5355 readonly fieldPathSets : readonly ( readonly number [ ] ) [ ] ;
5456}
@@ -65,7 +67,7 @@ export class InternPoolStore {
6567 /**
6668 * The SharedArrayBuffers backing the encoded string buffers.
6769 */
68- private readonly bufferSabs : SharedArrayBuffer [ ] = [ ] ;
70+ private readonly bufferSabs : ( SharedArrayBuffer | ArrayBuffer ) [ ] = [ ] ;
6971
7072 /**
7173 * Tracks the buffer index for each string ID (1-based index, 0 represents uninitialized).
@@ -85,7 +87,7 @@ export class InternPoolStore {
8587 /**
8688 * The single SharedArrayBuffer holding all metadata arrays.
8789 */
88- private metadataSab : SharedArrayBuffer ;
90+ private metadataSab : SharedArrayBuffer | ArrayBuffer ;
8991
9092 /**
9193 * Whether this store is read-only (for worker-side decoding).
@@ -121,7 +123,7 @@ export class InternPoolStore {
121123 this . readOnly = readOnly ;
122124 if ( typeof initialCapacityOrSharedData === 'number' ) {
123125 const initialCapacity = initialCapacityOrSharedData ;
124- this . metadataSab = new SharedArrayBuffer ( initialCapacity * 10 ) ;
126+ this . metadataSab = allocateBuffer ( initialCapacity * 10 ) ;
125127 this . bufferIndices = new Uint16Array (
126128 this . metadataSab ,
127129 0 ,
@@ -208,7 +210,7 @@ export class InternPoolStore {
208210 this . maxBufferSize - this . currentOffset < encoded . length
209211 ) {
210212 const newSize = Math . max ( this . maxBufferSize , encoded . length ) ;
211- const sab = new SharedArrayBuffer ( newSize ) ;
213+ const sab = allocateBuffer ( newSize ) ;
212214 this . bufferSabs . push ( sab ) ;
213215 this . buffers . push ( new Uint8Array ( sab ) ) ;
214216 this . currentBufferIndex = this . buffers . length - 1 ;
@@ -261,9 +263,12 @@ export class InternPoolStore {
261263
262264 const buffer = this . buffers [ bufferIndex ] ;
263265 const bytes = buffer . subarray ( offset , offset + length ) ;
264- const nonSharedBytes = new Uint8Array ( length ) ;
265- nonSharedBytes . set ( bytes ) ;
266- return this . decoder . decode ( nonSharedBytes ) ;
266+ if ( isSharedBuffer ( bytes . buffer ) ) {
267+ const nonSharedBytes = new Uint8Array ( length ) ;
268+ nonSharedBytes . set ( bytes ) ;
269+ return this . decoder . decode ( nonSharedBytes ) ;
270+ }
271+ return this . decoder . decode ( bytes ) ;
267272 }
268273
269274 /**
@@ -310,7 +315,7 @@ export class InternPoolStore {
310315 newCapacity *= 2 ;
311316 }
312317
313- const newMetadataSab = new SharedArrayBuffer ( newCapacity * 10 ) ;
318+ const newMetadataSab = allocateBuffer ( newCapacity * 10 ) ;
314319 const newBufferIndices = new Uint16Array ( newMetadataSab , 0 , newCapacity ) ;
315320 const newOffsets = new Uint32Array (
316321 newMetadataSab ,
0 commit comments