BLI: inline fast case of CacheMutex.ensure

I can measure a few percent speedup by doing that in the file from #146949.

Pull Request: https://projects.blender.org/blender/blender/pulls/147608
This commit is contained in:
Jacques Lucke
2025-10-08 12:23:22 +02:00
parent e3e8c283d5
commit 3e0df5d2d7
2 changed files with 12 additions and 2 deletions

View File

@@ -82,7 +82,14 @@ class CacheMutex {
* This function is thread-safe under the assumption that the same parameters are passed from
* every thread.
*/
void ensure(FunctionRef<void()> compute_cache);
void ensure(const FunctionRef<void()> compute_cache)
{
/* Handle fast case when the cache is up-to-date. */
if (cache_valid_.load(std::memory_order_acquire)) {
return;
}
this->ensure_impl(compute_cache);
}
/**
* Reset the cache. The next time #ensure is called, it will recompute that code.
@@ -107,6 +114,9 @@ class CacheMutex {
{
return cache_valid_.load(std::memory_order_relaxed);
}
private:
void ensure_impl(FunctionRef<void()> compute_cache);
};
} // namespace blender

View File

@@ -11,7 +11,7 @@
namespace blender {
void CacheMutex::ensure(const FunctionRef<void()> compute_cache)
void CacheMutex::ensure_impl(const FunctionRef<void()> compute_cache)
{
if (cache_valid_.load(std::memory_order_acquire)) {
return;