Permalink
Browse files

Other: Updated test cases to use new buffer util

  • Loading branch information...
dcodeIO committed Jan 28, 2017
1 parent 0be01a1 commit 579068a45e285c7d2c69b359716dd6870352f46f
Showing with 10 additions and 11 deletions.
  1. +2 −2 bench/alloc.js
  2. +3 −8 bench/index.js
  3. +5 −1 lib/fetch/tests/index.js
@@ -2,9 +2,9 @@
"use strict";
var newSuite = require("./suite"),
pool = require("../src/util/pool");
protobuf = require("..");
var poolAlloc = pool(function(size) {
var poolAlloc = protobuf.util.pool(function(size) {
return new Uint8Array(size);
}, Uint8Array.prototype.subarray);
@@ -39,15 +39,10 @@ for (i = 0; i < 500000; ++i)
Test.verify(data);
process.stdout.write("\n");
if (!Buffer.from)
Buffer.from = function from(str, enc) {
return new Buffer(str, enc);
};
// give the optimizer some time to do its job
setTimeout(function() {
var str = JSON.stringify(data),
strbuf = Buffer.from(str, "utf8");
strbuf = protobuf.util._Buffer_from(str, "utf8");
newSuite("encoding")
.add("Type.encode to buffer", function() {
@@ -57,7 +52,7 @@ setTimeout(function() {
JSON.stringify(data);
})
.add("JSON.stringify to buffer", function() {
Buffer.from(JSON.stringify(data), "utf8");
protobuf.util._Buffer_from(JSON.stringify(data), "utf8");
})
.run();
@@ -81,7 +76,7 @@ setTimeout(function() {
JSON.parse(JSON.stringify(data));
})
.add("JSON to/from buffer", function() {
JSON.parse(Buffer.from(JSON.stringify(data), "utf8").toString("utf8"));
JSON.parse(protobuf.util._Buffer_from(JSON.stringify(data), "utf8").toString("utf8"));
})
.run();
@@ -144,7 +144,11 @@ function fakeXHR(status, ancient) {
self.status = status;
if (self.responseType === "arraybuffer" && !ancient) {
var buf = new Buffer(self._path, "utf8");
self.response = buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength);
var abuf = new ArrayBuffer(buf.length);
var view = new Uint8Array(abuf);
for (var i = 0; i < buf.length; ++i)
view[i] = buf[i];
self.response = abuf;
} else
self.responseText = self._path;
self.onreadystatechange();

0 comments on commit 579068a

Please sign in to comment.