Skip to content

Commit

Permalink
crypto: make createXYZ inlineable
Browse files Browse the repository at this point in the history
This commit increase by around 10% hot code paths that are hitting
createXYZ functions. Before this change the createXYZ called the XYZ
constructor without new.

PR-URL: #16067
Reviewed-By: Bryan English <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Yosuke Furukawa <[email protected]>
Reviewed-By: Evan Lucas <[email protected]>
Reviewed-By: Benedikt Meurer <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Timothy Gu <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
  • Loading branch information
mcollina committed Oct 9, 2017
1 parent 9f98989 commit 9bc4f86
Showing 1 changed file with 58 additions and 12 deletions.
70 changes: 58 additions & 12 deletions lib/crypto.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,23 +79,69 @@ const {
} = require('internal/crypto/util');
const Certificate = require('internal/crypto/certificate');

// These helper functions are needed because the constructors can
// use new, in which case V8 cannot inline the recursive constructor call
function createHash(algorithm, options) {
return new Hash(algorithm, options);
}

function createCipher(cipher, password, options) {
return new Cipher(cipher, password, options);
}

function createCipheriv(cipher, key, iv, options) {
return new Cipheriv(cipher, key, iv, options);
}

function createDecipher(cipher, password, options) {
return new Decipher(cipher, password, options);
}

function createDecipheriv(cipher, key, iv, options) {
return new Decipheriv(cipher, key, iv, options);
}

function createDiffieHellman(sizeOrKey, keyEncoding, generator, genEncoding) {
return new DiffieHellman(sizeOrKey, keyEncoding, generator, genEncoding);
}

function createDiffieHellmanGroup(name) {
return new DiffieHellmanGroup(name);
}

function createECDH(curve) {
return new ECDH(curve);
}

function createHmac(hmac, key, options) {
return new Hmac(hmac, key, options);
}

function createSign(algorithm, options) {
return new Sign(algorithm, options);
}

function createVerify(algorithm, options) {
return new Verify(algorithm, options);
}

module.exports = exports = {
// Methods
_toBuf: toBuf,
createCipher: Cipher,
createCipheriv: Cipheriv,
createDecipher: Decipher,
createDecipheriv: Decipheriv,
createDiffieHellman: DiffieHellman,
createDiffieHellmanGroup: DiffieHellmanGroup,
createECDH: ECDH,
createHash: Hash,
createHmac: Hmac,
createSign: Sign,
createVerify: Verify,
createCipher,
createCipheriv,
createDecipher,
createDecipheriv,
createDiffieHellman,
createDiffieHellmanGroup,
createECDH,
createHash,
createHmac,
createSign,
createVerify,
getCiphers,
getCurves,
getDiffieHellman: DiffieHellmanGroup,
getDiffieHellman: createDiffieHellmanGroup,
getHashes,
pbkdf2,
pbkdf2Sync,
Expand Down

0 comments on commit 9bc4f86

Please sign in to comment.