Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[perf] strict equality #52

Merged
merged 1 commit into from
Dec 17, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions binary.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ exports.deconstructPacket = function(packet){
newData[i] = _deconstructPacket(data[i]);
}
return newData;
} else if ('object' == typeof data && !(data instanceof Date)) {
} else if (typeof data === 'object' && !(data instanceof Date)) {
var newData = {};
for (var key in data) {
newData[key] = _deconstructPacket(data[key]);
Expand Down Expand Up @@ -71,7 +71,7 @@ exports.reconstructPacket = function(packet, buffers) {
data[i] = _reconstructPacket(data[i]);
}
return data;
} else if (data && 'object' == typeof data) {
} else if (data && 'object' === typeof data) {
for (var key in data) {
data[key] = _reconstructPacket(data[key]);
}
Expand Down Expand Up @@ -125,7 +125,7 @@ exports.removeBlobs = function(data, callback) {
for (var i = 0; i < obj.length; i++) {
_removeBlobs(obj[i], i, obj);
}
} else if (obj && 'object' == typeof obj && !isBuf(obj)) { // and object
} else if (obj && 'object' === typeof obj && !isBuf(obj)) { // and object
for (var key in obj) {
_removeBlobs(obj[key], key, obj);
}
Expand Down
26 changes: 13 additions & 13 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ function Encoder() {}
Encoder.prototype.encode = function(obj, callback){
debug('encoding packet %j', obj);

if (exports.BINARY_EVENT == obj.type || exports.BINARY_ACK == obj.type) {
if (exports.BINARY_EVENT === obj.type || exports.BINARY_ACK === obj.type) {
encodeAsBinary(obj, callback);
}
else {
Expand All @@ -151,14 +151,14 @@ function encodeAsString(obj) {
str += obj.type;

// attachments if we have them
if (exports.BINARY_EVENT == obj.type || exports.BINARY_ACK == obj.type) {
if (exports.BINARY_EVENT === obj.type || exports.BINARY_ACK === obj.type) {
str += obj.attachments;
str += '-';
}

// if we have a namespace other than `/`
// we append it followed by a comma `,`
if (obj.nsp && '/' != obj.nsp) {
if (obj.nsp && '/' !== obj.nsp) {
nsp = true;
str += obj.nsp;
}
Expand Down Expand Up @@ -233,9 +233,9 @@ Emitter(Decoder.prototype);

Decoder.prototype.add = function(obj) {
var packet;
if ('string' == typeof obj) {
if (typeof obj === 'string') {
packet = decodeString(obj);
if (exports.BINARY_EVENT == packet.type || exports.BINARY_ACK == packet.type) { // binary packet's json
if (exports.BINARY_EVENT === packet.type || exports.BINARY_ACK === packet.type) { // binary packet's json
this.reconstructor = new BinaryReconstructor(packet);

// no attachments, labeled binary but no binary data to follow
Expand Down Expand Up @@ -281,24 +281,24 @@ function decodeString(str) {
// look up attachments if type binary
if (exports.BINARY_EVENT == p.type || exports.BINARY_ACK == p.type) {
var buf = '';
while (str.charAt(++i) != '-') {
while (str.charAt(++i) !== '-') {
buf += str.charAt(i);
if (i == str.length) break;
}
if (buf != Number(buf) || str.charAt(i) != '-') {
if (buf != Number(buf) || str.charAt(i) !== '-') {
throw new Error('Illegal attachments');
}
p.attachments = Number(buf);
}

// look up namespace (if any)
if ('/' == str.charAt(i + 1)) {
if ('/' === str.charAt(i + 1)) {
p.nsp = '';
while (++i) {
var c = str.charAt(i);
if (',' == c) break;
if (',' === c) break;
p.nsp += c;
if (i == str.length) break;
if (i === str.length) break;
}
} else {
p.nsp = '/';
Expand All @@ -315,7 +315,7 @@ function decodeString(str) {
break;
}
p.id += str.charAt(i);
if (i == str.length) break;
if (i === str.length) break;
}
p.id = Number(p.id);
}
Expand All @@ -336,7 +336,7 @@ function tryParse(p, str) {
return error();
}
return p;
};
}

/**
* Deallocates a parser's resources
Expand Down Expand Up @@ -377,7 +377,7 @@ function BinaryReconstructor(packet) {

BinaryReconstructor.prototype.takeBinaryData = function(binData) {
this.buffers.push(binData);
if (this.buffers.length == this.reconPack.attachments) { // done with buffer list
if (this.buffers.length === this.reconPack.attachments) { // done with buffer list
var packet = binary.reconstructPacket(this.reconPack, this.buffers);
this.finishedReconstruction();
return packet;
Expand Down