dhardy / rand

http://doc.rust-lang.org/rand
Other
2 stars 2 forks source link

Rename `AsciiWordChar` and optimize `Codepoint` #75

Closed pitdicker closed 6 years ago

pitdicker commented 6 years ago

This renames AsciiWordChar to Alphanumeric. And just after making the Avoid low bits PR, I changed AsciiWordChar to use the low bits (?!). Better use a shift than a mask now.

Adding the [inline] attribute to RangeInt::new and RangeInt::new_inclusive helps LLVM to calculate the range and zone at compile time if the range is constant. That makes it a better choice than the current bitmask or even simple_range for Codepoint.

Benchmarks before:

test distr_uniform_ascii_char ... bench:       2,785 ns/iter (+/- 59) = 1436 MB/s
test distr_uniform_codepoint  ... bench:       9,792 ns/iter (+/- 36) = 408 MB/s

After

test distr_uniform_alphanumeric ... bench:       2,654 ns/iter (+/- 54) = 1507 MB/s
test distr_uniform_codepoint    ... bench:       2,799 ns/iter (+/- 5) = 1429 MB/s