numpy/numpy — pull request #3931 by juliantaylor (2013-10-16 19:50:43+00:00)
Title: move memchr like code to a function

and improve the speed a bit by using by using __builtin_ctz (tzcnt on x86)

Improves sparse mask performance by about a factor of three, the worst
case of no consecutive mask elements slows down by about 10%-20%.

```
In [1]: import numpy as np
In [2]: d = np.ones(60000)
In [3]: m = np.ones(60000, dtype=np.bool)
In [4]: r = np.zeros(60000)
In [5]: %timeit np.copyto(r, d, where=m)
10000 loops, best of 3: 137 µs per loop
# vs before 156 µs
In [7]: %timeit np.copyto(r, d, where=m)
100000 loops, best of 3: 15.5 µs per loop
# vs before 58.2 µs
In [8]: m[::2] = ~m[::2]
In [9]: %timeit np.copyto(r, d, where=m)
1000 loops, best of 3: 634 µs per loop
# vs before 548 µs
```