Commit dcd9f349 authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook GitHub Bot

Move AlignedSysAllocator computation of max

Summary: [Folly] Move `AlignedSysAllocator` computation of max value over input alignment values from two places to a single place.

Differential Revision: D19229096

fbshipit-source-id: 4e95c7b7e0afe99c37116150184eb180683c7d13
parent 3b29cdba
...@@ -434,8 +434,8 @@ class DefaultAlign { ...@@ -434,8 +434,8 @@ class DefaultAlign {
assert(!(align_ < sizeof(void*)) && bool("bad align: too small")); assert(!(align_ < sizeof(void*)) && bool("bad align: too small"));
assert(!(align_ & (align_ - 1)) && bool("bad align: not power-of-two")); assert(!(align_ & (align_ - 1)) && bool("bad align: not power-of-two"));
} }
std::size_t operator()(std::size_t align) const noexcept { std::size_t operator()() const noexcept {
return align_ < align ? align : align_; return align_;
} }
friend bool operator==(Self const& a, Self const& b) noexcept { friend bool operator==(Self const& a, Self const& b) noexcept {
...@@ -454,8 +454,8 @@ class FixedAlign { ...@@ -454,8 +454,8 @@ class FixedAlign {
using Self = FixedAlign<Align>; using Self = FixedAlign<Align>;
public: public:
constexpr std::size_t operator()(std::size_t align) const noexcept { constexpr std::size_t operator()() const noexcept {
return Align < align ? align : Align; return Align;
} }
friend bool operator==(Self const&, Self const&) noexcept { friend bool operator==(Self const&, Self const&) noexcept {
...@@ -496,7 +496,7 @@ class AlignedSysAllocator : private Align { ...@@ -496,7 +496,7 @@ class AlignedSysAllocator : private Align {
public: public:
static_assert(std::is_nothrow_copy_constructible<Align>::value, ""); static_assert(std::is_nothrow_copy_constructible<Align>::value, "");
static_assert(is_nothrow_invocable_r_v<std::size_t, Align, std::size_t>, ""); static_assert(is_nothrow_invocable_r_v<std::size_t, Align>, "");
using value_type = T; using value_type = T;
...@@ -521,7 +521,7 @@ class AlignedSysAllocator : private Align { ...@@ -521,7 +521,7 @@ class AlignedSysAllocator : private Align {
T* allocate(size_t count) { T* allocate(size_t count) {
using lifted = typename detail::lift_void_to_char<T>::type; using lifted = typename detail::lift_void_to_char<T>::type;
auto const a = align()(alignof(lifted)); auto const a = align()() < alignof(lifted) ? alignof(lifted) : align()();
auto const p = aligned_malloc(sizeof(lifted) * count, a); auto const p = aligned_malloc(sizeof(lifted) * count, a);
if (!p) { if (!p) {
if (FOLLY_UNLIKELY(errno != ENOMEM)) { if (FOLLY_UNLIKELY(errno != ENOMEM)) {
......
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