mirror of
https://github.com/zhigang1992/react-native-web.git
synced 2026-01-12 17:43:00 +08:00
[fix] improve style resolver performance
Script time in the benchmark was profiled by adding `console.profile` around the timings for script time. The call to Array.join in the resolve function stood out. Since the code already iterates over the array it can run slightly faster by building the cache key in that loop instead. Close #1213
This commit is contained in:
committed by
Nicolas Gallagher
parent
d0ac55aa4f
commit
2b77bfd853
@@ -84,15 +84,19 @@ export default class ReactNativeStyleResolver {
|
|||||||
// otherwise fallback to resolving
|
// otherwise fallback to resolving
|
||||||
const flatArray = flattenArray(style);
|
const flatArray = flattenArray(style);
|
||||||
let isArrayOfNumbers = true;
|
let isArrayOfNumbers = true;
|
||||||
|
let cacheKey = '';
|
||||||
for (let i = 0; i < flatArray.length; i++) {
|
for (let i = 0; i < flatArray.length; i++) {
|
||||||
const id = flatArray[i];
|
const id = flatArray[i];
|
||||||
if (typeof id !== 'number') {
|
if (typeof id !== 'number') {
|
||||||
isArrayOfNumbers = false;
|
isArrayOfNumbers = false;
|
||||||
} else {
|
} else {
|
||||||
|
if (isArrayOfNumbers) {
|
||||||
|
cacheKey += (id + '-');
|
||||||
|
}
|
||||||
this._injectRegisteredStyle(id);
|
this._injectRegisteredStyle(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const key = isArrayOfNumbers ? createCacheKey(flatArray.join('-')) : null;
|
const key = isArrayOfNumbers ? createCacheKey(cacheKey) : null;
|
||||||
return this._resolveStyleIfNeeded(flatArray, key);
|
return this._resolveStyleIfNeeded(flatArray, key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user