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

Method next

src/lib/json_buffer.ts:1517–1549  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1515 }
1516
1517 next(): IteratorResult<any> {
1518 // Bounds check
1519 if (this.index >= this.len) {
1520 return { done: true, value: undefined };
1521 }
1522
1523 // Optimization 2: Bitwise shift for *8.
1524 // Calculate offset: start + (index * 8)
1525 const offset = this.start + (this.index++ << 3);
1526
1527 // Direct memory read
1528 const type = this.u32[offset >> 2]!;
1529
1530 // Optimization 3: Inline Primitive Handling (Zero Allocation Path)
1531 // TYPE_NUMBER (3) is the most common primitive, check it first.
1532 if (type === 3) {
1533 const payload = this.u32[(offset + 4) >> 2]!;
1534 return { done: false, value: this.f64[payload >> 3] };
1535 }
1536
1537 // TYPE_NULL (0), TYPE_TRUE (1), TYPE_FALSE (2)
1538 if (type <= 2) {
1539 // Nested ternary is faster than switch for 3 values
1540 const val = type === 1 ? true : (type === 2 ? false : null);
1541 return { done: false, value: val };
1542 }
1543
1544 // Fallback: Objects (5, 6) & Strings (4)
1545 // We MUST delegate to readSlot here to get the correct Proxy or String.
1546 // This maintains correctness (distinct objects) while isolating the cost
1547 // only to complex types.
1548 return { done: false, value: this.buffer.readSlot(offset) };
1549 }
1550}
1551
1552export const SharedJsonBuffer = SharedJsonBufferImpl as {

Callers

nothing calls this directly

Calls 1

readSlotMethod · 0.80

Tested by

no test coverage detected