Skip to content

Commit

Permalink
avoid using memset for zeros.
Browse files Browse the repository at this point in the history
  • Loading branch information
Hui committed Mar 7, 2017
1 parent 66f1b8a commit 1d92b6e
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions numpy/core/src/multiarray/alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ _npy_free_cache(void * p, npy_uintp nelem, npy_uint msz,
}


static NPY_INLINE void *
_PyDataMem_NEW_ZEROED_RAW(size_t size) {
return PyDataMem_NEW_ZEROED(size, 1);
}

/*
* array data cache, sz is number of bytes to allocate
*/
Expand All @@ -69,18 +74,15 @@ npy_alloc_cache(npy_uintp sz)
return _npy_alloc_cache(sz, 1, NBUCKETS, datacache, &PyDataMem_NEW);
}


/* zero initialized data, sz is number of bytes to allocate */
NPY_NO_EXPORT void *
npy_alloc_cache_zero(npy_uintp sz)
{
void * p;
NPY_BEGIN_THREADS_DEF;
if (sz < NBUCKETS) {
p = _npy_alloc_cache(sz, 1, NBUCKETS, datacache, &PyDataMem_NEW);
if (p) {
memset(p, 0, sz);
}
return p;
return _npy_alloc_cache(sz, 1, NBUCKETS, datacache, &_PyDataMem_NEW_ZEROED_RAW);
}
NPY_BEGIN_THREADS;
p = PyDataMem_NEW_ZEROED(sz, 1);
Expand Down

0 comments on commit 1d92b6e

Please sign in to comment.