@@ -3526,7 +3526,6 @@ resolve_dtype_iter(PyObject *Py_UNUSED(m), PyObject *arg) {
3526
3526
//------------------------------------------------------------------------------
3527
3527
// general utility
3528
3528
3529
- #define AK_FT_MEMCMP_SIZE 8
3530
3529
3531
3530
static char * first_true_1d_kwarg_names [] = {
3532
3531
"array" ,
@@ -3561,10 +3560,10 @@ first_true_1d(PyObject *Py_UNUSED(m), PyObject *args, PyObject *kwargs)
3561
3560
return NULL ;
3562
3561
}
3563
3562
3564
- static npy_bool zero_buffer [ AK_FT_MEMCMP_SIZE ] = { 0 } ;
3563
+ npy_intp lookahead = sizeof ( npy_uint64 ) ;
3565
3564
3566
3565
npy_intp size = PyArray_SIZE (array );
3567
- lldiv_t size_div = lldiv ((long long )size , AK_FT_MEMCMP_SIZE ); // quot, rem
3566
+ lldiv_t size_div = lldiv ((long long )size , lookahead ); // quot, rem
3568
3567
3569
3568
npy_bool * array_buffer = (npy_bool * )PyArray_DATA (array );
3570
3569
@@ -3580,10 +3579,10 @@ first_true_1d(PyObject *Py_UNUSED(m), PyObject *args, PyObject *kwargs)
3580
3579
p_end = p + size ;
3581
3580
3582
3581
while (p < p_end - size_div .rem ) {
3583
- if (memcmp ( p , zero_buffer , AK_FT_MEMCMP_SIZE ) != 0 ) {
3584
- break ; // found a true
3582
+ if (* ( npy_uint64 * ) p != 0 ) {
3583
+ break ; // found a true within lookahead
3585
3584
}
3586
- p += AK_FT_MEMCMP_SIZE ;
3585
+ p += lookahead ;
3587
3586
}
3588
3587
while (p < p_end ) {
3589
3588
if (* p ) break ;
@@ -3594,12 +3593,10 @@ first_true_1d(PyObject *Py_UNUSED(m), PyObject *args, PyObject *kwargs)
3594
3593
p = array_buffer + size - 1 ;
3595
3594
p_end = array_buffer - 1 ;
3596
3595
while (p > p_end + size_div .rem ) {
3597
- if (memcmp (p - AK_FT_MEMCMP_SIZE + 1 , // go to front
3598
- zero_buffer ,
3599
- AK_FT_MEMCMP_SIZE ) != 0 ) {
3600
- break ; // found a true
3596
+ if (* (npy_uint64 * )(p - lookahead + 1 ) != 0 ) {
3597
+ break ; // found a true within lookahead
3601
3598
}
3602
- p -= AK_FT_MEMCMP_SIZE ;
3599
+ p -= lookahead ;
3603
3600
}
3604
3601
while (p > p_end ) {
3605
3602
if (* p ) break ;
@@ -3699,15 +3696,15 @@ first_true_2d(PyObject *Py_UNUSED(m), PyObject *args, PyObject *kwargs)
3699
3696
array_ind = array ; // can use array, no decref needed
3700
3697
}
3701
3698
3702
- static npy_bool zero_buffer [ AK_FT_MEMCMP_SIZE ] = { 0 } ;
3699
+ npy_intp lookahead = sizeof ( npy_uint64 ) ;
3703
3700
3704
3701
// buffer of indicators
3705
3702
npy_bool * buffer_ind = (npy_bool * )PyArray_DATA (array_ind );
3706
3703
3707
3704
npy_intp count_row = PyArray_DIM (array_ind , 0 );
3708
3705
npy_intp count_col = PyArray_DIM (array_ind , 1 );
3709
3706
3710
- lldiv_t div_col = lldiv ((long long )count_col , AK_FT_MEMCMP_SIZE ); // quot, rem
3707
+ lldiv_t div_col = lldiv ((long long )count_col , lookahead ); // quot, rem
3711
3708
3712
3709
npy_intp dims_post = {count_row };
3713
3710
PyArrayObject * array_pos = (PyArrayObject * )PyArray_EMPTY (
@@ -3743,10 +3740,10 @@ first_true_2d(PyObject *Py_UNUSED(m), PyObject *args, PyObject *kwargs)
3743
3740
// scan each row from the front and terminate when True
3744
3741
// remove from the end the remainder
3745
3742
while (p < p_end - div_col .rem ) {
3746
- if (memcmp ( p , zero_buffer , AK_FT_MEMCMP_SIZE ) != 0 ) {
3743
+ if (* ( npy_uint64 * ) p != 0 ) {
3747
3744
break ; // found a true
3748
3745
}
3749
- p += AK_FT_MEMCMP_SIZE ;
3746
+ p += lookahead ;
3750
3747
}
3751
3748
while (p < p_end ) {
3752
3749
if (* p ) {break ;}
@@ -3764,13 +3761,11 @@ first_true_2d(PyObject *Py_UNUSED(m), PyObject *args, PyObject *kwargs)
3764
3761
p_end = buffer_ind + (count_col * r ) - 1 ;
3765
3762
3766
3763
while (p > p_end + div_col .rem ) {
3767
- // must give memcmp the start of the buffer
3768
- if (memcmp (p - AK_FT_MEMCMP_SIZE + 1 , // go to front
3769
- zero_buffer ,
3770
- AK_FT_MEMCMP_SIZE ) != 0 ) {
3764
+ // must go to start of lookahead
3765
+ if (* (npy_uint64 * )(p - lookahead + 1 ) != 0 ) {
3771
3766
break ; // found a true
3772
3767
}
3773
- p -= AK_FT_MEMCMP_SIZE ;
3768
+ p -= lookahead ;
3774
3769
}
3775
3770
while (p > p_end ) {
3776
3771
if (* p ) {break ;}
0 commit comments