diff options
| author | Dylan DPC <dylan.dpc@gmail.com> | 2020-02-12 14:21:06 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-02-12 14:21:06 +0100 |
| commit | f2d829ce6ab52c9e5b9aacd1181c87208c736ee9 (patch) | |
| tree | 6e0a83292130eea697f8bbb96ed79dfd387711ea /src/test/debuginfo/enum-thinlto.rs | |
| parent | 79ebf53cbb659175e863cdc4ca6341ee934376fd (diff) | |
| parent | 9aea154e7893b498b98a3d9c8e4c385c96fbe454 (diff) | |
| download | rust-f2d829ce6ab52c9e5b9aacd1181c87208c736ee9.tar.gz rust-f2d829ce6ab52c9e5b9aacd1181c87208c736ee9.zip | |
Rollup merge of #68914 - nnethercote:speed-up-SipHasher128, r=michaelwoerister
Speed up `SipHasher128`. The current code in `SipHasher128::short_write` is inefficient. It uses `u8to64_le` (which is complex and slow) to extract just the right number of bytes of the input into a u64 and pad the result with zeroes. It then left-shifts that value in order to bitwise-OR it with `self.tail`. For example, imagine we have a u32 input `0xIIHH_GGFF` and only need three bytes to fill up `self.tail`. The current code uses `u8to64_le` to construct `0x0000_0000_00HH_GGFF`, which is just `0xIIHH_GGFF` with the `0xII` removed and zero-extended to a u64. The code then left-shifts that value by five bytes -- discarding the `0x00` byte that replaced the `0xII` byte! -- to give `0xHHGG_FF00_0000_0000`. It then then ORs that value with `self.tail`. There's a much simpler way to do it: zero-extend to u64 first, then left shift. E.g. `0xIIHH_GGFF` is zero-extended to `0x0000_0000_IIHH_GGFF`, and then left-shifted to `0xHHGG_FF00_0000_0000`. We don't have to take time to exclude the unneeded `0xII` byte, because it just gets shifted out anyway! It also avoids multiple occurrences of `unsafe`. There's a similar story with the setting of `self.tail` at the method's end. The current code uses `u8to64_le` to extract the remaining part of the input, but the same effect can be achieved more quickly with a right shift on the zero-extended input. This commit changes `SipHasher128` to use the simpler shift-based approach. The code is also smaller, which means that `short_write` is now inlined where previously it wasn't, which makes things faster again. This gives big speed-ups for all incremental builds, especially "baseline" incremental builds. r? @michaelwoerister
Diffstat (limited to 'src/test/debuginfo/enum-thinlto.rs')
0 files changed, 0 insertions, 0 deletions
