Skip to content

Commit 14af73f

Browse files
committed
Simplify hexWrite
1 parent 1f9cdc9 commit 14af73f

File tree

1 file changed

+3
-14
lines changed

1 file changed

+3
-14
lines changed

index.js

+3-14
Original file line numberDiff line numberDiff line change
@@ -847,21 +847,10 @@ Buffer.prototype.lastIndexOf = function lastIndexOf (val, byteOffset, encoding)
847847
}
848848

849849
function hexWrite (buf, string, offset, length) {
850-
offset = Number(offset) || 0
851-
const remaining = buf.length - offset
852-
if (!length) {
853-
length = remaining
854-
} else {
855-
length = Number(length)
856-
if (length > remaining) {
857-
length = remaining
858-
}
859-
}
860-
861-
const strLen = string.length
850+
const bytes = string.length >>> 1
862851

863-
if (length > (strLen >>> 1)) {
864-
length = strLen >>> 1
852+
if (length > bytes) {
853+
length = bytes
865854
}
866855

867856
for (let i = 0; i < length; ++i) {

0 commit comments

Comments
 (0)