Skip to content

Commit 1fc83cf

Browse files
committed
refactor: use FNV-1a hashing for calc expression property identification
1 parent a6fd5ba commit 1fc83cf

File tree

7 files changed

+109
-345
lines changed

7 files changed

+109
-345
lines changed

packages/react-native/ReactCommon/react/renderer/components/view/YogaLayoutableShadowNode.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -903,12 +903,11 @@ YGValue YogaLayoutableShadowNode::yogaNodeCalcValueResolver(
903903

904904
auto& node = shadowNodeFromContext(yogaNode);
905905
auto& props = static_cast<const YogaStylableProps&>(*node.props_);
906-
auto key = static_cast<CalcExpressionPropertyID>(id);
907-
if (!props.calcExpressions.contains(key)) {
906+
if (!props.calcExpressions.contains(id)) {
908907
return {};
909908
}
910-
911-
auto& calc = props.calcExpressions.at(key);
909+
910+
auto& calc = props.calcExpressions.at(id);
912911
return YGValue(
913912
calc.resolve(
914913
context.referenceLength,

packages/react-native/ReactCommon/react/renderer/components/view/YogaStylableProps.cpp

Lines changed: 92 additions & 290 deletions
Large diffs are not rendered by default.

packages/react-native/ReactCommon/react/renderer/components/view/primitives.h

Lines changed: 2 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <bitset>
1818
#include <cmath>
1919
#include <optional>
20+
#include <unordered_map>
2021

2122
namespace facebook::react {
2223

@@ -249,46 +250,6 @@ struct BorderMetrics {
249250
bool operator==(const BorderMetrics &rhs) const = default;
250251
};
251252

252-
enum class CalcExpressionPropertyID : uint8_t {
253-
Width,
254-
Height,
255-
MinWidth,
256-
MinHeight,
257-
MaxWidth,
258-
MaxHeight,
259-
FlexBasis,
260-
RowGap,
261-
ColumnGap,
262-
Gap,
263-
Left,
264-
Top,
265-
Right,
266-
Bottom,
267-
Start,
268-
End,
269-
InsetInline,
270-
InsetBlock,
271-
Inset,
272-
MarginLeft,
273-
MarginTop,
274-
MarginRight,
275-
MarginBottom,
276-
MarginStart,
277-
MarginEnd,
278-
MarginHorizontal,
279-
MarginVertical,
280-
MarginAll,
281-
PaddingLeft,
282-
PaddingTop,
283-
PaddingRight,
284-
PaddingBottom,
285-
PaddingStart,
286-
PaddingEnd,
287-
PaddingHorizontal,
288-
PaddingVertical,
289-
PaddingAll,
290-
};
291-
292-
using CalcExpressions = std::unordered_map<CalcExpressionPropertyID, CSSCalc>;
253+
using CalcExpressions = std::unordered_map<uint32_t, CSSCalc>;
293254

294255
} // namespace facebook::react

packages/react-native/ReactCommon/yoga/yoga/YGValue.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ YG_EXPORT bool YGFloatIsUndefined(float value);
5858
/**
5959
* Host-defined identifier for a dynamic style value.
6060
*/
61-
typedef uint8_t YGValueDynamicID;
61+
typedef uint32_t YGValueDynamicID;
6262

6363
/**
6464
* Layout context passed to YGValueDynamic for resolving dynamic values.
@@ -77,14 +77,6 @@ typedef YGValue (*YGValueDynamic)(
7777
YGValueDynamicID id,
7878
YGValueDynamicContext context);
7979

80-
/**
81-
* Callback + identifier pair for internal storage.
82-
*/
83-
struct YGValueDynamicData {
84-
YGValueDynamic callback;
85-
YGValueDynamicID id;
86-
};
87-
8880
YG_EXTERN_C_END
8981

9082
// Equality operators for comparison of YGValue in C++

packages/react-native/ReactCommon/yoga/yoga/style/StyleLength.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,11 @@ class StyleLength {
147147
}
148148

149149
private:
150+
struct YGValueDynamicData {
151+
YGValueDynamic callback;
152+
YGValueDynamicID id;
153+
};
154+
150155
union Payload {
151156
constexpr Payload() : value{} {}
152157
constexpr explicit Payload(FloatOptional val) : value(val) {}

packages/react-native/ReactCommon/yoga/yoga/style/StyleSizeLength.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,11 @@ class StyleSizeLength {
178178
}
179179

180180
private:
181+
struct YGValueDynamicData {
182+
YGValueDynamic callback;
183+
YGValueDynamicID id;
184+
};
185+
181186
union Payload {
182187
constexpr Payload() : value{} {}
183188
constexpr explicit Payload(FloatOptional val) : value(val) {}

packages/react-native/ReactCommon/yoga/yoga/style/StyleValuePool.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ class StyleValuePool {
200200
YGValueDynamicID getDynamicCallbackID(StyleValueHandle handle) const {
201201
assert(handle.isDynamic());
202202
assert(handle.isValueIndexed());
203-
return static_cast<uint8_t>(buffer_.get32(handle.value() + 2));
203+
return buffer_.get32(handle.value() + 2);
204204
}
205205

206206
static constexpr bool isIntegerPackable(float f) {

0 commit comments

Comments
 (0)