MCPcopy Create free account
hub / github.com/apitable/apitable / passStringToWasm0

Function passStringToWasm0

packages/databus-wasm-nodejs/databus_wasm.js:74–110  ·  view source on GitHub ↗
(arg, malloc, realloc)

Source from the content-addressed store, hash-verified

72});
73
74function passStringToWasm0(arg, malloc, realloc) {
75
76 if (realloc === undefined) {
77 const buf = cachedTextEncoder.encode(arg);
78 const ptr = malloc(buf.length, 1) >>> 0;
79 getUint8Memory0().subarray(ptr, ptr + buf.length).set(buf);
80 WASM_VECTOR_LEN = buf.length;
81 return ptr;
82 }
83
84 let len = arg.length;
85 let ptr = malloc(len, 1) >>> 0;
86
87 const mem = getUint8Memory0();
88
89 let offset = 0;
90
91 for (; offset < len; offset++) {
92 const code = arg.charCodeAt(offset);
93 if (code > 0x7F) break;
94 mem[ptr + offset] = code;
95 }
96
97 if (offset !== len) {
98 if (offset !== 0) {
99 arg = arg.slice(offset);
100 }
101 ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
102 const view = getUint8Memory0().subarray(ptr + offset, ptr + len);
103 const ret = encodeString(arg, view);
104
105 offset += ret.written;
106 }
107
108 WASM_VECTOR_LEN = offset;
109 return ptr;
110}
111
112let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
113

Callers 3

databus_wasm.jsFile · 0.70
constructorMethod · 0.70
get_datasheet_packMethod · 0.70

Calls 3

getUint8Memory0Function · 0.70
encodeMethod · 0.65
setMethod · 0.65

Tested by

no test coverage detected