InternalBuf doesn't need capacity
authorTudor Bosman <tudorb@fb.com>
Tue, 12 Jun 2012 00:09:43 +0000 (17:09 -0700)
committerTudor Bosman <tudorb@fb.com>
Tue, 12 Jun 2012 23:23:01 +0000 (16:23 -0700)
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
folly/experimental/io/IOBuf.h

index 16c4e5518eedca3c0cb3f77f13893c91aeaf7a0d..838d7069d2ffbdff52eb40d12e3fe01c88fa49a1 100644 (file)
@@ -92,7 +92,7 @@ unique_ptr<IOBuf> IOBuf::create(uint32_t capacity) {
       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));
     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<uint8_t*>(this) == kMaxIOBufSize);
 }
 
 IOBuf::IOBuf(ExtBufTypeEnum type,
@@ -274,7 +274,7 @@ unique_ptr<IOBuf> 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(IOBuf::create(int_.capacity));
+    unique_ptr<IOBuf> iobuf(IOBuf::create(kMaxInternalDataSize));
     assert((iobuf->flags_ & kFlagExt) == 0);
     iobuf->data_ += headroom();
     memcpy(iobuf->data_, data_, length_);
index 03f2126f0a94c4b2b57c3c2d71da94fd79074f69..91dbc395de9cb08cee273d428c3b4a09c36b5642 100644 (file)
@@ -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));
   };