Commit e81459f6 authored by Tudor Bosman's avatar Tudor Bosman

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
parent 9f705afd
...@@ -92,7 +92,7 @@ unique_ptr<IOBuf> IOBuf::create(uint32_t capacity) { ...@@ -92,7 +92,7 @@ unique_ptr<IOBuf> IOBuf::create(uint32_t capacity) {
throw std::bad_alloc(); throw std::bad_alloc();
} }
uint8_t* bufEnd = static_cast<uint8_t*>(buf) +kMaxIOBufSize; uint8_t* bufEnd = static_cast<uint8_t*>(buf) + kMaxIOBufSize;
unique_ptr<IOBuf> iobuf(new(buf) IOBuf(bufEnd)); unique_ptr<IOBuf> iobuf(new(buf) IOBuf(bufEnd));
assert(iobuf->capacity() >= capacity); assert(iobuf->capacity() >= capacity);
return iobuf; return iobuf;
...@@ -164,8 +164,8 @@ IOBuf::IOBuf(uint8_t* end) ...@@ -164,8 +164,8 @@ IOBuf::IOBuf(uint8_t* end)
data_(int_.buf), data_(int_.buf),
length_(0), length_(0),
flags_(0) { flags_(0) {
int_.capacity = end - int_.buf; assert(end - int_.buf == kMaxInternalDataSize);
assert(int_.capacity <= kMaxInternalDataSize); assert(end - reinterpret_cast<uint8_t*>(this) == kMaxIOBufSize);
} }
IOBuf::IOBuf(ExtBufTypeEnum type, IOBuf::IOBuf(ExtBufTypeEnum type,
...@@ -274,7 +274,7 @@ unique_ptr<IOBuf> IOBuf::cloneOne() const { ...@@ -274,7 +274,7 @@ unique_ptr<IOBuf> IOBuf::cloneOne() const {
} else { } else {
// We have an internal data buffer that cannot be shared // We have an internal data buffer that cannot be shared
// Allocate a new IOBuf and copy the data into it. // Allocate a new IOBuf and copy the data into it.
unique_ptr<IOBuf> iobuf(IOBuf::create(int_.capacity)); unique_ptr<IOBuf> iobuf(IOBuf::create(kMaxInternalDataSize));
assert((iobuf->flags_ & kFlagExt) == 0); assert((iobuf->flags_ & kFlagExt) == 0);
iobuf->data_ += headroom(); iobuf->data_ += headroom();
memcpy(iobuf->data_, data_, length_); memcpy(iobuf->data_, data_, length_);
......
...@@ -405,7 +405,7 @@ class IOBuf { ...@@ -405,7 +405,7 @@ class IOBuf {
const uint8_t* bufferEnd() const { const uint8_t* bufferEnd() const {
return (flags_ & kFlagExt) ? return (flags_ & kFlagExt) ?
ext_.buf + ext_.capacity : ext_.buf + ext_.capacity :
int_.buf + int_.capacity; int_.buf + kMaxInternalDataSize;
} }
/** /**
...@@ -415,7 +415,7 @@ class IOBuf { ...@@ -415,7 +415,7 @@ class IOBuf {
* method to get the length of the actual valid data in this IOBuf. * method to get the length of the actual valid data in this IOBuf.
*/ */
uint32_t capacity() const { uint32_t capacity() const {
return (flags_ & kFlagExt) ? ext_.capacity : int_.capacity; return (flags_ & kFlagExt) ? ext_.capacity : kMaxInternalDataSize;
} }
/** /**
...@@ -918,7 +918,6 @@ class IOBuf { ...@@ -918,7 +918,6 @@ class IOBuf {
SharedInfo* sharedInfo; SharedInfo* sharedInfo;
}; };
struct InternalBuf { struct InternalBuf {
uint32_t capacity;
uint8_t buf[] __attribute__((aligned)); uint8_t buf[] __attribute__((aligned));
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment