Skip to content

Commit 01abbf8

Browse files
committed
Optimize asciiWrite
1 parent dc9fd07 commit 01abbf8

1 file changed

Lines changed: 9 additions & 10 deletions

File tree

index.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,15 @@ function utf8Write (buf, string, offset, length) {
869869
}
870870

871871
function asciiWrite (buf, string, offset, length) {
872-
return blitBuffer(asciiToBytes(string), buf, offset, length)
872+
if (length > string.length) {
873+
length = string.length
874+
}
875+
876+
for (let i = 0; i < length; i++) {
877+
buf[offset + i] = string.charCodeAt(i)
878+
}
879+
880+
return length
873881
}
874882

875883
function base64Write (buf, string, offset, length) {
@@ -2050,15 +2058,6 @@ function utf8ToBytes (string, units) {
20502058
return bytes
20512059
}
20522060

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

0 commit comments

Comments
 (0)