diff options
author | Daniel Llorens <daniel.llorens@bluewin.ch> | 2013-04-02 15:53:22 +0200 |
---|---|---|
committer | Ludovic Courtès <ludo@gnu.org> | 2013-04-03 21:46:27 +0200 |
commit | 51a1763f6596d594ebd774e7c3fd9138e6f4d507 (patch) | |
tree | 2c969aa68ae0ff2263e67fcd7db5a0e81893e5de /libguile/array-map.c | |
parent | 9a68d7b388c610cdbc5689ae9cbadb70ee311f67 (diff) | |
download | guile-51a1763f6596d594ebd774e7c3fd9138e6f4d507.tar.gz |
Remove double indirection in array-map! with <2 args
* libguile/array-map.c: (ramap): factor GVSET/GVREF out of rank-1 loop
for ra0 and the first element of ras.
Diffstat (limited to 'libguile/array-map.c')
-rw-r--r-- | libguile/array-map.c | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/libguile/array-map.c b/libguile/array-map.c index 9ed040196..b05548b61 100644 --- a/libguile/array-map.c +++ b/libguile/array-map.c @@ -644,25 +644,31 @@ static int ramap (SCM ra0, SCM proc, SCM ras) { ssize_t i = SCM_I_ARRAY_DIMS (ra0)->lbnd; + size_t n = SCM_I_ARRAY_DIMS (ra0)->ubnd - i + 1; - size_t i0 = SCM_I_ARRAY_BASE (ra0); - ssize_t inc0 = SCM_I_ARRAY_DIMS (ra0)->inc; - size_t n = SCM_I_ARRAY_DIMS (ra0)->ubnd - SCM_I_ARRAY_DIMS (ra0)->lbnd + 1; - size_t i0end = i0 + n*inc0; - ra0 = SCM_I_ARRAY_V (ra0); + scm_t_array_handle h0; + size_t i0, i0end; + ssize_t inc0; + scm_generalized_vector_get_handle (SCM_I_ARRAY_V (ra0), &h0); + i0 = h0.base + h0.dims[0].lbnd + SCM_I_ARRAY_BASE (ra0)*h0.dims[0].inc; + inc0 = SCM_I_ARRAY_DIMS (ra0)->inc * h0.dims[0].inc; + i0end = i0 + n*inc0; if (scm_is_null (ras)) for (; i0 < i0end; i0 += inc0) - GVSET (ra0, i0, scm_call_0 (proc)); + h0.impl->vset (&h0, i0, scm_call_0 (proc)); else { SCM ra1 = SCM_CAR (ras); - size_t i1 = SCM_I_ARRAY_BASE (ra1); - ssize_t inc1 = SCM_I_ARRAY_DIMS (ra1)->inc; - ra1 = SCM_I_ARRAY_V (ra1); + scm_t_array_handle h1; + size_t i1; + ssize_t inc1; + scm_generalized_vector_get_handle (SCM_I_ARRAY_V (ra1), &h1); + i1 = h1.base + h1.dims[0].lbnd + SCM_I_ARRAY_BASE (ra1)*h1.dims[0].inc; + inc1 = SCM_I_ARRAY_DIMS (ra1)->inc * h1.dims[0].inc; ras = SCM_CDR (ras); - if (scm_is_null(ras)) + if (scm_is_null (ras)) for (; i0 < i0end; i0 += inc0, i1 += inc1) - GVSET (ra0, i0, scm_call_1 (proc, GVREF (ra1, i1))); + h0.impl->vset (&h0, i0, scm_call_1 (proc, h1.impl->vref (&h1, i1))); else { ras = scm_vector (ras); @@ -672,10 +678,12 @@ ramap (SCM ra0, SCM proc, SCM ras) unsigned long k; for (k = scm_c_vector_length (ras); k--;) args = scm_cons (GVREF (scm_c_vector_ref (ras, k), i), args); - GVSET (ra0, i0, scm_apply_1 (proc, GVREF (ra1, i1), args)); + h0.impl->vset (&h0, i0, scm_apply_1 (proc, h1.impl->vref (&h1, i1), args)); } } + scm_array_handle_release (&h1); } + scm_array_handle_release (&h0); return 1; } |