From 339b52f3bcf42996470db1ce74193046d66f1a9a Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Fri, 24 Feb 2023 15:25:10 +0100 Subject: [PATCH] src: make util.h self-containted Before it depended on util-inl.h. Fix it by moving MaybeStackBuffer::AllocateSufficientStorage() into util-inl.h PR-URL: https://github.com/nodejs/node/pull/46817 Reviewed-By: Anna Henningsen Reviewed-By: Matteo Collina --- src/util-inl.h | 16 ++++++++++++++++ src/util.h | 14 +------------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/util-inl.h b/src/util-inl.h index 833082291a16aa..864f6d86cdf689 100644 --- a/src/util-inl.h +++ b/src/util-inl.h @@ -510,6 +510,22 @@ SlicedArguments::SlicedArguments( (*this)[i] = args[i + start]; } +template +void MaybeStackBuffer::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 ArrayBufferViewContents::ArrayBufferViewContents( v8::Local value) { diff --git a/src/util.h b/src/util.h index 96415fccc20a35..9bdd00bb834a2b 100644 --- a/src/util.h +++ b/src/util.h @@ -411,19 +411,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.