perf: precalculate length

This commit is contained in:
Daniel Tschinder 2019-01-15 12:56:24 -08:00
parent 59c4bbb4ab
commit 48fd387779
2 changed files with 8 additions and 4 deletions

View File

@ -56,9 +56,13 @@ export default class LValParser extends NodeUtils {
case "ObjectExpression":
node.type = "ObjectPattern";
for (let index = 0; index < node.properties.length; index++) {
const prop = node.properties[index];
const isLast = index === node.properties.length - 1;
for (
let i = 0, length = node.properties.length, last = length - 1;
i < length;
i++
) {
const prop = node.properties[i];
const isLast = i === last;
this.toAssignableObjectExpressionProp(prop, isBinding, isLast);
}
break;

View File

@ -64,7 +64,7 @@ const astralIdentifierCodes = [509,0,227,0,150,4,294,9,1368,2,2,1,6,3,41,2,5,0,1
// rare.
function isInAstralSet(code: number, set: $ReadOnlyArray<number>): boolean {
let pos = 0x10000;
for (let i = 0; i < set.length; i += 2) {
for (let i = 0, length = set.length; i < length; i += 2) {
pos += set[i];
if (pos > code) return false;