| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent e3beb78 commit eb8d6f5
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -321,6 +321,11 @@ inline bool StringEqualNoCase(const char* a, const char* b); | |||
| 321 | 321 | // strncasecmp() is locale-sensitive. Use StringEqualNoCaseN() instead. | |
| 322 | 322 | inline bool StringEqualNoCaseN(const char* a, const char* b, size_t length); | |
| 323 | 323 | ||
| 324 | + template <typename T, size_t N> | ||
| 325 | + constexpr size_t arraysize(const T (&)[N]) { | ||
| 326 | + return N; | ||
| 327 | + } | ||
| 328 | + | ||
| 324 | 329 | // Allocates an array of member type T. For up to kStackStorageSize items, | |
| 325 | 330 | // the stack is used, otherwise malloc(). | |
| 326 | 331 | template <typename T, size_t kStackStorageSize = 1024> | |
@@ -360,8 +365,7 @@ class MaybeStackBuffer { | |||
| 360 | 365 | // Current maximum capacity of the buffer with which SetLength() can be used | |
| 361 | 366 | // without first calling AllocateSufficientStorage(). | |
| 362 | 367 | size_t capacity() const { | |
| 363 | - return IsAllocated() ? capacity_ : | ||
| 364 | - IsInvalidated() ? 0 : kStackStorageSize; | ||
| 368 | + return capacity_; | ||
| 365 | 369 | } | |
| 366 | 370 | ||
| 367 | 371 | // Make sure enough space for `storage` entries is available. | |
@@ -403,6 +407,7 @@ class MaybeStackBuffer { | |||
| 403 | 407 | // be used. | |
| 404 | 408 | void Invalidate() { | |
| 405 | 409 | CHECK(!IsAllocated()); | |
| 410 | + capacity_ = 0; | ||
| 406 | 411 | length_ = 0; | |
| 407 | 412 | buf_ = nullptr; | |
| 408 | 413 | } | |
@@ -423,10 +428,11 @@ class MaybeStackBuffer { | |||
| 423 | 428 | CHECK(IsAllocated()); | |
| 424 | 429 | buf_ = buf_st_; | |
| 425 | 430 | length_ = 0; | |
| 426 | - capacity_ = 0; | ||
| 431 | + capacity_ = arraysize(buf_st_); | ||
| 427 | 432 | } | |
| 428 | 433 | ||
| 429 | - MaybeStackBuffer() : length_(0), capacity_(0), buf_(buf_st_) { | ||
| 434 | + MaybeStackBuffer() | ||
| 435 | + : length_(0), capacity_(arraysize(buf_st_)), buf_(buf_st_) { | ||
| 430 | 436 | // Default to a zero-length, null-terminated buffer. | |
| 431 | 437 | buf_[0] = T(); | |
| 432 | 438 | } | |
@@ -701,11 +707,6 @@ inline bool IsBigEndian() { | |||
| 701 | 707 | return GetEndianness() == kBigEndian; | |
| 702 | 708 | } | |
| 703 | 709 | ||
| 704 | - template <typename T, size_t N> | ||
| 705 | - constexpr size_t arraysize(const T (&)[N]) { | ||
| 706 | - return N; | ||
| 707 | - } | ||
| 708 | - | ||
| 709 | 710 | // Round up a to the next highest multiple of b. | |
| 710 | 711 | template <typename T> | |
| 711 | 712 | constexpr T RoundUp(T a, T b) { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments