[libc-commits] [PATCH] D85103: [libc] Add strspn implementation.

Chris Gyurgyik via Phabricator via libc-commits libc-commits at lists.llvm.org
Tue Aug 4 14:54:02 PDT 2020


cgyurgyik added inline comments.


================
Comment at: libc/src/string/strspn.cpp:21
+
+static void toggle_bit(size_t *bitset, const size_t ch) {
+  const size_t mask = size_t{1} << (ch % exploded_unsigned_char_bit);
----------------
cgyurgyik wrote:
> sivachandra wrote:
> > I would prefer a `bool` specialization of https://github.com/llvm/llvm-project/blob/master/libc/utils/CPP/Array.h for which the internal implementation is a bit array like `std::vector<bool>`.
> > 
> > Also, why not use `uintptr_t` array instead of `size_t` array?
> > 
> > ```
> > static constexpr size_t BitsPerUnit = 8 * sizeof(uintptr_t);
> > uintptr_t Data[size / BitsPerUnit + size % BitsPerUnit]; // size is of type size_t
> > 
> > // Setter; x is of type size_t
> > Data[x / BitsPerUnit] |= (uintptr_t(1) << (x % BitsPerUnit));
> > 
> > // Getter; x is of type size_t
> > return Data[x / BitsPerUnit] & (uintptr_t(1) << (x % BitsPerUnit));
> > ```
> Ok I'll work on this.
Discussed offline - going to add std::bitset util instead, since std::array<bool, size_t> doesn't mimic the std::vector<bool> implementation.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D85103/new/

https://reviews.llvm.org/D85103



More information about the libc-commits mailing list