Commit Graph

31 Commits

Author SHA1 Message Date
Marshall Pierce
1f0b90d113 Use current dependency versions.
Small tweaks to be compatible with updated rand api.
2018-10-02 21:14:30 -06:00
Marshall Pierce
3a0fdd4460 Apply rustfmt 2018-03-20 12:41:30 -05:00
Marshall Pierce
0113a0529b Add decode_config_slice.
Overall, still a mixed bag performance wise: nice speedups (5-11%) on
medium and large sizes, but slowdowns on 100 bytes and below for the
existing methods. However, decode_config_slice is a big win, especially
on smaller sizes: the best case for decoding 3 bytes goes from 166MiB/s
on master to 222 MiB/s. (Meanwhile the worst case goes from 95 MiB/s to
50 MiB/s, but I really doubt decoding base64 3 bytes at a time is
anyone's hotspot.)

Because this involved splitting out a separate helper function to do
the core of decode_config_buf and decode_config_slice, we seem to get
bit by some optimiser heuristics that get very fussy about inlining
hints and minor code changes, so that's something to keep an eye on.

Logic for when the fast decode logic could be used was tightened to
allow using them on shorter but still legal inputs.

Make random_config set strip_whitespace based off of line wrapping,
so no need to separately strip whitespace before decoding.
2017-12-05 10:13:17 -06:00
Marshall Pierce
0d3b7ab8ce Tweak decoding to never write more bytes that will then be discarded.
This opens the door to decoding to a slice, where such writes can't be
papered over by truncating a vec.

This incurs a minor performance cost (normally 0-1%, but up to 8-9% on 3
 byte decodes). Perf tuning to follow.
2017-12-04 15:59:03 -06:00
Marshall Pierce
c9fb70e8a8 Split up the integration tests so it's easier to find relevant tests 2017-11-30 09:36:45 -06:00
Marshall Pierce
ce54f9c4a6 Let rustfmt do its thing 2017-11-17 08:36:56 -06:00
Marshall Pierce
6758be0e2a Add encode_config_slice that writes to a &[u8].
Also, enable some compiler warnings and tighten up the docs.

Hat tip to @quodlibetor in #49 for starting this work.
2017-10-31 16:08:12 -05:00
Marshall Pierce
c9f4fbe908 Massage the Display wrapper a little 2017-09-22 07:35:02 -05:00
Marshall Pierce
51c3ee297e Make new() require a config. I just really don't like murky default
choices that people will use without thinking.
2017-09-21 21:19:08 -05:00
Marshall Pierce
b88c238852 A few testing tweaks 2017-07-05 15:15:33 -05:00
Marshall Pierce
154103eee3 Optimize decode performance. Fixes #30. 2017-05-22 10:32:00 -07:00
Marshall Pierce
91366d5017 Syntactic tidying, plus removing some tests.
The old tests that exhaustively check strings a couple bytes long
weren't that useful, and only checked one config. Using the random
config helper in src/tests.rs is a better use of wall clock time
when waiting for tests to run.
2017-05-18 07:51:41 -07:00
Marshall Pierce
f77519682e Rewrite line wrapping to use a linear-time algo.
Encoded bytes are moved from the end to the front so each byte is
only moved once.

Encoding is somewhat rearranged to operate on a slice into the
output buffer. This makes it easier to avoid clobbering any
existing bytes in the buffer, as well as paving the way to slice-
based encoding needed for a Display wrapper, stream adapters, etc.
2017-04-30 14:15:23 -07:00
Alice Maz
6555a4b1a2 Add vtab to "whitespace" chars
isspace is a better model to follow than js's btoa
2017-04-23 01:16:48 +00:00
Alice Maz
d0bba9775f Add MIME support
MIME config option, LineEnding enum, add necessary code to encode and decode
also get rid of decode_ws
2017-03-26 04:39:18 +00:00
Alice Maz
75a1f14a2d Merge branch 'decode-error' of https://github.com/marshallpierce/rust-base64 into marshallpierce-decode-error 2017-03-25 21:46:47 +00:00
Alice Maz
082fc5805d Test decode with &str and &[u8]
on basic tests, now that it is polymorphic over asref typeclass
2017-03-25 21:09:42 +00:00
Marshall Pierce
c6691e7b08 Eliminate unused error variant and rename to DecodeError 2017-02-15 07:32:44 -08:00
Alice Maz
bd8ef6e61c fix merge issues 2017-02-12 14:39:28 -08:00
Marshall Pierce
0fc917e368 Tweak some var names and comments for clarity. Update random roundtrip tests to allow an extra fast loop iteration (plus slop at the end). Use profile.bench since it turns out that's a thing. 2017-02-05 17:44:26 -08:00
Vincent Prouillet
dd8bf38866 Add config struct instead of mode
Based on rustc-serialize, minus the MIME
specific fields
2017-01-17 14:25:55 +09:00
Marshall Pierce
1ba394c278 Add tests around encoding/decoding into an existing buffer, and improve comments a little 2017-01-12 12:42:22 -08:00
Marshall Pierce
dc44239c5c Fix fat-fingered constant; add another test 2017-01-11 17:01:36 -08:00
Marshall Pierce
87d62a943e Read chunk via read_u64 2017-01-11 14:18:11 -08:00
Marshall Pierce
4d6d81a22c Main decode loop looking more like aklomp's 2017-01-11 14:18:11 -08:00
Marshall Pierce
b681bb62b3 Switch to lookup tables for decoding.
This brings big speedups: over 2x at 100 byte inputs to 6x by 3KiB
and larger. A consequence of this change in logic is that internal
padding characters (a '=' in the middle of base64) is now rejected.
This behavior is allowed per the RFC (4648 s. 3.3), but such
characters were silently ignored before.

On i7-6850K I'm seeing >3 IPC with 0.01% branch mispredict on the
10MiB test. Old code had 1.4 IPC with a pretty hefty 8.46% branch
mispredict.
2016-12-30 14:39:31 -08:00
Marshall Pierce
c518bb947b Add tests for base64 without padding, as well as roundtrip tests
for every possible 1, 2, and 3 byte string (encode, then decode)
and random byte strings up to length 10.
2016-12-30 13:18:05 -08:00
Alice Maz
c9dc498b34 Cleanup 2016-06-12 16:10:53 -07:00
Alice Maz
297f67cfe5 Replace u8{en,de} with {en,de}code_mode. Add URLSafe mode 2016-06-12 15:01:36 -07:00
Alice Maz
b7a2bbc4d5 Change encode's return from Result<String, Err> to Vec<u8> and decode's from Result<String, Err> to Result<Vec<u8>, Err>
Closes #1
2016-06-12 11:53:04 -07:00
Alice Maz
8a473508d2 there's the tests 2015-12-03 18:10:44 -05:00