diff options
author | Daniel Llorens <daniel.llorens@bluewin.ch> | 2013-04-03 22:40:40 +0200 |
---|---|---|
committer | Ludovic Courtès <ludo@gnu.org> | 2013-04-05 22:54:14 +0200 |
commit | ab1ca17986ee758b7ec4088bf3f6a596872b1677 (patch) | |
tree | 464b09e7c11c36e36b5a1eeac53af83ba9164ea5 /libguile/array-map.c | |
parent | b5159a471a1acbe1ad08ee5365d123912fcc607d (diff) | |
download | guile-ab1ca17986ee758b7ec4088bf3f6a596872b1677.tar.gz |
Remove double indirection in array-fill!
* libguile/array-map.c: new function rafill, like scm_array_fill_int,
but factors GVSET out of the loop. Use it in scm_array_fill_x instead of
scm_array_fill_int.
* test-suite/tests/arrays.test: add test for array-fill! with stride != 1.
Signed-off-by: Ludovic Courtès <ludo@gnu.org>
Diffstat (limited to 'libguile/array-map.c')
-rw-r--r-- | libguile/array-map.c | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/libguile/array-map.c b/libguile/array-map.c index b5b8cec9e..c86ea8457 100644 --- a/libguile/array-map.c +++ b/libguile/array-map.c @@ -318,6 +318,23 @@ scm_ramapc (void *cproc_ptr, SCM data, SCM ra0, SCM lra, const char *what) } } +static int +rafill (SCM dst, SCM fill) +{ + long n = (SCM_I_ARRAY_DIMS (dst)->ubnd - SCM_I_ARRAY_DIMS (dst)->lbnd + 1); + scm_t_array_handle h; + size_t i; + ssize_t inc; + scm_generalized_vector_get_handle (SCM_I_ARRAY_V (dst), &h); + i = h.base + h.dims[0].lbnd + SCM_I_ARRAY_BASE (dst)*h.dims[0].inc; + inc = SCM_I_ARRAY_DIMS (dst)->inc * h.dims[0].inc; + + for (; n-- > 0; i += inc) + h.impl->vset (&h, i, fill); + + scm_array_handle_release (&h); + return 1; +} SCM_DEFINE (scm_array_fill_x, "array-fill!", 2, 0, 0, (SCM ra, SCM fill), @@ -325,14 +342,14 @@ SCM_DEFINE (scm_array_fill_x, "array-fill!", 2, 0, 0, "returned is unspecified.") #define FUNC_NAME s_scm_array_fill_x { - scm_ramapc (scm_array_fill_int, fill, ra, SCM_EOL, FUNC_NAME); + scm_ramapc (rafill, fill, ra, SCM_EOL, FUNC_NAME); return SCM_UNSPECIFIED; } #undef FUNC_NAME /* to be used as cproc in scm_ramapc to fill an array dimension with "fill". */ -int +int scm_array_fill_int (SCM ra, SCM fill, SCM ignore SCM_UNUSED) #define FUNC_NAME s_scm_array_fill_x { |