-
Notifications
You must be signed in to change notification settings - Fork 28.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
src: make base64 decoding 50% faster
Make the inner loop execute fewer compare-and-branch executions per processed byte, resulting in a 50% or more speedup. This coincidentally fixes an out-of-bounds read: while (unbase64(*src) < 0 && src < srcEnd) Should have read: while (src < srcEnd && unbase64(*src) < 0) But this commit removes the offending code altogether. Fixes: #2166 PR-URL: #2193 Reviewed-By: Trevor Norris <trev.norris@gmail.com>
- Loading branch information
1 parent
b148c0d
commit 8fd3ce1
Showing
2 changed files
with
83 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
var assert = require('assert'); | ||
var common = require('../common.js'); | ||
|
||
var bench = common.createBenchmark(main, {}); | ||
|
||
function main(conf) { | ||
for (var s = 'abcd'; s.length < 32 << 20; s += s); | ||
s.match(/./); // Flatten string. | ||
assert.equal(s.length % 4, 0); | ||
var b = Buffer(s.length / 4 * 3); | ||
b.write(s, 0, s.length, 'base64'); | ||
bench.start(); | ||
for (var i = 0; i < 32; i += 1) b.base64Write(s, 0, s.length); | ||
bench.end(32); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters