This PR replaces the bitflags functionality with an in-house implementation.
I think we all agree on reducing the number of dependencies where it makes sense, and I also think bitflags is one dependency worth removing. It is based on a macro_rule which is able to escape the original Rust syntax (think of that : u8 syntax to specify that flags are bytes. That's a C++ notation!), making code a little confusing. macro_rules have too much freedom of toying with the code, IMO.
The new Flags struct is a type-safe and value-safe collection of flags. It is not possible to build an invalid collection of Flags. The idea is based on std::fs::OpenOptions.
Did you note that bits() private method? That's a micro-optimization. While I could implement the contains() method using pure boolean logic, with Compiler Explorer I noticed that that would introduce conditional jumps in the assembly. For the sake of the CPU pipeline, I chose to convert the single flags back into an integer for the comparison, thus avoiding jumps altogether.
This PR replaces the bitflags functionality with an in-house implementation.
I think we all agree on reducing the number of dependencies where it makes sense, and I also think bitflags is one dependency worth removing. It is based on a
macro_rule
which is able to escape the original Rust syntax (think of that: u8
syntax to specify that flags are bytes. That's a C++ notation!), making code a little confusing.macro_rules
have too much freedom of toying with the code, IMO.The new
Flags
struct is a type-safe and value-safe collection of flags. It is not possible to build an invalid collection of Flags. The idea is based onstd::fs::OpenOptions
.Did you note that
bits()
private method? That's a micro-optimization. While I could implement thecontains()
method using pure boolean logic, with Compiler Explorer I noticed that that would introduce conditional jumps in the assembly. For the sake of the CPU pipeline, I chose to convert the single flags back into an integer for the comparison, thus avoiding jumps altogether.