@@ -326,6 +326,11 @@ inline bool StringEqualNoCase(const char* a, const char* b);
326
326
// strncasecmp() is locale-sensitive. Use StringEqualNoCaseN() instead.
327
327
inline bool StringEqualNoCaseN (const char * a, const char * b, size_t length);
328
328
329
+ template <typename T, size_t N>
330
+ constexpr size_t arraysize (const T (&)[N]) {
331
+ return N;
332
+ }
333
+
329
334
// Allocates an array of member type T. For up to kStackStorageSize items,
330
335
// the stack is used, otherwise malloc().
331
336
template <typename T, size_t kStackStorageSize = 1024 >
@@ -365,8 +370,7 @@ class MaybeStackBuffer {
365
370
// Current maximum capacity of the buffer with which SetLength() can be used
366
371
// without first calling AllocateSufficientStorage().
367
372
size_t capacity () const {
368
- return IsAllocated () ? capacity_ :
369
- IsInvalidated () ? 0 : kStackStorageSize ;
373
+ return capacity_;
370
374
}
371
375
372
376
// Make sure enough space for `storage` entries is available.
@@ -408,6 +412,7 @@ class MaybeStackBuffer {
408
412
// be used.
409
413
void Invalidate () {
410
414
CHECK (!IsAllocated ());
415
+ capacity_ = 0 ;
411
416
length_ = 0 ;
412
417
buf_ = nullptr ;
413
418
}
@@ -428,10 +433,11 @@ class MaybeStackBuffer {
428
433
CHECK (IsAllocated ());
429
434
buf_ = buf_st_;
430
435
length_ = 0 ;
431
- capacity_ = 0 ;
436
+ capacity_ = arraysize (buf_st_) ;
432
437
}
433
438
434
- MaybeStackBuffer () : length_(0 ), capacity_(0 ), buf_(buf_st_) {
439
+ MaybeStackBuffer ()
440
+ : length_(0 ), capacity_(arraysize(buf_st_)), buf_(buf_st_) {
435
441
// Default to a zero-length, null-terminated buffer.
436
442
buf_[0 ] = T ();
437
443
}
@@ -707,11 +713,6 @@ inline bool IsBigEndian() {
707
713
return GetEndianness () == kBigEndian ;
708
714
}
709
715
710
- template <typename T, size_t N>
711
- constexpr size_t arraysize (const T (&)[N]) {
712
- return N;
713
- }
714
-
715
716
// Round up a to the next highest multiple of b.
716
717
template <typename T>
717
718
constexpr T RoundUp (T a, T b) {
0 commit comments