Including <iostream> or similar headers is quite expensive, since it also pulls in things like <locale> and so on. In many BLI headers, iostreams are only used to implement some sort of "debug print", or an operator<< for ostream. Change some of the commonly used places to instead include <iosfwd>, which is the standard way of forward-declaring iostreams related classes, and move the actual debug-print / operator<< implementations into .cc files. This is not done for templated classes though (it would be possible to provide explicit operator<< instantiations somewhere in the source file, but that would lead to hard-to-figure-out linker error whenever someone would add a different template type). There, where possible, I changed from full <iostream> include to only the needed <ostream> part. For Span<T>, I just removed print_as_lines since it's not used by anything. It could be moved into a .cc file using a similar approach as above if needed. Doing full blender build changes include counts this way: - <iostream> 1986 -> 978 - <sstream> 2880 -> 925 It does not affect the total build time much though, mostly because towards the end of it there's just several CPU cores finishing compiling OpenVDB related source files. Pull Request: https://projects.blender.org/blender/blender/pulls/111046
102 lines
2.8 KiB
C++
102 lines
2.8 KiB
C++
/* SPDX-FileCopyrightText: 2023 Blender Authors
|
|
*
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
|
|
#include "BLI_bit_span.hh"
|
|
#include "BLI_bit_span_ops.hh"
|
|
|
|
#include <ostream>
|
|
|
|
namespace blender::bits {
|
|
|
|
void MutableBitSpan::set_all()
|
|
{
|
|
if (bit_range_.is_empty()) {
|
|
return;
|
|
}
|
|
const AlignedIndexRanges ranges = split_index_range_by_alignment(bit_range_, BitsPerInt);
|
|
{
|
|
BitInt &first_int = *int_containing_bit(data_, bit_range_.start());
|
|
const BitInt first_int_mask = mask_range_bits(ranges.prefix.start() & BitIndexMask,
|
|
ranges.prefix.size());
|
|
first_int |= first_int_mask;
|
|
}
|
|
{
|
|
BitInt *start = int_containing_bit(data_, ranges.aligned.start());
|
|
const int64_t ints_to_fill = ranges.aligned.size() / BitsPerInt;
|
|
constexpr BitInt fill_value = BitInt(-1);
|
|
initialized_fill_n(start, ints_to_fill, fill_value);
|
|
}
|
|
{
|
|
BitInt &last_int = *int_containing_bit(data_, bit_range_.one_after_last() - 1);
|
|
const BitInt last_int_mask = mask_first_n_bits(ranges.suffix.size());
|
|
last_int |= last_int_mask;
|
|
}
|
|
}
|
|
|
|
void MutableBitSpan::reset_all()
|
|
{
|
|
if (bit_range_.is_empty()) {
|
|
return;
|
|
}
|
|
const AlignedIndexRanges ranges = split_index_range_by_alignment(bit_range_, BitsPerInt);
|
|
{
|
|
BitInt &first_int = *int_containing_bit(data_, bit_range_.start());
|
|
const BitInt first_int_mask = mask_range_bits(ranges.prefix.start() & BitIndexMask,
|
|
ranges.prefix.size());
|
|
first_int &= ~first_int_mask;
|
|
}
|
|
{
|
|
BitInt *start = int_containing_bit(data_, ranges.aligned.start());
|
|
const int64_t ints_to_fill = ranges.aligned.size() / BitsPerInt;
|
|
constexpr BitInt fill_value = 0;
|
|
initialized_fill_n(start, ints_to_fill, fill_value);
|
|
}
|
|
{
|
|
BitInt &last_int = *int_containing_bit(data_, bit_range_.one_after_last() - 1);
|
|
const BitInt last_int_mask = mask_first_n_bits(ranges.suffix.size());
|
|
last_int &= ~last_int_mask;
|
|
}
|
|
}
|
|
|
|
void MutableBitSpan::copy_from(const BitSpan other)
|
|
{
|
|
BLI_assert(this->size() == other.size());
|
|
copy_from_or(*this, other);
|
|
}
|
|
|
|
void MutableBitSpan::copy_from(const BoundedBitSpan other)
|
|
{
|
|
BLI_assert(this->size() == other.size());
|
|
copy_from_or(*this, other);
|
|
}
|
|
|
|
void MutableBoundedBitSpan::copy_from(const BitSpan other)
|
|
{
|
|
BLI_assert(this->size() == other.size());
|
|
copy_from_or(*this, other);
|
|
}
|
|
|
|
void MutableBoundedBitSpan::copy_from(const BoundedBitSpan other)
|
|
{
|
|
BLI_assert(this->size() == other.size());
|
|
copy_from_or(*this, other);
|
|
}
|
|
|
|
std::ostream &operator<<(std::ostream &stream, const BitSpan &span)
|
|
{
|
|
stream << "(Size: " << span.size() << ", ";
|
|
for (const BitRef bit : span) {
|
|
stream << bit;
|
|
}
|
|
stream << ")";
|
|
return stream;
|
|
}
|
|
|
|
std::ostream &operator<<(std::ostream &stream, const MutableBitSpan &span)
|
|
{
|
|
return stream << BitSpan(span);
|
|
}
|
|
|
|
} // namespace blender::bits
|