Cleanup: Remove some indirect includes in common headers

The idea is to avoid mistakenly depending on indirect includes,
and avoid compile time overhead from unnecessary header parsing.

Pull Request: https://projects.blender.org/blender/blender/pulls/116664
This commit is contained in:
Hans Goudey 2024-01-06 01:47:39 +01:00 committed by Hans Goudey
parent ae02096ad6
commit 09063a3632
31 changed files with 61 additions and 56 deletions

View File

@ -28,6 +28,7 @@
#include "BKE_report.h"
#include "BLI_dynstr.h"
#include "BLI_math_base.h"
#include "BLI_utildefines.h"
#include "BLT_translation.h"

View File

@ -8,6 +8,7 @@
#pragma once
#include <functional>
#include <memory>
#include "AS_asset_catalog.hh"

View File

@ -9,6 +9,7 @@
* but does not write it to a file.
*/
#include <cctype>
#include <cstring>
#include "BLI_alloca.h"

View File

@ -4,6 +4,7 @@
#pragma once
#include <functional>
#include <optional>
#include "BLI_function_ref.hh"

View File

@ -2,6 +2,8 @@
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#include <cstring>
#include "BKE_file_handler.hh"
#include "BLI_string.h"

View File

@ -25,12 +25,10 @@
* need. More complexity can be added when it seems necessary.
*/
#include <algorithm>
#include <stdlib.h>
#include <cstdlib>
#include "MEM_guardedalloc.h"
#include "BLI_math_base.h"
#include "BLI_utildefines.h"
namespace blender {
@ -67,7 +65,7 @@ class RawAllocator {
public:
void *allocate(size_t size, size_t alignment, const char * /*name*/)
{
BLI_assert(is_power_of_2_i(int(alignment)));
BLI_assert(is_power_of_2(int(alignment)));
void *ptr = malloc(size + alignment + sizeof(MemHead));
void *used_ptr = reinterpret_cast<void *>(
uintptr_t(POINTER_OFFSET(ptr, alignment + sizeof(MemHead))) & ~(uintptr_t(alignment) - 1));

View File

@ -15,7 +15,6 @@
*/
#include <algorithm>
#include <cstring>
#include <utility>
#include "BLI_memory_utils.hh"
@ -160,7 +159,9 @@ class Any {
info_->copy_construct(&buffer_, &other.buffer_);
}
else {
memcpy(&buffer_, &other.buffer_, RealInlineBufferCapacity);
std::copy_n(static_cast<const std::byte *>(other.buffer_.ptr()),
RealInlineBufferCapacity,
static_cast<std::byte *>(buffer_.ptr()));
}
}
}
@ -176,7 +177,9 @@ class Any {
info_->move_construct(&buffer_, &other.buffer_);
}
else {
memcpy(&buffer_, &other.buffer_, RealInlineBufferCapacity);
std::copy_n(static_cast<const std::byte *>(other.buffer_.ptr()),
RealInlineBufferCapacity,
static_cast<std::byte *>(buffer_.ptr()));
}
}
}

View File

@ -13,6 +13,8 @@
* - #BLI_STATIC_ASSERT_ALIGN
*/
#include <stddef.h>
#ifdef __cplusplus
extern "C" {
#endif

View File

@ -33,7 +33,7 @@ class BitGroupVector {
{
if (group_size < 64) {
/* Align to next power of two so that a single group never spans across two ints. */
return int64_t(power_of_2_max_u(uint32_t(group_size)));
return power_of_2_max(group_size);
}
/* Align to multiple of BitsPerInt. */
return (group_size + BitsPerInt - 1) & ~(BitsPerInt - 1);

View File

@ -8,7 +8,6 @@
#include "BLI_bit_ref.hh"
#include "BLI_index_range.hh"
#include "BLI_math_bits.h"
#include "BLI_memory_utils.hh"
namespace blender::bits {

View File

@ -5,6 +5,7 @@
#pragma once
#include "BLI_bit_span.hh"
#include "BLI_math_bits.h"
namespace blender::bits {

View File

@ -37,8 +37,6 @@
* - `BLI_bitmap` should only be used in C code that can not use `blender::BitVector`.
*/
#include <cstring>
#include "BLI_allocator.hh"
#include "BLI_bit_span.hh"
#include "BLI_span.hh"

View File

@ -61,7 +61,6 @@
* };
*/
#include <functional>
#include <memory>
#include <string>
#include <utility>

View File

@ -11,9 +11,7 @@
*/
#include <algorithm>
#include <cmath>
#include "BLI_allocator.hh"
#include "BLI_memory_utils.hh"
#include "BLI_utildefines.h"
#include "BLI_vector.hh"
@ -26,30 +24,6 @@ namespace blender {
* Those should eventually be de-duplicated with functions in BLI_math_base.h.
* \{ */
inline constexpr int64_t is_power_of_2_constexpr(const int64_t x)
{
BLI_assert(x >= 0);
return (x & (x - 1)) == 0;
}
inline constexpr int64_t log2_floor_constexpr(const int64_t x)
{
BLI_assert(x >= 0);
return x <= 1 ? 0 : 1 + log2_floor_constexpr(x >> 1);
}
inline constexpr int64_t log2_ceil_constexpr(const int64_t x)
{
BLI_assert(x >= 0);
return (is_power_of_2_constexpr(int(x))) ? log2_floor_constexpr(x) : log2_floor_constexpr(x) + 1;
}
inline constexpr int64_t power_of_2_max_constexpr(const int64_t x)
{
BLI_assert(x >= 0);
return 1ll << log2_ceil_constexpr(x);
}
template<typename IntT> inline constexpr IntT ceil_division(const IntT x, const IntT y)
{
BLI_assert(x >= 0);
@ -83,7 +57,7 @@ inline constexpr int64_t total_slot_amount_for_usable_slots(
const int64_t max_load_factor_numerator,
const int64_t max_load_factor_denominator)
{
return power_of_2_max_constexpr(ceil_division_by_fraction(
return power_of_2_max(ceil_division_by_fraction(
min_usable_slots, max_load_factor_numerator, max_load_factor_denominator));
}
@ -115,7 +89,7 @@ class LoadFactor {
int64_t *r_total_slots,
int64_t *r_usable_slots) const
{
BLI_assert(is_power_of_2_i(int(min_total_slots)));
BLI_assert(is_power_of_2(int(min_total_slots)));
int64_t total_slots = this->compute_total_slots(min_usable_slots, numerator_, denominator_);
total_slots = std::max(total_slots, min_total_slots);

View File

@ -10,8 +10,7 @@
#include <atomic>
#include "BLI_compiler_attrs.h"
#include "BLI_utildefines.h"
#include "BLI_assert.h"
#include "BLI_utility_mixins.hh"
namespace blender {

View File

@ -5,6 +5,7 @@
#pragma once
#include <array>
#include <limits>
#include <optional>
#include <variant>

View File

@ -38,10 +38,9 @@
*/
#include <algorithm>
#include <cmath>
#include <iosfwd>
#include "BLI_utildefines.h"
#include "BLI_assert.h"
namespace blender {

View File

@ -65,7 +65,7 @@ template<typename Allocator = GuardedAllocator> class LinearAllocator : NonCopya
{
BLI_assert(size >= 0);
BLI_assert(alignment >= 1);
BLI_assert(is_power_of_2_i(alignment));
BLI_assert(is_power_of_2(alignment));
const uintptr_t alignment_mask = alignment - 1;
const uintptr_t potential_allocation_begin = (current_begin_ + alignment_mask) &

View File

@ -43,6 +43,8 @@
* probing might work best.
*/
#include <limits>
#include "BLI_sys_types.h"
namespace blender {

View File

@ -58,7 +58,6 @@
#include <algorithm>
#include <array>
#include <string>
#include <vector>
#include "BLI_index_range.hh"

View File

@ -254,6 +254,32 @@ extern "C" {
*/
#define DECIMAL_DIGITS_BOUND(t) (241 * sizeof(t) / 100 + 1)
#ifdef __cplusplus
inline constexpr int64_t is_power_of_2(const int64_t x)
{
BLI_assert(x >= 0);
return (x & (x - 1)) == 0;
}
inline constexpr int64_t log2_floor(const int64_t x)
{
BLI_assert(x >= 0);
return x <= 1 ? 0 : 1 + log2_floor(x >> 1);
}
inline constexpr int64_t log2_ceil(const int64_t x)
{
BLI_assert(x >= 0);
return (is_power_of_2(int(x))) ? log2_floor(x) : log2_floor(x) + 1;
}
inline constexpr int64_t power_of_2_max(const int64_t x)
{
BLI_assert(x >= 0);
return 1ll << log2_ceil(x);
}
#endif
/** \} */
/* -------------------------------------------------------------------- */

View File

@ -25,9 +25,6 @@
*/
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <memory>
#include "BLI_allocator.hh"
#include "BLI_index_range.hh"
@ -35,8 +32,6 @@
#include "BLI_span.hh"
#include "BLI_utildefines.h"
#include "MEM_guardedalloc.h"
namespace blender {
namespace internal {

View File

@ -14,7 +14,7 @@ namespace blender {
AlignedIndexRanges split_index_range_by_alignment(const IndexRange range, const int64_t alignment)
{
BLI_assert(is_power_of_2_i(alignment));
BLI_assert(is_power_of_2(alignment));
const int64_t mask = alignment - 1;
AlignedIndexRanges aligned_ranges;

View File

@ -11,7 +11,7 @@ namespace blender::tests {
static bool is_aligned(void *ptr, uint alignment)
{
BLI_assert(is_power_of_2_i(int(alignment)));
BLI_assert(is_power_of_2(int(alignment)));
return (POINTER_AS_UINT(ptr) & (alignment - 1)) == 0;
}

View File

@ -20,6 +20,7 @@
#include "BLI_array.hh"
#include "BLI_dynstr.h"
#include "BLI_listbase.h"
#include "BLI_math_base.h"
#include "BLI_rect.h"
#include "BLI_string.h"
#include "BLI_utildefines.h"

View File

@ -6,6 +6,7 @@
* \ingroup edinterface
*/
#include <cfloat>
#include <limits>
#include <stdexcept>

View File

@ -10,6 +10,7 @@
#include "BLI_lasso_2d.h"
#include "BLI_listbase.h"
#include "BLI_math_base.h"
#include "BLI_rect.h"
#include "BLI_utildefines.h"

View File

@ -8,8 +8,8 @@
#include "DNA_object_types.h" /* For MAX_DUPLI_RECUR */
#include <array>
#include <optional>
#include <ostream>
#include <iosfwd>
#include <string>
namespace blender::io {

View File

@ -7,6 +7,7 @@
#include "BKE_mesh.hh"
#include "BKE_object.hh"
#include "BLI_math_base.h"
#include "BLI_math_vector_types.hh"
#include "BLI_string.h"

View File

@ -10,7 +10,6 @@
#include <cfloat>
#include <cmath>
#include <cstring>
#include "BKE_node.hh"

View File

@ -17,6 +17,7 @@
#include "BLI_blenlib.h"
#include "BLI_ghash.h"
#include "BLI_math_base.h"
#include "BLI_math_matrix.h"
#include "BLI_utildefines.h"