Browse Source

Ensure we are nearly always in fast mode on V8

See: https://stackoverflow.com/a/24989927/1518408
master
Futago-za Ryuu 4 years ago
parent
commit
27ec5ed9b1
  1. 3
      lib/compiler/visitor.js
  2. 21
      lib/util/objects.js
  3. 2
      src/parser.pegjs

3
lib/compiler/visitor.js

@ -18,8 +18,9 @@ class ASTVisitor {
// Simple AST node visitor builder for PEG.js
static build( functions ) {
const visitor = new ASTVisitor();
let visitor = new ASTVisitor();
util.extend( visitor, functions );
visitor = util.enforceFastProperties( visitor );
return visitor.visit.bind( visitor );
}

21
lib/util/objects.js

@ -109,6 +109,27 @@ const objects = {
},
// Will ensure on V8 that that property access is always in fast mode
// See: https://stackoverflow.com/a/24989927/1518408
enforceFastProperties( o ) {
/* eslint no-unreachable: 0 */
function Sub() { }
Sub.prototype = o;
const receiver = new Sub();
function ic() {
return typeof receiver.foo;
}
ic();
ic();
return o;
eval( "o" + o );
},
};
module.exports = objects;

2
src/parser.pegjs

@ -93,7 +93,7 @@
function createNode( type, details ) {
const node = new ast.Node( type, location() );
util.extend( node, details );
return node;
return util.enforceFastProperties( node );
}
}

Loading…
Cancel
Save