From 6ae981ba6e10ee67bf5c3827e8b231f7755855da Mon Sep 17 00:00:00 2001 From: Eric Rozell Date: Wed, 30 Oct 2024 07:39:21 -0700 Subject: [PATCH] Use static values for undefined and auto lengths (#1030) Summary: X-link: https://github.com/facebook/react-native/pull/47305 X-link: https://github.com/facebook/yoga/pull/1734 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, mdvacca Differential Revision: D65207753 --- lib/yoga/src/main/cpp/yoga/style/StyleValuePool.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/yoga/src/main/cpp/yoga/style/StyleValuePool.h b/lib/yoga/src/main/cpp/yoga/style/StyleValuePool.h index 597eae4c437..ddb0d253630 100644 --- a/lib/yoga/src/main/cpp/yoga/style/StyleValuePool.h +++ b/lib/yoga/src/main/cpp/yoga/style/StyleValuePool.h @@ -49,9 +49,11 @@ class StyleValuePool { StyleLength getLength(StyleValueHandle handle) const { if (handle.isUndefined()) { - return StyleLength::undefined(); + static const StyleLength undefined = StyleLength::undefined(); + return undefined; } else if (handle.isAuto()) { - return StyleLength::ofAuto(); + static const StyleLength ofAuto = StyleLength::ofAuto(); + return ofAuto; } else { assert( handle.type() == StyleValueHandle::Type::Point ||