rust-cssparser icon indicating copy to clipboard operation
rust-cssparser copied to clipboard

Consider using a pointer offset instead of a slice and integer position

Open jdm opened this issue 8 years ago • 4 comments

The generated assembly for code using next_byte_unchecked like skip_whitespace has a suprising number of indirections in order to actually get the byte value. This is caused by the need to get the slice, then get the byte at the desired offset from it at https://github.com/servo/rust-cssparser/blob/682087fca5ba5f2f05a09bba72c62dac6b3d778d/src/tokenizer.rs#L372. If we use store a pointer and increase its instead of the offset, it should cause more efficient code to be generated.

jdm avatar Dec 08 '17 19:12 jdm

A safe way to represent a slice as a pair of pointer might be std::slice::Iter.

SimonSapin avatar Dec 08 '17 19:12 SimonSapin

Is next_byte_unchecked really unchecked and free of bound checks? I thought we need to use unsafe get_unchecked or assert bounds to do that?

pickfire avatar Aug 11 '20 03:08 pickfire

It's unchecked in the sense that it doesn't check for EOF. But it does a bounds-check / panics if you misuse it.

emilio avatar Aug 11 '20 11:08 emilio

Posted https://github.com/servo/rust-cssparser/pull/381 for posterity which uses a slice iterator. It seems that's a regression at least on the big-data-url test, so it'd need more work.

emilio avatar Apr 07 '24 20:04 emilio