Skip to content

Commit

Permalink
Improve decoding performance
Browse files Browse the repository at this point in the history
This yields a performance improvement over indexing into `source` over and over. `source` is asserted to be a string, `psz` is monotonically increasing, and `psz >= source.length` is a good indication that you've run out of characters.

Originally proposed by @oscxc in #74.

Co-authored-by: Rand <15077550@qq.com>
  • Loading branch information
steveluscher and oscxc committed Jul 3, 2024
1 parent 39f2673 commit 261fb36
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/cjs/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ function base (ALPHABET) {
const size = (((source.length - psz) * FACTOR) + 1) >>> 0 // log(58) / log(256), rounded up.
const b256 = new Uint8Array(size)
// Process the characters.
while (source[psz]) {
while (psz < source.length) {
// Decode character
let carry = BASE_MAP[source.charCodeAt(psz)]
// Invalid character
Expand Down
2 changes: 1 addition & 1 deletion src/esm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ function base (ALPHABET) {
const size = (((source.length - psz) * FACTOR) + 1) >>> 0 // log(58) / log(256), rounded up.
const b256 = new Uint8Array(size)
// Process the characters.
while (source[psz]) {
while (psz < source.length) {
// Decode character
let carry = BASE_MAP[source.charCodeAt(psz)]
// Invalid character
Expand Down
2 changes: 1 addition & 1 deletion ts_src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ function base (ALPHABET: string): base.BaseConverter {
const b256 = new Uint8Array(size)

// Process the characters.
while (source[psz]) {
while (psz < source.length) {
// Decode character
let carry = BASE_MAP[source.charCodeAt(psz)]

Expand Down

0 comments on commit 261fb36

Please sign in to comment.