From 068d38d832cc1afdd79d8cf08d61ca39169ccb20 Mon Sep 17 00:00:00 2001 From: Artem Chudinov Date: Thu, 20 Aug 2015 04:24:56 +0500 Subject: [PATCH] Use RegExp.prototype.test instead of String.prototype.match where it is OK There is no sense in using String.prototype.match if the retrieved matched results are not used. By the way, if a bit of performance (especially RAM usage) is preferred over unification, then, obviously, conditions like if (/SIGNED MESSAGE/.test(header[1])) { can be changed to if (header[1].indexOf('SIGNED MESSAGE') !== -1) { --- src/encoding/armor.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/encoding/armor.js b/src/encoding/armor.js index ca59bbab..e807deeb 100644 --- a/src/encoding/armor.js +++ b/src/encoding/armor.js @@ -49,14 +49,14 @@ function getType(text) { // BEGIN PGP MESSAGE, PART X/Y // Used for multi-part messages, where the armor is split amongst Y // parts, and this is the Xth part out of Y. - if (header[1].match(/MESSAGE, PART \d+\/\d+/)) { + if (/MESSAGE, PART \d+\/\d+/.test(header[1])) { return enums.armor.multipart_section; } else // BEGIN PGP MESSAGE, PART X // Used for multi-part messages, where this is the Xth part of an // unspecified number of parts. Requires the MESSAGE-ID Armor // Header to be used. - if (header[1].match(/MESSAGE, PART \d+/)) { + if (/MESSAGE, PART \d+/.test(header[1])) { return enums.armor.multipart_last; } else @@ -64,25 +64,25 @@ function getType(text) { // Used for detached signatures, OpenPGP/MIME signatures, and // cleartext signatures. Note that PGP 2.x uses BEGIN PGP MESSAGE // for detached signatures. - if (header[1].match(/SIGNED MESSAGE/)) { + if (/SIGNED MESSAGE/.test(header[1])) { return enums.armor.signed; } else // BEGIN PGP MESSAGE // Used for signed, encrypted, or compressed files. - if (header[1].match(/MESSAGE/)) { + if (/MESSAGE/.test(header[1])) { return enums.armor.message; } else // BEGIN PGP PUBLIC KEY BLOCK // Used for armoring public keys. - if (header[1].match(/PUBLIC KEY BLOCK/)) { + if (/PUBLIC KEY BLOCK/.test(header[1])) { return enums.armor.public_key; } else // BEGIN PGP PRIVATE KEY BLOCK // Used for armoring private keys. - if (header[1].match(/PRIVATE KEY BLOCK/)) { + if (/PRIVATE KEY BLOCK/.test(header[1])) { return enums.armor.private_key; } } @@ -240,7 +240,7 @@ function splitHeaders(text) { */ function verifyHeaders(headers) { for (var i = 0; i < headers.length; i++) { - if (!headers[i].match(/^(Version|Comment|MessageID|Hash|Charset): .+$/)) { + if (!/^(Version|Comment|MessageID|Hash|Charset): .+$/.test(headers[i])) { throw new Error('Improperly formatted armor header: ' + headers[i]); } } @@ -316,7 +316,7 @@ function dearmor(text) { var sig_sum = splitChecksum(sig.body); result = { - text: msg.body.replace(/\n$/, '').replace(/\n/g, "\r\n"), + text: msg.body.replace(/\n$/, '').replace(/\n/g, "\r\n"), data: base64.decode(sig_sum.body), headers: msg.headers, type: type