Skip to content

Commit

Permalink
Other: Updated test cases to use new buffer util
Browse files Browse the repository at this point in the history
  • Loading branch information
dcodeIO committed Jan 28, 2017
1 parent 0be01a1 commit 579068a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
4 changes: 2 additions & 2 deletions bench/alloc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
11 changes: 3 additions & 8 deletions bench/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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();

Expand All @@ -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();

Expand Down
6 changes: 5 additions & 1 deletion lib/fetch/tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 579068a

Please sign in to comment.