This mostly copys the <experimental/functional> stuff and updates the code to current libc++ style.
Details
- Reviewers
• Quuxplusone ldionne Mordante - Group Reviewers
Restricted Project - Commits
- rG971e9c80e966: [libc++] Implement std::boyer_moore{, _horspool}_searcher
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
Thanks for working on this! This will be super useful — not really to working programmers ;) but in terms of checking boxes for C++17 conformance and finally getting to remove the experimental versions!
libcxx/include/__functional/boyer_moore_searcher.h | ||
---|---|---|
35–40 | Personally I'd prefer to see the first specialization here done as the primary template, and then we just have one specialization for _BMSkipTable<..., false>. I see it's less symmetric, but it eliminates a forward declaration (and ~7 LoC). | |
57 | Likewise throughout. "All your ctors should be explicit unless they're used for implicit conversions" (or unless the Standard API mandates it :() | |
87 | #include <__algorithm/fill_n.h> Actually, whoa, I thought this was our <vector> dependency, but it's not! This specialization should just use a plain old C array value_type __table_[256]; and cut out all the metaprogramming. This header shouldn't need to depend on <array> at all. | |
123 | Let's use __last - __first and save some instantiations. These are random-access iterators. | |
125 | First reaction: Why depend on shared_ptr? Second reaction: Why two dereferences (one for the shared_ptr and another for the vector)? At the very least this should use make_shared<difference_type[]>(__pattern_length_ + 1). But it would be awesome if we could eliminate the shared_ptr too, somehow. I assume it's in there because std::search wants to copy these things but we don't want the copy to be expensive. Could we just make std::search not copy these things? And then it wouldn't matter if the copy was expensive, and we could just use std::vector<D> instead of std::shared_ptr<D[]>. (The copy ctor still needs to exist, IIUC, but it doesn't have to be fast, if we can claim it's the user's fault if they ever call it.) | |
187 | As above, __last - __first — this is instantiated only with RAI and reverse_iterator<RAI>, both of which are random-access. | |
193 | ||
206–207 | Nit: Should be if (__first == __last) or if (__count == 0), I'd think. size_t can't be negative. | |
libcxx/include/optional | ||
165–167 ↗ | (On Diff #413306) | This, and the diff in the <optional> test, looks unrelated to boyer_moore_searcher. Please do this in a separate PR (which I'll rubberstamp if CI is green). |
libcxx/include/__functional/boyer_moore_searcher.h | ||
---|---|---|
35–40 | Is that purely style or is there any technical reason to change it? | |
87 | I think it's easier to read when using an array. | |
125 | std::search doesn't copy this. It just gets a const ref and returns the search result. I'm not sure why you wouldn't just call the search directly, but hey. I'd argue that using std::shared_ptr<D[]> might be the better alternative, since after construction the elements will never change. And AFAIK it would be cheaper to copy and as cheap to move. |
LGTM once CI is green and comments are addressed. I'm fine with the code not being perfect since we're basically copying it from <experimental/>. I'm fine (and actually prefer) making changes as follow-up patches.
libcxx/test/std/utilities/optional/optional.hash/enabled_hash.pass.cpp | ||
---|---|---|
28 | Please add a release note mentioning that we will remove the experimental version in two releases, i.e. LLVM 17. And also mark the experimental feature as deprecated. This is documented in libcxx/docs/DesignDocs/ExperimentalFeatures.rst. | |
30 | Can we tick some boxes in the status pages? |
libcxx/test/std/utilities/optional/optional.hash/enabled_hash.pass.cpp | ||
---|---|---|
30 | No, we can't. It's part of library fundamentals, and I think not everything has been implemented yet. Maybe we should add a status page for that, because it's really hard to find out what is already implemented. |
libcxx/include/__functional/boyer_moore_searcher.h | ||
---|---|---|
209 | shouldn't this be vector<difference_type>? |
- Try to fix GCC
libcxx/include/__functional/boyer_moore_searcher.h | ||
---|---|---|
209 | Why do you think it should be vector<difference_type>? |
libcxx/include/__functional/boyer_moore_searcher.h | ||
---|---|---|
209 | if value_type is signed and the range consists of e.g. the same values with length more than the max, __compute_bm_prefix will cause a signed overflow, moreover as __scratch can now contain negative values we could index out of __suffix_ |
libcxx/include/__functional/boyer_moore_searcher.h | ||
---|---|---|
209 | We should add a test and fix this bug in both this version and the experimental/functional version as well (even though we'll eventually remove that one). |
libcxx/include/__functional/boyer_moore_searcher.h | ||
---|---|---|
209 | if we plan on fixing the expirmental/functional we should add a +1 to the size in the _BMSkipTable array-based specialization typedef std::array<value_type, numeric_limits<unsigned_key_type>::max()> skip_map; otherwise we could index out of the array (not an issue in the new one) |
LGTM but please fix the experimental version too since it's so trivial.
libcxx/include/__functional/boyer_moore_searcher.h | ||
---|---|---|
209 | This comment above was marked as done but wasn't done AFAICT. |
Personally I'd prefer to see the first specialization here done as the primary template, and then we just have one specialization for _BMSkipTable<..., false>. I see it's less symmetric, but it eliminates a forward declaration (and ~7 LoC).