mirror of
https://github.com/nodejs/node.git
synced 2026-11-09 15:11:11 -05:00
src: allocate Buffer memory using ArrayBuffer allocator
Always use the right allocator for memory that is turned into an `ArrayBuffer` at a later point. This enables embedders to use their own `ArrayBuffer::Allocator`s, and is inspired by Electron’s electron/node@f61bae3440. It should render their downstream patch unnecessary. Refs: https://github.com/electron/node/commit/f61bae3440e1bfcc83bba6ff0785adfb89b4045e PR-URL: https://github.com/nodejs/node/pull/26207 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
This commit is contained in:
16 files changed
+254
-317
No files matched your search
@@ -594,10 +594,9 @@ class Parser : public AsyncWrap, public StreamListener {
|
||||
uv_buf_t OnStreamAlloc(size_t suggested_size) override {
|
||||
// For most types of streams, OnStreamRead will be immediately after
|
||||
// OnStreamAlloc, and will consume all data, so using a static buffer for
|
||||
// reading is more efficient. For other streams, just use the default
|
||||
// allocator, which uses Malloc().
|
||||
// reading is more efficient. For other streams, just use Malloc() directly.
|
||||
if (env()->http_parser_buffer_in_use())
|
||||
return StreamListener::OnStreamAlloc(suggested_size);
|
||||
return uv_buf_init(Malloc(suggested_size), suggested_size);
|
||||
env()->set_http_parser_buffer_in_use(true);
|
||||
|
||||
if (env()->http_parser_buffer() == nullptr)
|
||||
|
||||
Reference in new issue
Block a user