summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorPaul Loyd <pavelko95@gmail.com>2013-12-13 01:16:08 +0400
committerFedor Indutny <fedor.indutny@gmail.com>2013-12-21 01:01:17 +0400
commit2ca69051608f3cdbfa28e65de9ddd326a13cd000 (patch)
treef882573a2639530db789b3135b57349e2827bc78 /lib
parent54da818e4bec4e5a0a1928441ec6fc90b4903ba0 (diff)
downloadnodejs-2ca69051608f3cdbfa28e65de9ddd326a13cd000.tar.gz
nodejs-2ca69051608f3cdbfa28e65de9ddd326a13cd000.tar.bz2
nodejs-2ca69051608f3cdbfa28e65de9ddd326a13cd000.zip
buffer: optimize writeInt* methods
Remove unnecessary encoding within writeInt*
Diffstat (limited to 'lib')
-rw-r--r--lib/buffer.js43
1 files changed, 0 insertions, 43 deletions
diff --git a/lib/buffer.js b/lib/buffer.js
index b43363024..d2d8b528c 100644
--- a/lib/buffer.js
+++ b/lib/buffer.js
@@ -678,50 +678,11 @@ Buffer.prototype.writeUInt32BE = function(value, offset, noAssert) {
return writeUInt32(this, value, offset, true);
};
-
-/*
- * We now move onto our friends in the signed number category. Unlike unsigned
- * numbers, we're going to have to worry a bit more about how we put values into
- * arrays. Since we are only worrying about signed 32-bit values, we're in
- * slightly better shape. Unfortunately, we really can't do our favorite binary
- * & in this system. It really seems to do the wrong thing. For example:
- *
- * > -32 & 0xff
- * 224
- *
- * What's happening above is really: 0xe0 & 0xff = 0xe0. However, the results of
- * this aren't treated as a signed number. Ultimately a bad thing.
- *
- * What we're going to want to do is basically create the unsigned equivalent of
- * our representation and pass that off to the wuint* functions. To do that
- * we're going to do the following:
- *
- * - if the value is positive
- * we can pass it directly off to the equivalent wuint
- * - if the value is negative
- * we do the following computation:
- * mb + val + 1, where
- * mb is the maximum unsigned value in that byte size
- * val is the Javascript negative integer
- *
- *
- * As a concrete value, take -128. In signed 16 bits this would be 0xff80. If
- * you do out the computations:
- *
- * 0xffff - 128 + 1
- * 0xffff - 127
- * 0xff80
- *
- * You can then encode this value as the signed version. This is really rather
- * hacky, but it should work and get the job done which is our goal here.
- */
-
Buffer.prototype.writeInt8 = function(value, offset, noAssert) {
value = +value;
offset = offset >>> 0;
if (!noAssert)
checkInt(this, value, offset, 1, 0x7f, -0x80);
- if (value < 0) value = 0xff + value + 1;
this[offset] = value;
return offset + 1;
};
@@ -732,7 +693,6 @@ Buffer.prototype.writeInt16LE = function(value, offset, noAssert) {
offset = offset >>> 0;
if (!noAssert)
checkInt(this, value, offset, 2, 0x7fff, -0x8000);
- if (value < 0) value = 0xffff + value + 1;
return writeUInt16(this, value, offset, false);
};
@@ -742,7 +702,6 @@ Buffer.prototype.writeInt16BE = function(value, offset, noAssert) {
offset = offset >>> 0;
if (!noAssert)
checkInt(this, value, offset, 2, 0x7fff, -0x8000);
- if (value < 0) value = 0xffff + value + 1;
return writeUInt16(this, value, offset, true);
};
@@ -752,7 +711,6 @@ Buffer.prototype.writeInt32LE = function(value, offset, noAssert) {
offset = offset >>> 0;
if (!noAssert)
checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000);
- if (value < 0) value = 0xffffffff + value + 1;
return writeUInt32(this, value, offset, false);
};
@@ -762,6 +720,5 @@ Buffer.prototype.writeInt32BE = function(value, offset, noAssert) {
offset = offset >>> 0;
if (!noAssert)
checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000);
- if (value < 0) value = 0xffffffff + value + 1;
return writeUInt32(this, value, offset, true);
};