X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=folly%2FArena.h;h=8b928b039d01febacbcc9596338b13fcbcd466d8;hb=cc4533454c08dc9db6c09ae22c7a1a003711a69f;hp=5ea7552fcf252bc416019c81eb279175fac5b55d;hpb=970c79617bdb988f7f69c3db483a9188382af541;p=folly.git diff --git a/folly/Arena.h b/folly/Arena.h index 5ea7552f..8b928b03 100644 --- a/folly/Arena.h +++ b/folly/Arena.h @@ -1,5 +1,5 @@ /* - * Copyright 2014 Facebook, Inc. + * Copyright 2016 Facebook, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,7 +14,7 @@ * limitations under the License. */ -#ifndef FOLLY_ARENA_H_ +#pragma once #define FOLLY_ARENA_H_ #include @@ -23,10 +23,10 @@ #include #include -#include "folly/Conv.h" -#include "folly/Likely.h" -#include "folly/Malloc.h" -#include "folly/Memory.h" +#include +#include +#include +#include namespace folly { @@ -84,7 +84,8 @@ class Arena { size = roundUp(size); bytesUsed_ += size; - if (LIKELY(end_ - ptr_ >= size)) { + assert(ptr_ <= end_); + if (LIKELY((size_t)(end_ - ptr_) >= size)) { // Fast path: there's enough room in the current block char* r = ptr_; ptr_ += size; @@ -98,7 +99,7 @@ class Arena { return r; } - void deallocate(void* p) { + void deallocate(void* /* p */) { // Deallocate? Never! } @@ -118,7 +119,6 @@ class Arena { return bytesUsed_; } - private: // not copyable Arena(const Arena&) = delete; Arena& operator=(const Arena&) = delete; @@ -127,11 +127,12 @@ class Arena { Arena(Arena&&) = default; Arena& operator=(Arena&&) = default; + private: struct Block; typedef boost::intrusive::slist_member_hook< boost::intrusive::tag> BlockLink; - struct Block { + struct FOLLY_ALIGNED_MAX Block { BlockLink link; // Allocate a block with at least size bytes of storage. @@ -147,16 +148,15 @@ class Arena { } private: - Block() { } - ~Block() { } - } __attribute__((aligned)); - // This should be alignas(std::max_align_t) but neither alignas nor - // max_align_t are supported by gcc 4.6.2. + Block() = default; + ~Block() = default; + }; public: static constexpr size_t kDefaultMinBlockSize = 4096 - sizeof(Block); static constexpr size_t kNoSizeLimit = 0; static constexpr size_t kDefaultMaxAlign = alignof(Block); + static constexpr size_t kBlockOverhead = sizeof(Block); private: bool isAligned(uintptr_t address) const { @@ -215,14 +215,12 @@ struct IsArenaAllocator> : std::true_type { }; */ template struct ArenaAllocatorTraits { - static size_t goodSize(const Alloc& alloc, size_t size) { - return size; - } + static size_t goodSize(const Alloc& /* alloc */, size_t size) { return size; } }; template <> struct ArenaAllocatorTraits { - static size_t goodSize(const SysAlloc& alloc, size_t size) { + static size_t goodSize(const SysAlloc& /* alloc */, size_t size) { return goodMallocSize(size); } }; @@ -244,6 +242,4 @@ struct IsArenaAllocator : std::true_type { }; } // namespace folly -#include "folly/Arena-inl.h" - -#endif /* FOLLY_ARENA_H_ */ +#include