@@ -233,6 +233,9 @@ class ByteSource {
233
233
// Returns the (allocated) size in bytes.
234
234
size_t size () const { return size_; }
235
235
236
+ // Returns if (allocated) size is zero.
237
+ bool empty () const { return size_ == 0 ; }
238
+
236
239
// Finalizes the Builder and returns a read-only view that is optionally
237
240
// truncated.
238
241
ByteSource release (std::optional<size_t > resize = std::nullopt) && {
@@ -271,6 +274,8 @@ class ByteSource {
271
274
272
275
size_t size () const { return size_; }
273
276
277
+ bool empty () const { return size_ == 0 ; }
278
+
274
279
operator bool () const { return data_ != nullptr ; }
275
280
276
281
BignumPointer ToBN () const {
@@ -718,22 +723,22 @@ class ArrayBufferOrViewContents {
718
723
// Ideally, these would return nullptr if IsEmpty() or length_ is zero,
719
724
// but some of the openssl API react badly if given a nullptr even when
720
725
// length is zero, so we have to return something.
721
- if (size () == 0 )
722
- return &buf;
726
+ if (empty ()) return &buf;
723
727
return reinterpret_cast <T*>(data_) + offset_;
724
728
}
725
729
726
730
inline T* data () {
727
731
// Ideally, these would return nullptr if IsEmpty() or length_ is zero,
728
732
// but some of the openssl API react badly if given a nullptr even when
729
733
// length is zero, so we have to return something.
730
- if (size () == 0 )
731
- return &buf;
734
+ if (empty ()) return &buf;
732
735
return reinterpret_cast <T*>(data_) + offset_;
733
736
}
734
737
735
738
inline size_t size () const { return length_; }
736
739
740
+ inline bool empty () const { return length_ == 0 ; }
741
+
737
742
// In most cases, input buffer sizes passed in to openssl need to
738
743
// be limited to <= INT_MAX. This utility method helps us check.
739
744
inline bool CheckSizeInt32 () { return size () <= INT_MAX; }
@@ -743,14 +748,14 @@ class ArrayBufferOrViewContents {
743
748
}
744
749
745
750
inline ByteSource ToCopy () const {
746
- if (size () == 0 ) return ByteSource ();
751
+ if (empty () ) return ByteSource ();
747
752
ByteSource::Builder buf (size ());
748
753
memcpy (buf.data <void >(), data (), size ());
749
754
return std::move (buf).release ();
750
755
}
751
756
752
757
inline ByteSource ToNullTerminatedCopy () const {
753
- if (size () == 0 ) return ByteSource ();
758
+ if (empty () ) return ByteSource ();
754
759
ByteSource::Builder buf (size () + 1 );
755
760
memcpy (buf.data <void >(), data (), size ());
756
761
buf.data <char >()[size ()] = 0 ;
0 commit comments