From 2e941e51f0b15d74a7b08822d4f0181625031fd6 Mon Sep 17 00:00:00 2001 From: Gregory Moskaliuk Date: Fri, 30 Oct 2026 10:30:12 +0100 Subject: [PATCH] Compare prop name pointers before their characters in RawPropsParser On the in-order path of `RawPropsParser::at`, every lookup compared the requested prop name with the expected key using `std::string_view` equality, which runs `memcmp`. Props constructors pass the same string literal for a prop on every parse, and that literal is what the parser stored when it was prepared, so the two views usually point to the same characters. Check the pointers first and fall back to comparing the characters when they differ. Co-Authored-By: Claude Opus 5.5 --- .../react/renderer/core/RawPropsParser.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/react-native/ReactCommon/react/renderer/core/RawPropsParser.cpp b/packages/react-native/ReactCommon/react/renderer/core/RawPropsParser.cpp index 1bf4bf4ae85b..bef5aa2839b0 100644 --- a/packages/react-native/ReactCommon/react/renderer/core/RawPropsParser.cpp +++ b/packages/react-native/ReactCommon/react/renderer/core/RawPropsParser.cpp @@ -14,6 +14,17 @@ namespace facebook::react { +namespace { + +// Same as `a == b`. Props constructors pass the same string literal for a key +// on every parse, so `a` usually points to the characters stored for that key +// when the parser was prepared; comparing the pointers first skips `memcmp`. +inline bool keysEqual(std::string_view a, std::string_view b) noexcept { + return a.data() == b.data() ? a.size() == b.size() : a == b; +} + +} // namespace + // During parser initialization, Props structs are used to parse // "fake"/empty objects, and `at` is called repeatedly which tells us // which props are accessed during parsing, and in which order. @@ -81,7 +92,7 @@ const RawValue* RawPropsParser::at( #endif rawProps.keyIndexCursor_ = 0; } - } while (key != keys_[rawProps.keyIndexCursor_]); + } while (!keysEqual(key, keys_[rawProps.keyIndexCursor_])); auto valueIndex = rawProps.keyIndexToValueIndex_[rawProps.keyIndexCursor_]; return valueIndex == kRawPropsValueIndexEmpty ? nullptr