Use toFastProperties to speed up t.* method access
This commit is contained in:
14
lib/6to5/to-fast-properties.js
Normal file
14
lib/6to5/to-fast-properties.js
Normal 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);
|
||||
};
|
||||
@@ -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);
|
||||
Reference in New Issue
Block a user