Skip to content

Commit b5742b6

Browse files
committed
Optimize asciiWrite
1 parent 14af73f commit b5742b6

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

index.js

+9-10
Original file line numberDiff line numberDiff line change
@@ -874,7 +874,15 @@ function utf8Write (buf, string, offset, length) {
874874
}
875875

876876
function asciiWrite (buf, string, offset, length) {
877-
return blitBuffer(asciiToBytes(string), buf, offset, length)
877+
if (length > string.length) {
878+
length = string.length
879+
}
880+
881+
for (let i = 0; i < length; i++) {
882+
buf[offset + i] = string.charCodeAt(i)
883+
}
884+
885+
return length
878886
}
879887

880888
function base64Write (buf, string, offset, length) {
@@ -2049,15 +2057,6 @@ function utf8ToBytes (string, units) {
20492057
return bytes
20502058
}
20512059

2052-
function asciiToBytes (str) {
2053-
const byteArray = []
2054-
for (let i = 0; i < str.length; ++i) {
2055-
// Node's code seems to be doing this and not & 0x7F..
2056-
byteArray.push(str.charCodeAt(i) & 0xFF)
2057-
}
2058-
return byteArray
2059-
}
2060-
20612060
function utf16leToBytes (str, units) {
20622061
let c, hi, lo
20632062
const byteArray = []

0 commit comments

Comments
 (0)