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

Method objectSet

src/lib/json_buffer.ts:991–1084  ·  view source on GitHub ↗
(target: Pointer, key: string, value: any)

Source from the content-addressed store, hash-verified

989 }
990
991 private objectSet(target: Pointer, key: string, value: any) {
992 this.resolvePtr(target.__ptr);
993 const preScanLen = this.scratchLen;
994 const preScanStart = this.scratchStart;
995
996 for (let i = 0; i < preScanLen; i++) {
997 const entryOffset = preScanStart + i * 12;
998 const keyPtr = this.u32[entryOffset >> 2]!;
999 if (this.readString(keyPtr) === key) {
1000 this.u32[(entryOffset + 4) >> 2] = TYPE_NULL;
1001 this.u32[(entryOffset + 8) >> 2] = 0;
1002 break;
1003 }
1004 }
1005
1006 const valResult = this.writeValue(value);
1007
1008 const valHandle = { __ptr: valResult.payload };
1009 const isValPtr = valResult.type >= TYPE_NUMBER;
1010
1011 if (isValPtr) {
1012 this.tempRoots.push({ handle: valHandle, type: valResult.type });
1013 }
1014
1015 try {
1016 this.resolvePtr(target.__ptr);
1017 let ptr = this.scratchPtr;
1018 const entriesStart = this.scratchStart;
1019 const count = this.scratchLen;
1020 const cap = this.scratchCap;
1021
1022 for (let i = 0; i < count; i++) {
1023 const entryOffset = entriesStart + i * 12;
1024 const keyPtr = this.u32[entryOffset >> 2]!;
1025 if (this.readString(keyPtr) === key) {
1026 this.u32[(entryOffset + 4) >> 2] = valResult.type;
1027 this.u32[(entryOffset + 8) >> 2] = valHandle.__ptr;
1028 return;
1029 }
1030 }
1031
1032 const keyResult = this.writeValue(key);
1033 const keyHandle = { __ptr: keyResult.payload };
1034 this.tempRoots.push({ handle: keyHandle, type: TYPE_STRING });
1035
1036 try {
1037 this.resolvePtr(target.__ptr);
1038 ptr = this.scratchPtr;
1039 const currentCap = this.scratchCap;
1040 const currentCount = this.scratchLen;
1041
1042 if (currentCount >= currentCap) {
1043 const newCap = Math.max(currentCap * 2, 4);
1044 const newByteSize = 12 + newCap * 12;
1045
1046 const newPtr = this.alloc(newByteSize);
1047
1048 this.resolvePtr(target.__ptr);

Callers 3

writeValueMethod · 0.95
writeInitialMethod · 0.95

Calls 4

resolvePtrMethod · 0.95
readStringMethod · 0.95
writeValueMethod · 0.95
allocMethod · 0.95

Tested by

no test coverage detected