Skip to content

Commit d4c8569

Browse files
generatedunixname1608173377072046meta-codesync[bot]
authored andcommitted
Stop reading buttons back out of the pointer payload under construction (#58297)
Summary: Pull Request resolved: #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
1 parent bdce09d commit d4c8569

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

  • packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/events

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/events/PointerEvent.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,13 +204,14 @@ internal class PointerEvent private constructor() : Event<PointerEvent>() {
204204
"button",
205205
getButtonChange(pointerType, eventState.lastButtonState, buttonState),
206206
)
207-
pointerEvent.putInt("buttons", getButtons(_eventName, pointerType, buttonState))
207+
val buttons = getButtons(_eventName, pointerType, buttonState)
208+
pointerEvent.putInt("buttons", buttons)
208209

209210
val pressure =
210211
if (isClickEvent) {
211212
0.0 // click events need pressure=0
212213
} else {
213-
getPressure(pointerEvent.getInt("buttons"), _eventName)
214+
getPressure(buttons, _eventName)
214215
}
215216

216217
pointerEvent.putDouble("pressure", pressure)

0 commit comments

Comments
 (0)