@@ -271,67 +271,6 @@ static char *read_from_handle_all(JSContext *cx, uint32_t handle, size_t *nwritt
271
271
return buf;
272
272
}
273
273
274
- template <auto op, class HandleType >
275
- static char *read_from_handle_all (JSContext *cx, HandleType handle, size_t *nwritten,
276
- bool read_until_zero) {
277
- // TODO(performance): investigate passing a size hint in situations where we might know
278
- // the final size, e.g. via the `content-length` header.
279
- // https://github.com/fastly/js-compute-runtime/issues/216
280
- size_t buf_size = HANDLE_READ_CHUNK_SIZE;
281
- // TODO(performance): make use of malloc slack.
282
- // https://github.com/fastly/js-compute-runtime/issues/217
283
- char *buf = static_cast <char *>(JS_malloc (cx, buf_size));
284
- if (!buf) {
285
- JS_ReportOutOfMemory (cx);
286
- return nullptr ;
287
- }
288
-
289
- // For realloc below.
290
- char *new_buf;
291
-
292
- size_t offset = 0 ;
293
- fastly_error_t err;
294
- while (true ) {
295
- size_t num_written = 0 ;
296
- if (!op (handle, buf + offset, HANDLE_READ_CHUNK_SIZE, &num_written, &err)) {
297
- HANDLE_ERROR (cx, err);
298
- JS_free (cx, buf);
299
- return nullptr ;
300
- }
301
-
302
- offset += num_written;
303
- if (num_written == 0 || (!read_until_zero && num_written < HANDLE_READ_CHUNK_SIZE)) {
304
- break ;
305
- }
306
-
307
- // TODO(performance): make use of malloc slack, and use a smarter buffer growth strategy.
308
- // https://github.com/fastly/js-compute-runtime/issues/217
309
- size_t new_size = buf_size + HANDLE_READ_CHUNK_SIZE;
310
- new_buf = static_cast <char *>(JS_realloc (cx, buf, buf_size, new_size));
311
- if (!new_buf) {
312
- JS_free (cx, buf);
313
- JS_ReportOutOfMemory (cx);
314
- return nullptr ;
315
- }
316
- buf = new_buf;
317
-
318
- buf_size += HANDLE_READ_CHUNK_SIZE;
319
- }
320
-
321
- new_buf = static_cast <char *>(JS_realloc (cx, buf, buf_size, offset + 1 ));
322
- if (!buf) {
323
- JS_free (cx, buf);
324
- JS_ReportOutOfMemory (cx);
325
- return nullptr ;
326
- }
327
- buf = new_buf;
328
-
329
- buf[offset] = ' \0 ' ;
330
- *nwritten = offset;
331
-
332
- return buf;
333
- }
334
-
335
274
/* *
336
275
* Writes the given number of bytes from the given buffer to the given handle.
337
276
*
0 commit comments