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
52 lines
1.4 KiB
C++
52 lines
1.4 KiB
C++
/* SPDX-FileCopyrightText: 2023 Blender Authors
|
|
*
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
|
|
#include "BLI_compute_context.hh"
|
|
#include "BLI_hash_md5.h"
|
|
#include <sstream>
|
|
|
|
namespace blender {
|
|
|
|
void ComputeContextHash::mix_in(const void *data, int64_t len)
|
|
{
|
|
DynamicStackBuffer<> buffer_owner(HashSizeInBytes + len, 8);
|
|
char *buffer = static_cast<char *>(buffer_owner.buffer());
|
|
memcpy(buffer, this, HashSizeInBytes);
|
|
memcpy(buffer + HashSizeInBytes, data, len);
|
|
|
|
BLI_hash_md5_buffer(buffer, HashSizeInBytes + len, this);
|
|
}
|
|
|
|
std::ostream &operator<<(std::ostream &stream, const ComputeContextHash &hash)
|
|
{
|
|
std::stringstream ss;
|
|
ss << "0x" << std::hex << hash.v1 << hash.v2;
|
|
stream << ss.str();
|
|
return stream;
|
|
}
|
|
|
|
void ComputeContext::print_stack(std::ostream &stream, StringRef name) const
|
|
{
|
|
Stack<const ComputeContext *> stack;
|
|
for (const ComputeContext *current = this; current; current = current->parent_) {
|
|
stack.push(current);
|
|
}
|
|
stream << "Context Stack: " << name << "\n";
|
|
while (!stack.is_empty()) {
|
|
const ComputeContext *current = stack.pop();
|
|
stream << "-> ";
|
|
current->print_current_in_line(stream);
|
|
const ComputeContextHash ¤t_hash = current->hash_;
|
|
stream << " \t(hash: " << current_hash << ")\n";
|
|
}
|
|
}
|
|
|
|
std::ostream &operator<<(std::ostream &stream, const ComputeContext &compute_context)
|
|
{
|
|
compute_context.print_stack(stream, "");
|
|
return stream;
|
|
}
|
|
|
|
} // namespace blender
|