This is an archive of the discontinued LLVM Phabricator instance.

Add some functions to search ArrayRefs
ClosedPublic

Authored by zturner on Nov 22 2016, 1:48 PM.

Details

Summary

This mirrors the interface of StringRef by adding functions for searching and dropping items from an ArrayRef until a certain condition is met. Specifically, this adds take_front, take_back, drop_front, and drop_back, along with helper functions find_if and find_if_not.

Diff Detail

Repository
rL LLVM

Event Timeline

zturner updated this revision to Diff 78942.Nov 22 2016, 1:48 PM
zturner retitled this revision from to Add some functions to search ArrayRefs.
zturner updated this object.
zturner added reviewers: chandlerc, mehdi_amini.
zturner added a subscriber: llvm-commits.
chandlerc added inline comments.Nov 22 2016, 2:29 PM
include/llvm/ADT/ArrayRef.h
34 ↗(On Diff #78942)

I'm really reluctant to add APIs based around the 'npos' idea. How challenging does removing this and relying exclusively on iterator based constructs make things?

173 ↗(On Diff #78942)

These are already inline functions, why not make them templates and use generic callables?

zturner added inline comments.Nov 22 2016, 2:40 PM
include/llvm/ADT/ArrayRef.h
173 ↗(On Diff #78942)

joker-eph pointed me to llvm::find_if(), I think I will add llvm::find_if_not(), then have the functions use that, and that should address both of your comments at the same time.

zturner updated this revision to Diff 78954.Nov 22 2016, 2:51 PM
  • Deleted member find_if and find_if_not
  • Deleted npos
  • Convert take / drop functions to use llvm::find_if and llvm::find_if_not free functions.
  • Updated the aforementioned functions to take a templatized predicate instead of an llvm::function_ref.
chandlerc edited edge metadata.Nov 22 2016, 3:13 PM

I would suggest passing the predicate by value instead of const reference to match the standard library. Feel free to fix up the range adapters in a separate patch and systematically.

Also, I'd suggest 'typename PredicateT' and 'PredicateT P' for naming conventions, if you want to be fully nit-picky. =D

chandlerc accepted this revision.Nov 22 2016, 3:13 PM
chandlerc edited edge metadata.

LGTM with suggested changes, no need for a second iteration here.

This revision is now accepted and ready to land.Nov 22 2016, 3:13 PM
This revision was automatically updated to reflect the committed changes.