This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "GNU Guile".
http://git.savannah.gnu.org/cgit/guile.git/commit/?id=336c921146957a7416bc1717289a01f1b556ad82 The branch, stable-2.0 has been updated via 336c921146957a7416bc1717289a01f1b556ad82 (commit) via 18cd9aff9429c99ffae34448507f9b468e20e06f (commit) from 3330f00f54649cdd0914b6ff03c7b7bbc38ffa8d (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 336c921146957a7416bc1717289a01f1b556ad82 Author: Andy Wingo <wi...@pobox.com> Date: Mon Feb 18 16:38:24 2013 +0100 optimize access to arrays of rank 1 or 2 * libguile/array-handle.c (scm_array_handle_pos_1): (scm_array_handle_pos_2): New functions. * libguile/generalized-arrays.c (scm_c_array_ref_1, scm_c_array_ref_2): (scm_c_array_set_1_x, scm_c_array_set_2_x): New functions. (scm_i_array_ref, scm_i_array_set_x): New subr bindings for array-ref and array-set! that avoid consing for arrays of rank 1 or 2. * test-suite/tests/arrays.test ("array-set!"): Fix expected exception for wrong number of indices. commit 18cd9aff9429c99ffae34448507f9b468e20e06f Author: Andy Wingo <wi...@pobox.com> Date: Mon Feb 18 12:46:00 2013 +0100 array handle inline functions defined in array-handle.h. * libguile/inline.h: * libguile/array-handle.h (scm_array_handle_ref): (scm_array_handle_set): Move definitions here from inline.h. * libguile/inline.c: Include array-handle.h. ----------------------------------------------------------------------- Summary of changes: libguile/array-handle.c | 43 +++++++++++++++- libguile/array-handle.h | 36 ++++++++++++- libguile/generalized-arrays.c | 114 ++++++++++++++++++++++++++++++++++++----- libguile/generalized-arrays.h | 8 +++- libguile/inline.c | 3 +- libguile/inline.h | 25 +--------- test-suite/tests/arrays.test | 4 +- 7 files changed, 189 insertions(+), 44 deletions(-) diff --git a/libguile/array-handle.c b/libguile/array-handle.c index ec3127a..08778f3 100644 --- a/libguile/array-handle.c +++ b/libguile/array-handle.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1995,1996,1997,1998,2000,2001,2002,2003,2004, 2005, 2006, 2009 Free Software Foundation, Inc. +/* Copyright (C) 1995,1996,1997,1998,2000,2001,2002,2003,2004, 2005, 2006, 2009, 2013 Free Software Foundation, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License @@ -97,6 +97,47 @@ scm_array_handle_pos (scm_t_array_handle *h, SCM indices) return pos; } +static void +check_array_index_bounds (scm_t_array_dim *dim, ssize_t idx) +{ + if (idx < dim->lbnd || idx > dim->ubnd) + scm_error (scm_out_of_range_key, NULL, "Value out of range ~S to ~S: ~S", + scm_list_3 (scm_from_ssize_t (dim->lbnd), + scm_from_ssize_t (dim->ubnd), + scm_from_ssize_t (idx)), + scm_list_1 (scm_from_ssize_t (idx))); +} + +ssize_t +scm_array_handle_pos_1 (scm_t_array_handle *h, ssize_t idx0) +{ + scm_t_array_dim *dim = scm_array_handle_dims (h); + + if (scm_array_handle_rank (h) != 1) + scm_misc_error (NULL, "wrong number of indices, expecting ~A", + scm_list_1 (scm_from_size_t (scm_array_handle_rank (h)))); + + check_array_index_bounds (&dim[0], idx0); + + return (idx0 - dim[0].lbnd) * dim[0].inc; +} + +ssize_t +scm_array_handle_pos_2 (scm_t_array_handle *h, ssize_t idx0, ssize_t idx1) +{ + scm_t_array_dim *dim = scm_array_handle_dims (h); + + if (scm_array_handle_rank (h) != 2) + scm_misc_error (NULL, "wrong number of indices, expecting ~A", + scm_list_1 (scm_from_size_t (scm_array_handle_rank (h)))); + + check_array_index_bounds (&dim[0], idx0); + check_array_index_bounds (&dim[1], idx1); + + return ((idx0 - dim[0].lbnd) * dim[0].inc + + (idx1 - dim[1].lbnd) * dim[1].inc); +} + SCM scm_array_handle_element_type (scm_t_array_handle *h) { diff --git a/libguile/array-handle.h b/libguile/array-handle.h index 2e8af77..fa2449d 100644 --- a/libguile/array-handle.h +++ b/libguile/array-handle.h @@ -4,7 +4,7 @@ #define SCM_ARRAY_HANDLE_H /* Copyright (C) 1995, 1996, 1997, 1999, 2000, 2001, 2004, 2006, - * 2008, 2009, 2011 Free Software Foundation, Inc. + * 2008, 2009, 2011, 2013 Free Software Foundation, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License @@ -25,6 +25,8 @@ #include "libguile/__scm.h" +#include "libguile/error.h" +#include "libguile/numbers.h" @@ -112,12 +114,42 @@ typedef struct scm_t_array_handle { SCM_API void scm_array_get_handle (SCM array, scm_t_array_handle *h); SCM_API ssize_t scm_array_handle_pos (scm_t_array_handle *h, SCM indices); +SCM_API ssize_t scm_array_handle_pos_1 (scm_t_array_handle *h, ssize_t idx0); +SCM_API ssize_t scm_array_handle_pos_2 (scm_t_array_handle *h, ssize_t idx0, ssize_t idx1); SCM_API SCM scm_array_handle_element_type (scm_t_array_handle *h); SCM_API void scm_array_handle_release (scm_t_array_handle *h); SCM_API const SCM* scm_array_handle_elements (scm_t_array_handle *h); SCM_API SCM* scm_array_handle_writable_elements (scm_t_array_handle *h); -/* See inline.h for scm_array_handle_ref and scm_array_handle_set */ + +SCM_INLINE SCM scm_array_handle_ref (scm_t_array_handle *h, ssize_t pos); +SCM_INLINE void scm_array_handle_set (scm_t_array_handle *h, ssize_t pos, SCM val); + +#if SCM_CAN_INLINE || defined SCM_INLINE_C_IMPLEMENTING_INLINES +/* Either inlining, or being included from inline.c. */ + +SCM_INLINE_IMPLEMENTATION SCM +scm_array_handle_ref (scm_t_array_handle *h, ssize_t p) +{ + if (SCM_UNLIKELY (p < 0 && ((size_t)-p) > h->base)) + /* catch overflow */ + scm_out_of_range (NULL, scm_from_ssize_t (p)); + /* perhaps should catch overflow here too */ + return h->impl->vref (h, h->base + p); +} + +SCM_INLINE_IMPLEMENTATION void +scm_array_handle_set (scm_t_array_handle *h, ssize_t p, SCM v) +{ + if (SCM_UNLIKELY (p < 0 && ((size_t)-p) > h->base)) + /* catch overflow */ + scm_out_of_range (NULL, scm_from_ssize_t (p)); + /* perhaps should catch overflow here too */ + h->impl->vset (h, h->base + p, v); +} + +#endif + SCM_INTERNAL void scm_init_array_handle (void); diff --git a/libguile/generalized-arrays.c b/libguile/generalized-arrays.c index 3a0ce25..f5f41ac 100644 --- a/libguile/generalized-arrays.c +++ b/libguile/generalized-arrays.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1995,1996,1997,1998,2000,2001,2002,2003,2004, 2005, 2006, 2009, 2010 Free Software Foundation, Inc. +/* Copyright (C) 1995,1996,1997,1998,2000,2001,2002,2003,2004, 2005, 2006, 2009, 2010, 2013 Free Software Foundation, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License @@ -33,6 +33,12 @@ #include "libguile/generalized-arrays.h" +SCM_INTERNAL SCM scm_i_array_ref (SCM v, + SCM idx0, SCM idx1, SCM idxN); +SCM_INTERNAL SCM scm_i_array_set_x (SCM v, SCM obj, + SCM idx0, SCM idx1, SCM idxN); + + int scm_is_array (SCM obj) { @@ -195,11 +201,35 @@ SCM_DEFINE (scm_array_in_bounds_p, "array-in-bounds?", 1, 0, 1, } #undef FUNC_NAME -SCM_DEFINE (scm_array_ref, "array-ref", 1, 0, 1, - (SCM v, SCM args), - "Return the element at the @code{(index1, index2)} element in\n" - "array @var{v}.") -#define FUNC_NAME s_scm_array_ref + +SCM +scm_c_array_ref_1 (SCM array, ssize_t idx0) +{ + scm_t_array_handle handle; + SCM res; + + scm_array_get_handle (array, &handle); + res = scm_array_handle_ref (&handle, scm_array_handle_pos_1 (&handle, idx0)); + scm_array_handle_release (&handle); + return res; +} + + +SCM +scm_c_array_ref_2 (SCM array, ssize_t idx0, ssize_t idx1) +{ + scm_t_array_handle handle; + SCM res; + + scm_array_get_handle (array, &handle); + res = scm_array_handle_ref (&handle, scm_array_handle_pos_2 (&handle, idx0, idx1)); + scm_array_handle_release (&handle); + return res; +} + + +SCM +scm_array_ref (SCM v, SCM args) { scm_t_array_handle handle; SCM res; @@ -209,15 +239,34 @@ SCM_DEFINE (scm_array_ref, "array-ref", 1, 0, 1, scm_array_handle_release (&handle); return res; } -#undef FUNC_NAME -SCM_DEFINE (scm_array_set_x, "array-set!", 2, 0, 1, - (SCM v, SCM obj, SCM args), - "Set the element at the @code{(index1, index2)} element in array\n" - "@var{v} to @var{obj}. The value returned by @code{array-set!}\n" - "is unspecified.") -#define FUNC_NAME s_scm_array_set_x +void +scm_c_array_set_1_x (SCM array, SCM obj, ssize_t idx0) +{ + scm_t_array_handle handle; + + scm_array_get_handle (array, &handle); + scm_array_handle_set (&handle, scm_array_handle_pos_1 (&handle, idx0), + obj); + scm_array_handle_release (&handle); +} + + +void +scm_c_array_set_2_x (SCM array, SCM obj, ssize_t idx0, ssize_t idx1) +{ + scm_t_array_handle handle; + + scm_array_get_handle (array, &handle); + scm_array_handle_set (&handle, scm_array_handle_pos_2 (&handle, idx0, idx1), + obj); + scm_array_handle_release (&handle); +} + + +SCM +scm_array_set_x (SCM v, SCM obj, SCM args) { scm_t_array_handle handle; @@ -226,8 +275,47 @@ SCM_DEFINE (scm_array_set_x, "array-set!", 2, 0, 1, scm_array_handle_release (&handle); return SCM_UNSPECIFIED; } + + +SCM_DEFINE (scm_i_array_ref, "array-ref", 1, 2, 1, + (SCM v, SCM idx0, SCM idx1, SCM idxN), + "Return the element at the @code{(idx0, idx1, idxN...)}\n" + "position in array @var{v}.") +#define FUNC_NAME s_scm_i_array_ref +{ + if (SCM_UNBNDP (idx0)) + return scm_array_ref (v, SCM_EOL); + else if (SCM_UNBNDP (idx1)) + return scm_c_array_ref_1 (v, scm_to_ssize_t (idx0)); + else if (scm_is_null (idxN)) + return scm_c_array_ref_2 (v, scm_to_ssize_t (idx0), scm_to_ssize_t (idx1)); + else + return scm_array_ref (v, scm_cons (idx0, scm_cons (idx1, idxN))); +} #undef FUNC_NAME + +SCM_DEFINE (scm_i_array_set_x, "array-set!", 2, 2, 1, + (SCM v, SCM obj, SCM idx0, SCM idx1, SCM idxN), + "Set the element at the @code{(idx0, idx1, idxN...)} position\n" + "in the array @var{v} to @var{obj}. The value returned by\n" + "@code{array-set!} is unspecified.") +#define FUNC_NAME s_scm_i_array_set_x +{ + if (SCM_UNBNDP (idx0)) + scm_array_set_x (v, obj, SCM_EOL); + else if (SCM_UNBNDP (idx1)) + scm_c_array_set_1_x (v, obj, scm_to_ssize_t (idx0)); + else if (scm_is_null (idxN)) + scm_c_array_set_2_x (v, obj, scm_to_ssize_t (idx0), scm_to_ssize_t (idx1)); + else + scm_array_set_x (v, obj, scm_cons (idx0, scm_cons (idx1, idxN))); + + return SCM_UNSPECIFIED; +} +#undef FUNC_NAME + + static SCM array_to_list (scm_t_array_handle *h, size_t dim, unsigned long pos) { diff --git a/libguile/generalized-arrays.h b/libguile/generalized-arrays.h index 1f9b6ad..2ad34a1 100644 --- a/libguile/generalized-arrays.h +++ b/libguile/generalized-arrays.h @@ -3,7 +3,7 @@ #ifndef SCM_GENERALIZED_ARRAYS_H #define SCM_GENERALIZED_ARRAYS_H -/* Copyright (C) 1995,1996,1997,1999,2000,2001, 2004, 2006, 2008, 2009 Free Software Foundation, Inc. +/* Copyright (C) 1995,1996,1997,1999,2000,2001, 2004, 2006, 2008, 2009, 2013 Free Software Foundation, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License @@ -48,6 +48,12 @@ SCM_API SCM scm_array_dimensions (SCM ra); SCM_API SCM scm_array_type (SCM ra); SCM_API SCM scm_array_in_bounds_p (SCM v, SCM args); +SCM_API SCM scm_c_array_ref_1 (SCM v, ssize_t idx0); +SCM_API SCM scm_c_array_ref_2 (SCM v, ssize_t idx0, ssize_t idx1); + +SCM_API void scm_c_array_set_1_x (SCM v, SCM obj, ssize_t idx0); +SCM_API void scm_c_array_set_2_x (SCM v, SCM obj, ssize_t idx0, ssize_t idx1); + SCM_API SCM scm_array_ref (SCM v, SCM args); SCM_API SCM scm_array_set_x (SCM v, SCM obj, SCM args); SCM_API SCM scm_array_to_list (SCM v); diff --git a/libguile/inline.c b/libguile/inline.c index be7670a..5916794 100644 --- a/libguile/inline.c +++ b/libguile/inline.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2001, 2006, 2008, 2011 Free Software Foundation, Inc. +/* Copyright (C) 2001, 2006, 2008, 2011, 2013 Free Software Foundation, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License @@ -23,5 +23,6 @@ #define SCM_IMPLEMENT_INLINES 1 #define SCM_INLINE_C_IMPLEMENTING_INLINES 1 #include "libguile/inline.h" +#include "libguile/array-handle.h" #include "libguile/gc.h" #include "libguile/smob.h" diff --git a/libguile/inline.h b/libguile/inline.h index 6b1cf5e..88ba7f7 100644 --- a/libguile/inline.h +++ b/libguile/inline.h @@ -4,7 +4,7 @@ #define SCM_INLINE_H /* Copyright (C) 2001, 2002, 2003, 2004, 2006, 2008, 2009, 2010, - * 2011 Free Software Foundation, Inc. + * 2011, 2013 Free Software Foundation, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License @@ -41,9 +41,6 @@ #include "libguile/error.h" -SCM_INLINE SCM scm_array_handle_ref (scm_t_array_handle *h, ssize_t pos); -SCM_INLINE void scm_array_handle_set (scm_t_array_handle *h, ssize_t pos, SCM val); - SCM_INLINE int scm_is_pair (SCM x); SCM_INLINE int scm_is_string (SCM x); @@ -61,26 +58,6 @@ SCM_INLINE SCM scm_words (scm_t_bits car, scm_t_uint16 n_words); #if SCM_CAN_INLINE || defined SCM_INLINE_C_IMPLEMENTING_INLINES /* Either inlining, or being included from inline.c. */ -SCM_INLINE_IMPLEMENTATION SCM -scm_array_handle_ref (scm_t_array_handle *h, ssize_t p) -{ - if (SCM_UNLIKELY (p < 0 && ((size_t)-p) > h->base)) - /* catch overflow */ - scm_out_of_range (NULL, scm_from_ssize_t (p)); - /* perhaps should catch overflow here too */ - return h->impl->vref (h, h->base + p); -} - -SCM_INLINE_IMPLEMENTATION void -scm_array_handle_set (scm_t_array_handle *h, ssize_t p, SCM v) -{ - if (SCM_UNLIKELY (p < 0 && ((size_t)-p) > h->base)) - /* catch overflow */ - scm_out_of_range (NULL, scm_from_ssize_t (p)); - /* perhaps should catch overflow here too */ - h->impl->vset (h, h->base + p, v); -} - SCM_INLINE_IMPLEMENTATION int scm_is_pair (SCM x) { diff --git a/test-suite/tests/arrays.test b/test-suite/tests/arrays.test index f13b1a2..f00c12d 100644 --- a/test-suite/tests/arrays.test +++ b/test-suite/tests/arrays.test @@ -1,6 +1,6 @@ ;;;; unif.test --- tests guile's uniform arrays -*- scheme -*- ;;;; -;;;; Copyright 2004, 2006, 2009, 2010, 2011, 2012 Free Software Foundation, Inc. +;;;; Copyright 2004, 2006, 2009, 2010, 2011, 2012, 2013 Free Software Foundation, Inc. ;;;; ;;;; This library is free software; you can redistribute it and/or ;;;; modify it under the terms of the GNU Lesser General Public @@ -451,7 +451,7 @@ (array-set! a 'y 2)) (pass-if-exception "end+1" exception:out-of-range (array-set! a 'y 6)) - (pass-if-exception "two indexes" exception:out-of-range + (pass-if-exception "two indexes" exception:wrong-num-indices (array-set! a 'y 6 7)))) (with-test-prefix "two dim" hooks/post-receive -- GNU Guile