@@ -233,6 +233,9 @@ class ByteSource {
233233 // Returns the (allocated) size in bytes.
234234 size_t size () const { return size_; }
235235
236+ // Returns if (allocated) size is zero.
237+ bool empty () const { return size_ == 0 ; }
238+
236239 // Finalizes the Builder and returns a read-only view that is optionally
237240 // truncated.
238241 ByteSource release (std::optional<size_t > resize = std::nullopt ) && {
@@ -271,6 +274,8 @@ class ByteSource {
271274
272275 size_t size () const { return size_; }
273276
277+ bool empty () const { return size_ == 0 ; }
278+
274279 operator bool () const { return data_ != nullptr ; }
275280
276281 BignumPointer ToBN () const {
@@ -718,22 +723,22 @@ class ArrayBufferOrViewContents {
718723 // Ideally, these would return nullptr if IsEmpty() or length_ is zero,
719724 // but some of the openssl API react badly if given a nullptr even when
720725 // length is zero, so we have to return something.
721- if (size () == 0 )
722- return &buf;
726+ if (empty ()) return &buf;
723727 return reinterpret_cast <T*>(data_) + offset_;
724728 }
725729
726730 inline T* data () {
727731 // Ideally, these would return nullptr if IsEmpty() or length_ is zero,
728732 // but some of the openssl API react badly if given a nullptr even when
729733 // length is zero, so we have to return something.
730- if (size () == 0 )
731- return &buf;
734+ if (empty ()) return &buf;
732735 return reinterpret_cast <T*>(data_) + offset_;
733736 }
734737
735738 inline size_t size () const { return length_; }
736739
740+ inline bool empty () const { return length_ == 0 ; }
741+
737742 // In most cases, input buffer sizes passed in to openssl need to
738743 // be limited to <= INT_MAX. This utility method helps us check.
739744 inline bool CheckSizeInt32 () { return size () <= INT_MAX; }
@@ -743,14 +748,14 @@ class ArrayBufferOrViewContents {
743748 }
744749
745750 inline ByteSource ToCopy () const {
746- if (size () == 0 ) return ByteSource ();
751+ if (empty () ) return ByteSource ();
747752 ByteSource::Builder buf (size ());
748753 memcpy (buf.data <void >(), data (), size ());
749754 return std::move (buf).release ();
750755 }
751756
752757 inline ByteSource ToNullTerminatedCopy () const {
753- if (size () == 0 ) return ByteSource ();
758+ if (empty () ) return ByteSource ();
754759 ByteSource::Builder buf (size () + 1 );
755760 memcpy (buf.data <void >(), data (), size ());
756761 buf.data <char >()[size ()] = 0 ;
0 commit comments