mozilla/rust — pull request #11498 by c-a (2014-01-12 12:36:37+00:00)
Title: Optimize ebml::reader::vuint_at()

Use two lookup tables, shift_table and mask_table, that for every possible four
bit prefix respectively holds the number of times the value should be right
shifted and what the right shifted value should be masked with.
This way we can get rid of the branches which in my testing gives approximately
a 2x speedup.

Timings on Intel(R) Core(TM) i5-3570K CPU @ 3.40GHz

-- Before --
running 5 tests
test ebml::tests::test_vuint_at ... ok
test ebml::bench::vuint_at_A_aligned ... bench: 494 ns/iter (+/- 3)
test ebml::bench::vuint_at_A_unaligned ... bench: 494 ns/iter (+/- 4)
test ebml::bench::vuint_at_D_aligned ... bench: 467 ns/iter (+/- 5)
test ebml::bench::vuint_at_D_unaligned ... bench: 467 ns/iter (+/- 5)

-- After --
running 5 tests
test ebml::tests::test_vuint_at ... ok
test ebml::bench::vuint_at_A_aligned ... bench: 203 ns/iter (+/- 2)
test ebml::bench::vuint_at_A_unaligned ... bench: 211 ns/iter (+/- 2)
test ebml::bench::vuint_at_D_aligned ... bench: 206 ns/iter (+/- 4)
test ebml::bench::vuint_at_D_unaligned ... bench: 209 ns/iter (+/- 2)