Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 36.4k
src: refactor grow_async_ids_stack#23808
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -4,7 +4,7 @@ | ||
| #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS | ||
| #include "v8.h" | ||
| #include "util-inl.h" | ||
| #include "util.h" | ||
| namespace node { | ||
| @@ -22,7 +22,9 @@ namespace node { | ||
| * The encapsulation herein provides a placeholder where such writes can be | ||
| * observed. Any notification APIs will be left as a future exercise. | ||
| */ | ||
| template <class NativeT, class V8T> | ||
| template <class NativeT, class V8T, | ||
| // SFINAE NativeT to be scalar | ||
| typename = std::enable_if_t<std::is_scalar<NativeT>::value>> | ||
| class AliasedBuffer { | ||
| public: | ||
| AliasedBuffer(v8::Isolate* isolate, const size_t count) | ||
| @@ -33,14 +35,14 @@ class AliasedBuffer { | ||
| CHECK_GT(count, 0); | ||
| const v8::HandleScope handle_scope(isolate_); | ||
| const size_t sizeInBytes = sizeof(NativeT) * count; | ||
| const size_t size_in_bytes = sizeof(NativeT) * count; | ||
| // allocate native buffer | ||
| buffer_ = Calloc<NativeT>(count); | ||
| // allocate v8 ArrayBuffer | ||
| v8::Local<v8::ArrayBuffer> ab = v8::ArrayBuffer::New( | ||
| isolate_, buffer_, sizeInBytes); | ||
| isolate_, buffer_, size_in_bytes); | ||
| // allocate v8 TypedArray | ||
| v8::Local<V8T> js_array = V8T::New(ab, byte_offset_, count); | ||
| @@ -55,6 +57,7 @@ class AliasedBuffer { | ||
| * | ||
| * Note that byte_offset must by aligned by sizeof(NativeT). | ||
| */ | ||
| // TODO(refack): refactor into a non-owning `AliasedBufferView` | ||
| AliasedBuffer(v8::Isolate* isolate, | ||
| const size_t byte_offset, | ||
| const size_t count, | ||
| @@ -96,7 +99,7 @@ class AliasedBuffer { | ||
| js_array_.Reset(); | ||
| } | ||
| AliasedBuffer& operator=(AliasedBuffer&& that) { | ||
| AliasedBuffer& operator=(AliasedBuffer&& that) noexcept { | ||
| this->~AliasedBuffer(); | ||
| isolate_ = that.isolate_; | ||
| count_ = that.count_; | ||
| @@ -226,6 +229,41 @@ class AliasedBuffer { | ||
| return count_; | ||
| } | ||
| // Should only be used to extend the array. | ||
| // Should only be used on an owning array, not one created as a sub array of | ||
| // an owning `AliasedBuffer`. | ||
| void reserve(size_t new_capacity) { | ||
| #if defined(DEBUG) && DEBUG | ||
| CHECK_GE(new_capacity, count_); | ||
| CHECK_EQ(byte_offset_, 0); | ||
refack marked this conversation as resolved.
Outdated
Uh oh!There was an error while loading. Please reload this page. | ||
| CHECK(free_buffer_); | ||
| #endif | ||
| const v8::HandleScope handle_scope(isolate_); | ||
| const size_t old_size_in_bytes = sizeof(NativeT) * count_; | ||
| const size_t new_size_in_bytes = sizeof(NativeT) * new_capacity; | ||
| // allocate new native buffer | ||
| NativeT* new_buffer = Calloc<NativeT>(new_capacity); | ||
| // copy old content | ||
| memcpy(new_buffer, buffer_, old_size_in_bytes); | ||
| // allocate v8 new ArrayBuffer | ||
| v8::Local<v8::ArrayBuffer> ab = v8::ArrayBuffer::New( | ||
| isolate_, new_buffer, new_size_in_bytes); | ||
| // allocate v8 TypedArray | ||
| v8::Local<V8T> js_array = V8T::New(ab, byte_offset_, new_capacity); | ||
| // move over old v8 TypedArray | ||
| js_array_ = std::move(v8::Global<V8T>(isolate_, js_array)); | ||
| // Free old buffer and set new values | ||
| free(buffer_); | ||
| buffer_ = new_buffer; | ||
| count_ = new_capacity; | ||
| } | ||
| private: | ||
| v8::Isolate* isolate_; | ||
| size_t count_; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -5,6 +5,7 @@ | ||
| #include <functional> | ||
| #include <unicode/unistr.h> | ||
| #include "util-inl.h" | ||
| namespace node { | ||
| namespace inspector { | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.