Skip to content

Commit 3c1c078

Browse files
elliotttJakeChampion
authored andcommitted
Remove an unused version of read_from_handle_all
1 parent 5440d93 commit 3c1c078

File tree

1 file changed

+0
-61
lines changed

1 file changed

+0
-61
lines changed

c-dependencies/js-compute-runtime/js-compute-builtins.cpp

-61
Original file line numberDiff line numberDiff line change
@@ -271,67 +271,6 @@ static char *read_from_handle_all(JSContext *cx, uint32_t handle, size_t *nwritt
271271
return buf;
272272
}
273273

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-
335274
/**
336275
* Writes the given number of bytes from the given buffer to the given handle.
337276
*

0 commit comments

Comments
 (0)