From e81459f687144b5d80a9e12cf024814f73169e2d Mon Sep 17 00:00:00 2001 From: Tudor Bosman Date: Mon, 11 Jun 2012 17:09:43 -0700 Subject: [PATCH] InternalBuf doesn't need capacity Summary: as it's always kMaxInternalDataSize. Test Plan: all tests in folly/experimental/io/test, both opt and dbg Reviewed By: brianp@fb.com FB internal diff: D492008 --- folly/experimental/io/IOBuf.cpp | 8 ++++---- folly/experimental/io/IOBuf.h | 5 ++--- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/folly/experimental/io/IOBuf.cpp b/folly/experimental/io/IOBuf.cpp index 16c4e551..838d7069 100644 --- a/folly/experimental/io/IOBuf.cpp +++ b/folly/experimental/io/IOBuf.cpp @@ -92,7 +92,7 @@ unique_ptr IOBuf::create(uint32_t capacity) { throw std::bad_alloc(); } - uint8_t* bufEnd = static_cast(buf) +kMaxIOBufSize; + uint8_t* bufEnd = static_cast(buf) + kMaxIOBufSize; unique_ptr iobuf(new(buf) IOBuf(bufEnd)); assert(iobuf->capacity() >= capacity); return iobuf; @@ -164,8 +164,8 @@ IOBuf::IOBuf(uint8_t* end) data_(int_.buf), length_(0), flags_(0) { - int_.capacity = end - int_.buf; - assert(int_.capacity <= kMaxInternalDataSize); + assert(end - int_.buf == kMaxInternalDataSize); + assert(end - reinterpret_cast(this) == kMaxIOBufSize); } IOBuf::IOBuf(ExtBufTypeEnum type, @@ -274,7 +274,7 @@ unique_ptr IOBuf::cloneOne() const { } else { // We have an internal data buffer that cannot be shared // Allocate a new IOBuf and copy the data into it. - unique_ptr iobuf(IOBuf::create(int_.capacity)); + unique_ptr iobuf(IOBuf::create(kMaxInternalDataSize)); assert((iobuf->flags_ & kFlagExt) == 0); iobuf->data_ += headroom(); memcpy(iobuf->data_, data_, length_); diff --git a/folly/experimental/io/IOBuf.h b/folly/experimental/io/IOBuf.h index 03f2126f..91dbc395 100644 --- a/folly/experimental/io/IOBuf.h +++ b/folly/experimental/io/IOBuf.h @@ -405,7 +405,7 @@ class IOBuf { const uint8_t* bufferEnd() const { return (flags_ & kFlagExt) ? ext_.buf + ext_.capacity : - int_.buf + int_.capacity; + int_.buf + kMaxInternalDataSize; } /** @@ -415,7 +415,7 @@ class IOBuf { * method to get the length of the actual valid data in this IOBuf. */ uint32_t capacity() const { - return (flags_ & kFlagExt) ? ext_.capacity : int_.capacity; + return (flags_ & kFlagExt) ? ext_.capacity : kMaxInternalDataSize; } /** @@ -918,7 +918,6 @@ class IOBuf { SharedInfo* sharedInfo; }; struct InternalBuf { - uint32_t capacity; uint8_t buf[] __attribute__((aligned)); }; -- 2.34.1