Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
ronag committed Aug 10, 2024
1 parent ec3482d commit dc3948d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions benchmark/buffers/buffer-write-string.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
const common = require('../common.js');
const bench = common.createBenchmark(main, {
encoding: [
'', 'utf8', 'ascii', 'hex', 'utf16le', 'latin1',
'',
],
args: [ '', 'offset', 'offset+length' ],
len: [2048],
args: [ '' ],
len: [1,8,16,32,128],

Check failure on line 9 in benchmark/buffers/buffer-write-string.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

A space is required after ','

Check failure on line 9 in benchmark/buffers/buffer-write-string.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

A space is required after ','

Check failure on line 9 in benchmark/buffers/buffer-write-string.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

A space is required after ','

Check failure on line 9 in benchmark/buffers/buffer-write-string.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

A space is required after ','
n: [1e6],
});

Expand Down
10 changes: 5 additions & 5 deletions lib/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1082,10 +1082,9 @@ function _fill(buf, value, offset, end, encoding) {
Buffer.prototype.write = function write(string, offset, length, encoding) {
// Buffer#write(string);
if (offset === undefined) {
return this.utf8Write(string, 0, this.length);
}
// Do nothing
// Buffer#write(string, encoding)
if (length === undefined && typeof offset === 'string') {
} else if (length === undefined && typeof offset === 'string') {
encoding = offset;
length = this.length;
offset = 0;
Expand All @@ -1109,15 +1108,16 @@ Buffer.prototype.write = function write(string, offset, length, encoding) {
}

const len = string.length;
if (len <= 16 && len <= length) {
if (len <= 16 && len <= length && (!encoding || encoding === 'ascii' || encoding === 'utf8')) {
let n = 0;
let pos = offset ?? 0;

Check failure on line 1113 in lib/buffer.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

'pos' is never reassigned. Use 'const' instead
while (true) {
const code = StringPrototypeCharCodeAt(string, n);
if (code >= 128) {
break;
}

this[offset + n] = code;
this[pos + n] = code;
n++;

if (n === len) {
Expand Down

0 comments on commit dc3948d

Please sign in to comment.