[BitVector] Add find_last() and find_last_unset()

Authored by zturner on Thu, Apr 20, 10:53 AM.



BitVector currently provides find_first() and find_first_unset(), this adds methods to search in reverse.

Diff Detail

zturner created this revision.Thu, Apr 20, 10:53 AM
chandlerc added inline comments.Thu, Apr 20, 5:48 PM
170–173 ↗(On Diff #95984)

The for loop above seems simpler?

If you really want, you can use:

for (unsigned i : llvm::reverse(llvm::seq(0, NumBitWords(size())))
196–202 ↗(On Diff #95984)

Rather than this, what about just handling the last word outside the loop?

zturner updated this revision to Diff 96162.Fri, Apr 21, 9:53 AM

Updated based on feedback from chandlerc.

zturner updated this revision to Diff 96163.Fri, Apr 21, 9:56 AM

Fix an inverted conditional / break statement.

chandlerc accepted this revision.Fri, Apr 21, 10:35 AM

LGTM with some loop simplifications.

175–179 ↗(On Diff #96163)

I this can be written as:

while (i > 0 && Bits[i] != Bitword(0))
213–218 ↗(On Diff #96163)

I think this is the same as:

while (W == ~BitWord(0) && --i > 0)
  W = Bits[i];
This revision is now accepted and ready to land.Fri, Apr 21, 10:35 AM
This revision was automatically updated to reflect the committed changes.