Commit d4c8569
Stop reading
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: 79b06256e8e6e245bcd050a5faa666202fa7a068buttons back out of the pointer payload under construction (#58297)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
Lines changed: 3 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
204 | 204 | | |
205 | 205 | | |
206 | 206 | | |
207 | | - | |
| 207 | + | |
| 208 | + | |
208 | 209 | | |
209 | 210 | | |
210 | 211 | | |
211 | 212 | | |
212 | 213 | | |
213 | | - | |
| 214 | + | |
214 | 215 | | |
215 | 216 | | |
216 | 217 | | |
| |||
0 commit comments