serpent-os / moss

The safe, fast and sane package manager for Linux
https://serpentos.com
71 stars 9 forks source link

Drop the bitflags dependency #148

Closed livingsilver94 closed 4 months ago

livingsilver94 commented 4 months ago

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.

livingsilver94 commented 4 months ago

Oops, made a mess with git history. Fixing.