MCPcopy Create free account
hub / github.com/btd/rollup-plugin-visualizer / writeStrings

Function writeStrings

shared/share/codec.ts:107–133  ·  view source on GitHub ↗
(writer: Writer, strings: readonly string[])

Source from the content-addressed store, hash-verified

105};
106
107const writeStrings = (writer: Writer, strings: readonly string[]): void => {
108 const lengths: number[] = [],
109 suffixes: string[] = [];
110 let previous = "";
111 for (const value of strings) {
112 let prefix = 0,
113 offset = 0,
114 prefixBytes = 0;
115 while (
116 offset < previous.length &&
117 offset < value.length &&
118 previous.codePointAt(offset) === value.codePointAt(offset)
119 ) {
120 const point = value.codePointAt(offset)!;
121 prefixBytes += point < 128 ? 1 : point < 2048 ? 2 : point < 65536 ? 3 : 4;
122 offset += point > 65535 ? 2 : 1;
123 prefix++;
124 }
125 writer.accountText(prefixBytes);
126 lengths.push(prefix);
127 suffixes.push(value.slice(offset));
128 previous = value;
129 }
130 writer.uint(strings.length);
131 writer.vector(lengths);
132 for (const suffix of suffixes) writer.text(suffix);
133};
134
135const readStrings = (reader: Reader): string[] => {
136 const count = reader.count(reader.limits.maxEntries),

Callers 1

encodeReportFunction · 0.85

Calls 4

accountTextMethod · 0.45
uintMethod · 0.45
vectorMethod · 0.45
textMethod · 0.45

Tested by

no test coverage detected