Skip to content

Commit

Permalink
remove useless bitwise comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
rusher committed Mar 21, 2018
1 parent 6a043ed commit 3e7aa33
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
2 changes: 2 additions & 0 deletions benchmarks/benchmarkOne.js
@@ -1,3 +1,5 @@
"use strict";

var fs = require("fs");
var Bench = require("./common_benchmarks");
var bench;
Expand Down
2 changes: 2 additions & 0 deletions benchmarks/benchmarks.js
@@ -1,3 +1,5 @@
"use strict";

const fs = require("fs");
const Bench = require("./common_benchmarks");
let bench;
Expand Down
3 changes: 2 additions & 1 deletion benchmarks/common_benchmarks.js
@@ -1,4 +1,5 @@
const Benchmark = require("benchmark");
"use strict";

const conf = require("../test/conf");

const colors = require("colors");
Expand Down
18 changes: 10 additions & 8 deletions src/io/Packet.js
Expand Up @@ -32,25 +32,27 @@ class Packet {
}

readUInt16() {
return this.buf[this.off++] | (this.buf[this.off++] << 8);
return this.buf[this.off++] + (this.buf[this.off++] << 8);
}

readUInt24() {
return this.buf[this.off++] | (this.buf[this.off++] << 8) | (this.buf[this.off++] << 16);
return this.buf[this.off++] + (this.buf[this.off++] << 8) + (this.buf[this.off++] << 16);
}

readUInt32() {
return (
(this.buf[this.off++] | (this.buf[this.off++] << 8) | (this.buf[this.off++] << 16)) +
this.buf[this.off++] +
(this.buf[this.off++] << 8) +
(this.buf[this.off++] << 16) +
this.buf[this.off++] * 0x1000000
);
}

readInt32() {
return (
this.buf[this.off++] |
(this.buf[this.off++] << 8) |
(this.buf[this.off++] << 16) |
this.buf[this.off++] +
(this.buf[this.off++] << 8) +
(this.buf[this.off++] << 16) +
(this.buf[this.off++] << 24)
);
}
Expand Down Expand Up @@ -117,7 +119,7 @@ class Packet {
}

readSignedLength() {
const type = this.readUInt8();
const type = this.buf[this.off++];
switch (type) {
case 0xfb:
return null;
Expand All @@ -133,7 +135,7 @@ class Packet {
}

readUnsignedLength() {
const type = this.readUInt8();
const type = this.buf[this.off++];
switch (type) {
case 0xfb:
return null;
Expand Down

0 comments on commit 3e7aa33

Please sign in to comment.