#pragma once
#include <algorithm>
+
#include "port/port.h"
namespace ROCKSDB_NAMESPACE {
// Example:
// Roundup(13, 5) => 15
// Roundup(201, 16) => 208
-inline size_t Roundup(size_t x, size_t y) {
- return ((x + y - 1) / y) * y;
-}
+inline size_t Roundup(size_t x, size_t y) { return ((x + y - 1) / y) * y; }
// Round down x to a multiple of y.
// Example:
size_t cursize_;
char* bufstart_;
-public:
+ public:
AlignedBuffer()
- : alignment_(),
- capacity_(0),
- cursize_(0),
- bufstart_(nullptr) {
- }
+ : alignment_(), capacity_(0), cursize_(0), bufstart_(nullptr) {}
- AlignedBuffer(AlignedBuffer&& o) ROCKSDB_NOEXCEPT {
- *this = std::move(o);
- }
+ AlignedBuffer(AlignedBuffer&& o) noexcept { *this = std::move(o); }
- AlignedBuffer& operator=(AlignedBuffer&& o) ROCKSDB_NOEXCEPT {
+ AlignedBuffer& operator=(AlignedBuffer&& o) noexcept {
alignment_ = std::move(o.alignment_);
buf_ = std::move(o.buf_);
capacity_ = std::move(o.capacity_);
return n % alignment == 0;
}
- size_t Alignment() const {
- return alignment_;
- }
+ size_t Alignment() const { return alignment_; }
- size_t Capacity() const {
- return capacity_;
- }
+ size_t Capacity() const { return capacity_; }
- size_t CurrentSize() const {
- return cursize_;
- }
+ size_t CurrentSize() const { return cursize_; }
- const char* BufferStart() const {
- return bufstart_;
- }
+ const char* BufferStart() const { return bufstart_; }
char* BufferStart() { return bufstart_; }
- void Clear() {
- cursize_ = 0;
- }
+ void Clear() { cursize_ = 0; }
char* Release() {
cursize_ = 0;
assert(offset < cursize_);
size_t to_read = 0;
- if(offset < cursize_) {
+ if (offset < cursize_) {
to_read = std::min(cursize_ - offset, read_size);
}
if (to_read > 0) {
// the buffer is modified without using the write APIs or encapsulation
// offered by AlignedBuffer. It is up to the user to guard against such
// errors.
- char* Destination() {
- return bufstart_ + cursize_;
- }
+ char* Destination() { return bufstart_ + cursize_; }
- void Size(size_t cursize) {
- cursize_ = cursize;
- }
+ void Size(size_t cursize) { cursize_ = cursize; }
};
} // namespace ROCKSDB_NAMESPACE