[PATCH] D27068: Improve string::find

Aditya Kumar via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Dec 2 11:48:50 PST 2016


hiraditya added inline comments.


================
Comment at: libcxx/include/__string:549
+    // Stop short when source is smaller than pattern.
+    ptrdiff_t __len2 = __last2 - __first2;
+    if (__len2 == 0)
----------------
mclow.lists wrote:
> Is there a reason that you calculate the end pointer(s) from `first + len` in the calling function, then recover the length here?
> 
> Also, `__len1` and `__len2` should be const.
Recovering length here is only making the interface uniform, I don't have any specific reason for that. This function is going to be inlined anyways. It started this way because I copied the interface from std::__search in the header file algorithm.



len2 can be a const, since len1 changes in the loop, for this to make const I would have to introduce another variable. I'll update the patch.



https://reviews.llvm.org/D27068





More information about the cfe-commits mailing list