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": case "ObjectExpression":
node.type = "ObjectPattern"; node.type = "ObjectPattern";
for (let index = 0; index < node.properties.length; index++) { for (
const prop = node.properties[index]; let i = 0, length = node.properties.length, last = length - 1;
const isLast = index === node.properties.length - 1; i < length;
i++
) {
const prop = node.properties[i];
const isLast = i === last;
this.toAssignableObjectExpressionProp(prop, isBinding, isLast); this.toAssignableObjectExpressionProp(prop, isBinding, isLast);
} }
break; 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. // rare.
function isInAstralSet(code: number, set: $ReadOnlyArray<number>): boolean { function isInAstralSet(code: number, set: $ReadOnlyArray<number>): boolean {
let pos = 0x10000; 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]; pos += set[i];
if (pos > code) return false; if (pos > code) return false;