From 55cc2fcd466d312ffdc9c1af2c19bffe73da9c9d Mon Sep 17 00:00:00 2001 From: Jacques Lucke Date: Fri, 13 Dec 2024 12:48:35 +0100 Subject: [PATCH] BLI: slight Vector move constructor improvement `OtherInlineBufferCapacity <= InlineBufferCapacity` implies `size <= InlineBufferCapacity` and can be done at compile time. So if that is true already (as it commonly is), the `else` branch is not necessary. This can improve performance in theory, although I couldn't measure that in practice. Additionally, this change also reduces the binary size (because of the omitted else branch). Since this code is inlined fairly often, the impact is measurable: the binary size is reduced by 50kb. --- source/blender/blenlib/BLI_vector.hh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/source/blender/blenlib/BLI_vector.hh b/source/blender/blenlib/BLI_vector.hh index 67f83264db3..27b7708f21e 100644 --- a/source/blender/blenlib/BLI_vector.hh +++ b/source/blender/blenlib/BLI_vector.hh @@ -243,7 +243,9 @@ class Vector { const int64_t size = other.size(); if (other.is_inline()) { - if (size <= InlineBufferCapacity) { + /* This first check is not strictly necessary, but improves performance because it can be + * done at compile time and makes the size check at run-time unnecessary. */ + if (OtherInlineBufferCapacity <= InlineBufferCapacity || size <= InlineBufferCapacity) { /* Copy between inline buffers. */ uninitialized_relocate_n(other.begin_, size, begin_); end_ = begin_ + size;