From 0d9a1d99989da562634cd5e95445373bbac71dea Mon Sep 17 00:00:00 2001 From: Eric Rozell Date: Wed, 30 Oct 2024 07:27:17 -0700 Subject: [PATCH] Use static values for undefined and auto lengths Summary: Profiling in a test app with many undefined lengths shows this saves roughly 33% of time spent in Yoga. ## Changelog [General][Fixed] Reduce amount of time spent in Yoga by reusing statically defined values in StyleLength::getLength() Reviewed By: yungsters Differential Revision: D65207753 --- yoga/style/StyleValuePool.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/yoga/style/StyleValuePool.h b/yoga/style/StyleValuePool.h index 597eae4c43..21f42f8cad 100644 --- a/yoga/style/StyleValuePool.h +++ b/yoga/style/StyleValuePool.h @@ -49,9 +49,11 @@ class StyleValuePool { StyleLength getLength(StyleValueHandle handle) const { if (handle.isUndefined()) { - return StyleLength::undefined(); + static StyleLength undefined = StyleLength::undefined(); + return undefined; } else if (handle.isAuto()) { - return StyleLength::ofAuto(); + static StyleLength ofAuto = StyleLength::ofAuto(); + return ofAuto; } else { assert( handle.type() == StyleValueHandle::Type::Point ||