bitfields comparison in opEquals

Per Nordlöw per.nordlow at gmail.com
Thu Apr 26 22:24:42 UTC 2018


I have a struct with a mixin(bitfields) containing many small 
bitfields. I also have a class member in the struct.

And because I want the class member to compare by using `is` I 
need to define

     bool opEquals(const scope typeof(this) that) const @safe pure 
nothrow @nogc
     {
         return (this.data == that.data &&
                 this.context is that.context &&

                 // these are all bitfields members
                 // TODO can we do this comparison in one go?
                 this.lang == that.lang &&
                 this.pot == that.pot &&
                 this.manner == that.manner &&
                 this.senseNr == that.senseNr &&
                 this.hasUniquePot == that.hasUniquePot &&
                 this.isHashed == that.isHashed);
     }

Is there a way to make the bitfields-comparsion in opEquals run 
faster by somehow checking for its size in words (n) and casting 
it to size_t[n] which can be compared very fast.


More information about the Digitalmars-d-learn mailing list