mol_vary 0.0.263 → 0.0.265

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/node.mjs CHANGED
@@ -173,6 +173,13 @@ var $;
173
173
  let text = '';
174
174
  let pos = 0;
175
175
  let page_offset = 0;
176
+ /** Char by char concatenation builds a rope with ~32 bytes per char, kept until flattened. */
177
+ const codes = [];
178
+ const flush = () => {
179
+ text += String.fromCodePoint(...codes);
180
+ codes.length = 0;
181
+ return text;
182
+ };
176
183
  const read_code = () => {
177
184
  let code = buffer[pos++];
178
185
  if (code >= 0x80)
@@ -184,7 +191,7 @@ var $;
184
191
  if (code >= 0x80)
185
192
  code = ascii_set[code - 0x80];
186
193
  if (code === undefined)
187
- $mol_fail(new Error('Wrong byte', { cause: { text, pos: pos - 1 } }));
194
+ $mol_fail(new Error('Wrong byte', { cause: { text: flush(), pos: pos - 1 } }));
188
195
  return code;
189
196
  };
190
197
  while (pos < buffer.length) {
@@ -200,17 +207,19 @@ var $;
200
207
  code = ascii_set[code - 0x80];
201
208
  if (mode < tiny_mode) {
202
209
  if (pos === buffer.length)
203
- $mol_fail(new Error('Expected 2 bytes', { cause: { text, pos: pos - 1 } }));
210
+ $mol_fail(new Error('Expected 2 bytes', { cause: { text: flush(), pos: pos - 1 } }));
204
211
  code |= read_remap() << 7;
205
212
  }
206
213
  if (mode === full_mode) {
207
214
  if (pos === buffer.length)
208
- $mol_fail(new Error('Expected 3 bytes', { cause: { text, pos: pos - 2 } }));
215
+ $mol_fail(new Error('Expected 3 bytes', { cause: { text: flush(), pos: pos - 2 } }));
209
216
  code |= read_remap() << 14;
210
217
  }
211
218
  code += page_offset;
212
219
  }
213
- text += String.fromCodePoint(code);
220
+ codes.push(code);
221
+ if (codes.length === 1024)
222
+ flush();
214
223
  }
215
224
  else if (code >= tiny_mode) { // Tiny Set
216
225
  mode = code;
@@ -226,9 +235,9 @@ var $;
226
235
  }
227
236
  }
228
237
  if (mode !== tiny_mode) {
229
- return $mol_fail(new Error('Wrong ending', { cause: { text, mode } }));
238
+ return $mol_fail(new Error('Wrong ending', { cause: { text: flush(), mode } }));
230
239
  }
231
- return text;
240
+ return flush();
232
241
  }
233
242
  $.$mol_charset_ucf_decode = $mol_charset_ucf_decode;
234
243
  })($ || ($ = {}));
package/node.test.js CHANGED
@@ -164,6 +164,13 @@ var $;
164
164
  let text = '';
165
165
  let pos = 0;
166
166
  let page_offset = 0;
167
+ /** Char by char concatenation builds a rope with ~32 bytes per char, kept until flattened. */
168
+ const codes = [];
169
+ const flush = () => {
170
+ text += String.fromCodePoint(...codes);
171
+ codes.length = 0;
172
+ return text;
173
+ };
167
174
  const read_code = () => {
168
175
  let code = buffer[pos++];
169
176
  if (code >= 0x80)
@@ -175,7 +182,7 @@ var $;
175
182
  if (code >= 0x80)
176
183
  code = ascii_set[code - 0x80];
177
184
  if (code === undefined)
178
- $mol_fail(new Error('Wrong byte', { cause: { text, pos: pos - 1 } }));
185
+ $mol_fail(new Error('Wrong byte', { cause: { text: flush(), pos: pos - 1 } }));
179
186
  return code;
180
187
  };
181
188
  while (pos < buffer.length) {
@@ -191,17 +198,19 @@ var $;
191
198
  code = ascii_set[code - 0x80];
192
199
  if (mode < tiny_mode) {
193
200
  if (pos === buffer.length)
194
- $mol_fail(new Error('Expected 2 bytes', { cause: { text, pos: pos - 1 } }));
201
+ $mol_fail(new Error('Expected 2 bytes', { cause: { text: flush(), pos: pos - 1 } }));
195
202
  code |= read_remap() << 7;
196
203
  }
197
204
  if (mode === full_mode) {
198
205
  if (pos === buffer.length)
199
- $mol_fail(new Error('Expected 3 bytes', { cause: { text, pos: pos - 2 } }));
206
+ $mol_fail(new Error('Expected 3 bytes', { cause: { text: flush(), pos: pos - 2 } }));
200
207
  code |= read_remap() << 14;
201
208
  }
202
209
  code += page_offset;
203
210
  }
204
- text += String.fromCodePoint(code);
211
+ codes.push(code);
212
+ if (codes.length === 1024)
213
+ flush();
205
214
  }
206
215
  else if (code >= tiny_mode) { // Tiny Set
207
216
  mode = code;
@@ -217,9 +226,9 @@ var $;
217
226
  }
218
227
  }
219
228
  if (mode !== tiny_mode) {
220
- return $mol_fail(new Error('Wrong ending', { cause: { text, mode } }));
229
+ return $mol_fail(new Error('Wrong ending', { cause: { text: flush(), mode } }));
221
230
  }
222
- return text;
231
+ return flush();
223
232
  }
224
233
  $.$mol_charset_ucf_decode = $mol_charset_ucf_decode;
225
234
  })($ || ($ = {}));