Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 5 additions & 3 deletions benchmark/buffers/buffer-copy.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@ const common = require('../common.js');
const bench = common.createBenchmark(main, {
bytes: [0, 8, 128, 32 * 1024],
partial: ['true', 'false'],
oob: ['true', 'false'],
Comment thread
BridgeAR marked this conversation as resolved.
Outdated
n: [6e6]
});

function main({ n, bytes, partial }) {
function main({ n, bytes, partial, oob }) {
const source = Buffer.allocUnsafe(bytes);
const target = Buffer.allocUnsafe(bytes);
const target = Buffer.allocUnsafe(bytes * 2);
const sourceStart = (partial === 'true' ? Math.floor(bytes / 2) : 0);
const sourceEnd = (oob === 'true' ? source.length + 1 : source.length);
bench.start();
for (let i = 0; i < n; i++) {
source.copy(target, 0, sourceStart);
source.copy(target, 0, sourceStart, sourceEnd);
}
bench.end(n);
}
2 changes: 1 addition & 1 deletion lib/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ function _copyActual(source, target, targetStart, sourceStart, sourceEnd) {
if (nb > sourceLen)
nb = sourceLen;

if (sourceStart !== 0 || sourceEnd !== source.length)
if (sourceStart !== 0 || sourceEnd < source.length)
source = new Uint8Array(source.buffer, source.byteOffset + sourceStart, nb);

target.set(source, targetStart);
Expand Down