MCPcopy Create free account
hub / github.com/W4G1/multithreading / initializeBuffer

Method initializeBuffer

src/lib/json_buffer.ts:156–183  ·  view source on GitHub ↗
(obj: T)

Source from the content-addressed store, hash-verified

154 }
155
156 private initializeBuffer(obj: T) {
157 Atomics.store(this.u32, OFFSET_FREE_PTR >> 2, HEADER_SIZE);
158
159 const isArr = Array.isArray(obj);
160 const initialKeys = isArr
161 ? obj.length
162 : (obj ? Object.keys(obj).length : 0);
163
164 const rootPtr = isArr
165 ? this.allocArray(initialKeys)
166 : this.allocObject(initialKeys);
167
168 Atomics.store(this.u32, OFFSET_ROOT >> 2, rootPtr);
169
170 if (obj) {
171 const rootTarget = { __ptr: rootPtr };
172 this.tempRoots.push({
173 handle: rootTarget,
174 type: isArr ? TYPE_ARRAY : TYPE_OBJECT,
175 });
176 try {
177 this.writeInitial(rootTarget, obj);
178 } finally {
179 this.tempRoots.pop();
180 Atomics.store(this.u32, OFFSET_ROOT >> 2, rootTarget.__ptr);
181 }
182 }
183 }
184
185 private getRootProxy(): any {
186 const rootPtr = Atomics.load(this.u32, OFFSET_ROOT >> 2);

Callers 1

constructorMethod · 0.95

Calls 3

allocArrayMethod · 0.95
allocObjectMethod · 0.95
writeInitialMethod · 0.95

Tested by

no test coverage detected