[PATCH] D33478: [libclang] When getting platform availabilities, merge multiple declarations if possible

Alex Lorenz via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Jun 5 10:22:42 PDT 2017


arphaman added inline comments.


================
Comment at: tools/libclang/CIndex.cpp:7322
+
+  for (int I = 0, E = AvailabilityAttrs.size(); I < E && I < availability_size;
+       ++I) {
----------------
rdwampler wrote:
> arphaman wrote:
> > You can use a ranged for loop here if you use `take_front`, e.g.
> > 
> > ```
> > for (const auto *Avail : AvailabilityAttrs.take_front(availability_size))
> > ```
> I would need to covert this to an `ArrayRef`, I believe. Also, I would need to check `availability_size` is in bounds. Would something like the following be preferred:
> ```
> int N = 0;
> for (const auto *Avail : AvailabilityAttrs) {
>   if (N < availability_size) {
>     // populate availability
>     N++;
>   }
> }
> ```
Right, sorry I forgot about the `N`.
I think that you can use `llvm::enumerate(llvm::makeArrayRef(AvailabilityAttrs).take_front(availability_size))` to get rid of `N` as well, as you can the index and the attribute pointer from the loop variable.
Btw, The `take_front(N)` will ensure that you will only iterate either over the first N attributes or all of the attributes if `N > AvailabilityAttrs.size()`, so you won't need to check `N` in the loop.


https://reviews.llvm.org/D33478





More information about the cfe-commits mailing list