http icon indicating copy to clipboard operation
http copied to clipboard

Document byte-by-byte comparisons (eq! macro) in name.rs

Open jsha opened this issue 4 years ago • 0 comments

I was recently reading name.rs, and was surprised to see a lot of hand-coded byte-by-byte comparisons for reading header names: https://github.com/hyperium/http/blob/975dbdd70a882fbf74a77a5b90ad190602bb98ac/src/header/name.rs#L1312-L1320

I'm curious why the code is written this way, rather than, say, with a match operator that would allow the compiler to optimize the comparisons appropriately. I see that @alexcrichton had a similar question during initial review of this code:

https://github.com/hyperium/http/pull/13/files#diff-45d89276e2be4715b26dc4e575f4153eR251

@carllerche I realize you wrote this code over 3 years ago, but would you be willing to take a second look and document the logic here? I'm assuming it's for performance but it would be good to know what specific performance problems were being worked around, and whether they've been improved in subsequent compiler releases.

Thanks, Jacob

jsha avatar Jun 28 '20 18:06 jsha