Use toFastProperties to speed up t.* method access

This commit is contained in:
Dan Abramov
2015-01-16 19:48:38 +03:00
parent 76b8945207
commit 938026abeb
2 changed files with 19 additions and 2 deletions

View File

@@ -0,0 +1,14 @@
/**
* A trick from Bluebird to force V8 to use fast properties for an object.
* Read more: http://stackoverflow.com/questions/24987896/
*
* Use %HasFastProperties(obj) and --allow-natives-syntax to check whether
* a particular object already has fast properties.
*/
module.exports = function toFastProperties(obj) {
/*jshint -W027*/
function f() {}
f.prototype = obj;
return f;
eval(obj);
};

View File

@@ -1,5 +1,6 @@
var esutils = require("esutils");
var _ = require("lodash");
var esutils = require("esutils");
var _ = require("lodash");
var toFastProperties = require("../to-fast-properties");
var t = exports;
@@ -573,3 +574,5 @@ t.getSpecifierName = function (specifier) {
t.isSpecifierDefault = function (specifier) {
return t.isIdentifier(specifier.id) && specifier.id.name === "default";
};
toFastProperties(t);