Skip to content

Commit

Permalink
Use static values for undefined and auto lengths (facebook#1030)
Browse files Browse the repository at this point in the history
Summary:
X-link: facebook/react-native#47305

X-link: facebook/yoga#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
  • Loading branch information
rozele authored and facebook-github-bot committed Oct 30, 2024
1 parent d4e82f9 commit 6ae981b
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/yoga/src/main/cpp/yoga/style/StyleValuePool.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 ||
Expand Down

0 comments on commit 6ae981b

Please sign in to comment.