From 9179df93af90199720f901145b37c2b43b26963c Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Thu, 22 Oct 2015 13:58:48 -0700 Subject: [PATCH] strict equals (linting + minor speed enhancement) strict equals checking slightly improves performance in many javascript engines http://www.adequatelygood.com/Performance-of-vs-.html and it also prevents linters from throwing errors --- lib/thirty-two/thirty-two.js | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/lib/thirty-two/thirty-two.js b/lib/thirty-two/thirty-two.js index 3e4dd6b..26d647e 100644 --- a/lib/thirty-two/thirty-two.js +++ b/lib/thirty-two/thirty-two.js @@ -1,4 +1,4 @@ -/* +/* Copyright (c) 2011, Chris Umbel Permission is hereby granted, free of charge, to any person obtaining a copy @@ -17,7 +17,7 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. +THE SOFTWARE. */ var charTable = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"; @@ -36,7 +36,7 @@ var byteTable = [ function quintetCount(buff) { var quintets = Math.floor(buff.length / 5); - return buff.length % 5 == 0 ? quintets: quintets + 1; + return buff.length % 5 === 0 ? quintets: quintets + 1; } exports.encode = function(plain) { @@ -53,7 +53,7 @@ exports.encode = function(plain) { faster. will have to revisit. */ while(i < plain.length) { var current = plain[i]; - + if(shiftIndex > 3) { digit = current & (0xff >> shiftIndex); shiftIndex = (shiftIndex + 5) % 8; @@ -62,17 +62,17 @@ exports.encode = function(plain) { i++; } else { digit = (current >> (8 - (shiftIndex + 5))) & 0x1f; - shiftIndex = (shiftIndex + 5) % 8; - if(shiftIndex == 0) i++; + shiftIndex = (shiftIndex + 5) % 8; + if(shiftIndex === 0) i++; } - + encoded[j] = charTable.charCodeAt(digit); j++; } for(i = j; i < encoded.length; i++) encoded[i] = 0x3d; //'='.charCodeAt(0) - + return encoded; }; @@ -85,23 +85,23 @@ exports.decode = function(encoded) { encoded = new Buffer(encoded); } var decoded = new Buffer(Math.ceil(encoded.length * 5 / 8)); - + /* byte by byte isn't as pretty as octet by octet but tests a bit - faster. will have to revisit. */ + faster. will have to revisit. */ for(var i = 0; i < encoded.length; i++) { - if(encoded[i] == 0x3d){ //'=' + if(encoded[i] === 0x3d){ //'=' break; } - + var encodedByte = encoded[i] - 0x30; - + if(encodedByte < byteTable.length) { plainDigit = byteTable[encodedByte]; - + if(shiftIndex <= 3) { shiftIndex = (shiftIndex + 5) % 8; - - if(shiftIndex == 0) { + + if(shiftIndex === 0) { plainChar |= plainDigit; decoded[plainPos] = plainChar; plainPos++;