mirror of
https://github.com/facebook/react-native.git
synced 2026-11-18 20:19:07 +00:00
Stop reading buttons back out of the pointer payload under construction (#58297)
Summary: Pull Request resolved: https://github.com/react/react-native/pull/58297 `PointerEvent.createW3CPointerEvent` built its payload map, then read one field straight back out of that same half-built map to compute another field: ``` pointerEvent.putInt("buttons", getButtons(_eventName, pointerType, buttonState)) ... getPressure(pointerEvent.getInt("buttons"), _eventName) ``` Reading from a `WritableNativeMap` while still writing to it is not free and not safe: - `ReadableNativeMap.getInt` materialises the *whole* map across JNI (`importKeys` + `importValues`) and memoises the result in `keysStorage` / `localMapStorage`. Every subsequent `put*` on the same instance then leaves those caches stale, so a later Kotlin-side read of the map (`hasKey`, `toHashMap`) does not see `pressure`, `tangentialPressure`, `hitPathForEventListener` or the modifier keys. - It happens on the pointer-event hot path, once per pointer index per dispatch, purely to recover a value the caller already has in hand. Keep the value in a local and pass it to `getPressure` directly. The payload is byte-for-byte identical: `getInt` returns exactly the `Int` that `putInt` stored, so `getPressure` receives the same argument as before. Changelog: [Internal] Reviewed By: christophpurrer Differential Revision: D118471070 fbshipit-source-id: 79b06256e8e6e245bcd050a5faa666202fa7a068
This commit is contained in:
1 parent
bdce09d494
commit
d4c85694ac
1 file changed
+3
-2
+3
-2
@@ -204,13 +204,14 @@ internal class PointerEvent private constructor() : Event<PointerEvent>() {
|
||||
"button",
|
||||
getButtonChange(pointerType, eventState.lastButtonState, buttonState),
|
||||
)
|
||||
pointerEvent.putInt("buttons", getButtons(_eventName, pointerType, buttonState))
|
||||
val buttons = getButtons(_eventName, pointerType, buttonState)
|
||||
pointerEvent.putInt("buttons", buttons)
|
||||
|
||||
val pressure =
|
||||
if (isClickEvent) {
|
||||
0.0 // click events need pressure=0
|
||||
} else {
|
||||
getPressure(pointerEvent.getInt("buttons"), _eventName)
|
||||
getPressure(buttons, _eventName)
|
||||
}
|
||||
|
||||
pointerEvent.putDouble("pressure", pressure)
|
||||
|
||||
Reference in new issue
Block a user