/*
- * Copyright 2017 Facebook, Inc.
+ * Copyright 2013-present Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include <folly/io/IOBuf.h>
+#include <cassert>
+#include <cstdint>
+#include <cstdlib>
+#include <stdexcept>
+
#include <folly/Conv.h>
#include <folly/Likely.h>
-#include <folly/Malloc.h>
#include <folly/Memory.h>
#include <folly/ScopeGuard.h>
-#include <folly/SpookyHashV2.h>
+#include <folly/hash/SpookyHashV2.h>
#include <folly/io/Cursor.h>
-
-#include <stdexcept>
-#include <assert.h>
-#include <stdint.h>
-#include <stdlib.h>
+#include <folly/lang/Align.h>
+#include <folly/memory/Malloc.h>
using std::unique_ptr;
}
}
-} // unnamed namespace
+} // namespace
namespace folly {
struct IOBuf::HeapPrefix {
- HeapPrefix(uint16_t flg)
- : magic(kHeapMagic),
- flags(flg) {}
+ explicit HeapPrefix(uint16_t flg) : magic(kHeapMagic), flags(flg) {}
~HeapPrefix() {
// Reset magic to 0 on destruction. This is solely for debugging purposes
// to help catch bugs where someone tries to use HeapStorage after it has
HeapStorage hs;
SharedInfo shared;
- std::max_align_t align;
+ folly::max_align_t align;
};
IOBuf::SharedInfo::SharedInfo()
void* IOBuf::operator new(size_t size) {
size_t fullSize = offsetof(HeapStorage, buf) + size;
auto* storage = static_cast<HeapStorage*>(malloc(fullSize));
- // operator new is not allowed to return NULL
+ // operator new is not allowed to return nullptr
if (UNLIKELY(storage == nullptr)) {
throw std::bad_alloc();
}
}
unique_ptr<IOBuf> IOBuf::createSeparate(uint64_t capacity) {
- return make_unique<IOBuf>(CREATE, capacity);
+ return std::make_unique<IOBuf>(CREATE, capacity);
}
unique_ptr<IOBuf> IOBuf::createChain(
//
// Note that we always pass freeOnError as false to the constructor.
// If the constructor throws we'll handle it below. (We have to handle
- // allocation failures from make_unique too.)
- return make_unique<IOBuf>(TAKE_OWNERSHIP, buf, capacity, length,
- freeFn, userData, false);
+ // allocation failures from std::make_unique too.)
+ return std::make_unique<IOBuf>(
+ TAKE_OWNERSHIP, buf, capacity, length, freeFn, userData, false);
} catch (...) {
takeOwnershipError(freeOnError, buf, freeFn, userData);
throw;
}
unique_ptr<IOBuf> IOBuf::wrapBuffer(const void* buf, uint64_t capacity) {
- return make_unique<IOBuf>(WRAP_BUFFER, buf, capacity);
+ return std::make_unique<IOBuf>(WRAP_BUFFER, buf, capacity);
}
IOBuf IOBuf::wrapBufferAsValue(const void* buf, uint64_t capacity) {
}
unique_ptr<IOBuf> IOBuf::clone() const {
- return make_unique<IOBuf>(cloneAsValue());
+ return std::make_unique<IOBuf>(cloneAsValue());
}
unique_ptr<IOBuf> IOBuf::cloneOne() const {
- return make_unique<IOBuf>(cloneOneAsValue());
+ return std::make_unique<IOBuf>(cloneOneAsValue());
}
unique_ptr<IOBuf> IOBuf::cloneCoalesced() const {
- return make_unique<IOBuf>(cloneCoalescedAsValue());
+ return std::make_unique<IOBuf>(cloneCoalescedAsValue());
}
IOBuf IOBuf::cloneAsValue() const {
// - If using jemalloc, we can try to expand in place, avoiding a memcpy()
// - If not using jemalloc and we don't have too much to copy,
// we'll use realloc() (note that realloc might have to copy
- // headroom + data + tailroom, see smartRealloc in folly/Malloc.h)
+ // headroom + data + tailroom, see smartRealloc in folly/memory/Malloc.h)
// - Otherwise, bite the bullet and reallocate.
if (headroom() + tailroom() >= minHeadroom + minTailroom) {
uint8_t* newData = writableBuffer() + minHeadroom;
}
}
-} // folly
+} // namespace folly