Skip to content

Commit

Permalink
src: make util.h self-containted
Browse files Browse the repository at this point in the history
Before it depended on util-inl.h. Fix it by moving
MaybeStackBuffer::AllocateSufficientStorage() into
util-inl.h

PR-URL: #46817
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
  • Loading branch information
joyeecheung authored and targos committed Mar 13, 2023
1 parent e994fd4 commit 12bf114
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
16 changes: 16 additions & 0 deletions src/util-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,22 @@ SlicedArguments::SlicedArguments(
(*this)[i] = args[i + start];
}

template <typename T, size_t kStackStorageSize>
void MaybeStackBuffer<T, kStackStorageSize>::AllocateSufficientStorage(
size_t storage) {
CHECK(!IsInvalidated());
if (storage > capacity()) {
bool was_allocated = IsAllocated();
T* allocated_ptr = was_allocated ? buf_ : nullptr;
buf_ = Realloc(allocated_ptr, storage);
capacity_ = storage;
if (!was_allocated && length_ > 0)
memcpy(buf_, buf_st_, length_ * sizeof(buf_[0]));
}

length_ = storage;
}

template <typename T, size_t S>
ArrayBufferViewContents<T, S>::ArrayBufferViewContents(
v8::Local<v8::Value> value) {
Expand Down
14 changes: 1 addition & 13 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -412,19 +412,7 @@ class MaybeStackBuffer {
// This method can be called multiple times throughout the lifetime of the
// buffer, but once this has been called Invalidate() cannot be used.
// Content of the buffer in the range [0, length()) is preserved.
void AllocateSufficientStorage(size_t storage) {
CHECK(!IsInvalidated());
if (storage > capacity()) {
bool was_allocated = IsAllocated();
T* allocated_ptr = was_allocated ? buf_ : nullptr;
buf_ = Realloc(allocated_ptr, storage);
capacity_ = storage;
if (!was_allocated && length_ > 0)
memcpy(buf_, buf_st_, length_ * sizeof(buf_[0]));
}

length_ = storage;
}
void AllocateSufficientStorage(size_t storage);

void SetLength(size_t length) {
// capacity() returns how much memory is actually available.
Expand Down

0 comments on commit 12bf114

Please sign in to comment.