From 9a879b27b339c529e5626ba26c2fb72ac6a98526 Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Wed, 12 Jul 2023 18:04:13 +0200 Subject: [PATCH] Cleanup: Fix macOS build error, move set performance test out of header Fixes, similar to a5a72019a910952ac082e9613e95d0c672cf2964 Pull Request: https://projects.blender.org/blender/blender/pulls/110017 --- intern/mikktspace/mikktspace.hh | 1 + source/blender/blenlib/BLI_set.hh | 85 -------------------- source/blender/blenlib/tests/BLI_set_test.cc | 81 +++++++++++++++++++ 3 files changed, 82 insertions(+), 85 deletions(-) diff --git a/intern/mikktspace/mikktspace.hh b/intern/mikktspace/mikktspace.hh index a76c891c716..5335410de30 100644 --- a/intern/mikktspace/mikktspace.hh +++ b/intern/mikktspace/mikktspace.hh @@ -9,6 +9,7 @@ #include #include +#include #ifdef WITH_TBB # include diff --git a/source/blender/blenlib/BLI_set.hh b/source/blender/blenlib/BLI_set.hh index 2ee8268e4b5..f7b26511433 100644 --- a/source/blender/blenlib/BLI_set.hh +++ b/source/blender/blenlib/BLI_set.hh @@ -45,8 +45,6 @@ * memory usage of the set. * - The method names don't follow the std::unordered_set names in many cases. Searching for such * names in this file will usually let you discover the new name. - * - There is a #StdUnorderedSetWrapper class, that wraps std::unordered_set and gives it the same - * interface as blender::Set. This is useful for bench-marking. * * Possible Improvements: * - Use a branch-less loop over slots in grow function (measured ~10% performance improvement when @@ -57,8 +55,6 @@ * to make a nice interface for this functionality. */ -#include - #include "BLI_array.hh" #include "BLI_hash.hh" #include "BLI_hash_tables.hh" @@ -889,87 +885,6 @@ class Set { } }; -/** - * A wrapper for std::unordered_set with the API of blender::Set. This can be used for - * benchmarking. - */ -template class StdUnorderedSetWrapper { - private: - using SetType = std::unordered_set>; - SetType set_; - - public: - int64_t size() const - { - return int64_t(set_.size()); - } - - bool is_empty() const - { - return set_.empty(); - } - - void reserve(int64_t n) - { - set_.reserve(n); - } - - void add_new(const Key &key) - { - set_.insert(key); - } - void add_new(Key &&key) - { - set_.insert(std::move(key)); - } - - bool add(const Key &key) - { - return set_.insert(key).second; - } - bool add(Key &&key) - { - return set_.insert(std::move(key)).second; - } - - void add_multiple(Span keys) - { - for (const Key &key : keys) { - set_.insert(key); - } - } - - bool contains(const Key &key) const - { - return set_.find(key) != set_.end(); - } - - bool remove(const Key &key) - { - return bool(set_.erase(key)); - } - - void remove_contained(const Key &key) - { - return set_.erase(key); - } - - void clear() - { - set_.clear(); - } - - typename SetType::iterator begin() const - { - return set_.begin(); - } - - typename SetType::iterator end() const - { - return set_.end(); - } -}; - /** * Same as a normal Set, but does not use Blender's guarded allocator. This is useful when * allocating memory with static storage duration. diff --git a/source/blender/blenlib/tests/BLI_set_test.cc b/source/blender/blenlib/tests/BLI_set_test.cc index c20a2b83600..93dcd540162 100644 --- a/source/blender/blenlib/tests/BLI_set_test.cc +++ b/source/blender/blenlib/tests/BLI_set_test.cc @@ -663,6 +663,87 @@ BLI_NOINLINE void benchmark_random_ints(StringRef name, int amount, int factor) std::cout << "Count: " << count << "\n"; } +/** + * A wrapper for std::unordered_set with the API of blender::Set. This can be used for + * benchmarking. + */ +template class StdUnorderedSetWrapper { + private: + using SetType = std::unordered_set>; + SetType set_; + + public: + int64_t size() const + { + return int64_t(set_.size()); + } + + bool is_empty() const + { + return set_.empty(); + } + + void reserve(int64_t n) + { + set_.reserve(n); + } + + void add_new(const Key &key) + { + set_.insert(key); + } + void add_new(Key &&key) + { + set_.insert(std::move(key)); + } + + bool add(const Key &key) + { + return set_.insert(key).second; + } + bool add(Key &&key) + { + return set_.insert(std::move(key)).second; + } + + void add_multiple(Span keys) + { + for (const Key &key : keys) { + set_.insert(key); + } + } + + bool contains(const Key &key) const + { + return set_.find(key) != set_.end(); + } + + bool remove(const Key &key) + { + return bool(set_.erase(key)); + } + + void remove_contained(const Key &key) + { + return set_.erase(key); + } + + void clear() + { + set_.clear(); + } + + typename SetType::iterator begin() const + { + return set_.begin(); + } + + typename SetType::iterator end() const + { + return set_.end(); + } +}; + TEST(set, Benchmark) { for (int i = 0; i < 3; i++) {