Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
QHash: fix small performance regression when detaching with resize
There are two QHashPrivate::Data constructors (and two overloads of ::detached()). Initially the Data ctor that takes a new size always assumed a resize was happening, and any place where there _may_ be a resize we would usually detach then rehash. In an effort to avoid the detach+rehash and instead call detach(d, size) without the performance overhead of rehashing the call to reallocationHelper() in this overload of the ctor was changed to verify that a rehash was actually needed. This had the unfortunate side-effect of making the compiler no longer inline the reallocationHelper() function, and it no longer expanded the if-expression with the constant so it was doing a tight copy-loop with a potential branch in the middle. In this patch we revert that and make the bool a template argument to highlight that it should be a constant for better performance (but also leaving a comment.) Also mark it Q_ALWAYS_INLINE, it has two uses and they both take advantage of the inlining + expanding the expression. In theory this might have had an impact on QHash::reserve() calls, though this code is only relevant when reserve() would cause growth so the performance regression would hopefully be small compared to all the other work that would also be needed. Reverts 45c137d Change-Id: I0d2076a9ded8ca816c54d6ce42d472a23bcbc9fd Reviewed-by: Lars Knoll <[email protected]> Reviewed-by: Thiago Macieira <[email protected]> (cherry picked from commit 6c8b6ac) Reviewed-by: Qt Cherry-pick Bot <[email protected]> (cherry picked from commit d53feb3)
- Loading branch information