Use Map instead of object as map in ReactNativeComponentTree (#16107)
Real Maps should now be used in RN JS engines. In theory this should be faster (but might not actually be in practice), and it avoids hitting upper bounds of property max counts. We don't use these types of Maps in Fabric.
Sebastian Markbåge committed
Jul 10, 2019 at 19:11 UTC
b7669044d9cce79d8ec56c7af6e45caa992aa0b0
1 file changed
+8
-8
packages/react-native-renderer/src/ReactNativeComponentTree.js
+8
-8
@@ -7,20 +7,20 @@
7
8
import invariant from 'shared/invariant';
9
10
-const instanceCache = {};
11
-const instanceProps = {};
10
+const instanceCache = new Map();
11
+const instanceProps = new Map();
12
13
export function precacheFiberNode(hostInst, tag) {
14
- instanceCache[tag] = hostInst;
14
+ instanceCache.set(tag, hostInst);
15
}
16
17
export function uncacheFiberNode(tag) {
18
- delete instanceCache[tag];
19
- delete instanceProps[tag];
18
+ instanceCache.delete(tag);
19
+ instanceProps.delete(tag);
20
}
21
22
function getInstanceFromTag(tag) {
23
- return instanceCache[tag] || null;
23
+ return instanceCache.get(tag) || null;
24
}
25
26
function getTagFromInstance(inst) {
@@ -39,9 +39,9 @@ export {
39
};
40
41
export function getFiberCurrentPropsFromNode(stateNode) {
42
- return instanceProps[stateNode._nativeTag] || null;
42
+ return instanceProps.get(stateNode._nativeTag) || null;
43
}
44
45
export function updateFiberProps(tag, props) {
46
- instanceProps[tag] = props;
46
+ instanceProps.set(tag, props);
47
}