Skip to content

Commit 073550a

Browse files
committed
Fix code style
Signed-off-by: Petr Shumilov <p.shumilov@vkteam.ru>
1 parent 1042232 commit 073550a

1 file changed

Lines changed: 13 additions & 11 deletions

File tree

runtime-common/core/allocator/script-malloc-interface.h

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,12 @@ constexpr uint64_t MALLOC_REPLACER_MAX_ALLOC = 0xFFFFFF00; // 4GiB
2424
namespace details {
2525
struct control_block {
2626
private:
27-
static inline constexpr auto SIZE_FIELD_BITSIZE{48};
28-
static inline constexpr auto BASE_OFFSET_FIELD_BITSIZE{16};
29-
static inline constexpr uint64_t BLOCK_SIZE_MASK{(1UL << SIZE_FIELD_BITSIZE) - 1};
30-
static inline constexpr uint64_t BASE_OFFSET_MASK{(1UL << BASE_OFFSET_FIELD_BITSIZE) - 1};
27+
static constexpr auto SIZE_FIELD_BITSIZE{48};
28+
static constexpr auto BASE_OFFSET_FIELD_BITSIZE{16};
29+
static constexpr uint64_t BLOCK_SIZE_MASK{(1UL << SIZE_FIELD_BITSIZE) - 1};
30+
static constexpr uint64_t BASE_OFFSET_MASK{(1UL << BASE_OFFSET_FIELD_BITSIZE) - 1};
31+
32+
static_assert(SIZE_FIELD_BITSIZE + BASE_OFFSET_FIELD_BITSIZE == 64);
3133

3234
public:
3335
static constexpr uint64_t max_size() noexcept {
@@ -59,7 +61,7 @@ static_assert(sizeof(control_block) == sizeof(uint64_t), "Control block's size m
5961
} // namespace details
6062

6163
inline void* alloc(size_t size) noexcept {
62-
const size_t cb_size{sizeof(details::control_block)};
64+
constexpr size_t cb_size{sizeof(details::control_block)};
6365
if (unlikely(size > std::min(details::control_block::max_size(), MALLOC_REPLACER_MAX_ALLOC) - cb_size)) {
6466
php_warning("attempt to allocate too much memory by malloc replacer, requested : %lu", size);
6567
return nullptr;
@@ -70,21 +72,21 @@ inline void* alloc(size_t size) noexcept {
7072
php_warning("not enough script memory to allocate, requested : %lu, actual requested: %lu", size, total_size);
7173
return base;
7274
}
73-
*(reinterpret_cast<uint64_t*>(base)) = details::control_block{.size = total_size, .base_offset = cb_size}.raw();
74-
return reinterpret_cast<void*>(reinterpret_cast<uint64_t>(base) + cb_size); // NOLINT
75+
*(static_cast<uint64_t*>(base)) = details::control_block{.size = total_size, .base_offset = cb_size}.raw();
76+
return static_cast<void*>(static_cast<uint8_t*>(base) + cb_size); // NOLINT
7577
}
7678

7779
inline void* alloc_aligned(size_t size, std::align_val_t alignment) noexcept {
7880
// Check that provided alignment is power of two
7981
const size_t align{static_cast<uint64_t>(alignment)};
8082
if (unlikely(align == 0 || !details::is_power_of_2(align) || align >= details::control_block::max_alignment())) {
81-
php_warning("allocation alignment have to be non-zero power of two and not greater than %" PRIi64 ", got : %lu", details::control_block::max_alignment(),
83+
php_warning("allocation alignment have to be non-zero power of two and not greater than %" PRIu64 ", got : %lu", details::control_block::max_alignment(),
8284
align);
8385
return nullptr;
8486
}
8587

8688
// Check that memory is enough
87-
const size_t cb_size{sizeof(details::control_block)};
89+
constexpr size_t cb_size{sizeof(details::control_block)};
8890
if (unlikely(size > std::min(details::control_block::max_size(), MALLOC_REPLACER_MAX_ALLOC) - (align - 1) - cb_size)) {
8991
php_warning("attempt to allocate too much memory by malloc replacer, requested : %lu", size);
9092
return nullptr;
@@ -123,7 +125,7 @@ inline void free(void* ptr) noexcept {
123125
return;
124126
}
125127

126-
const size_t cb_size{sizeof(details::control_block)};
128+
constexpr size_t cb_size{sizeof(details::control_block)};
127129
const auto mem{reinterpret_cast<uint64_t>(ptr)};
128130

129131
const auto cb{details::control_block::from_raw(*reinterpret_cast<uint64_t*>(mem - cb_size))}; // NOLINT
@@ -142,7 +144,7 @@ inline void* realloc(void* ptr, size_t new_size) noexcept {
142144
return nullptr;
143145
}
144146

145-
const size_t cb_size{sizeof(details::control_block)};
147+
constexpr size_t cb_size{sizeof(details::control_block)};
146148
const auto mem{reinterpret_cast<uint64_t>(ptr)};
147149

148150
const auto cb{details::control_block::from_raw(*reinterpret_cast<uint64_t*>(mem - cb_size))}; // NOLINT

0 commit comments

Comments
 (0)