diff --git a/libguile/bytevectors.c b/libguile/bytevectors.c index 52b531d02..70663880b 100644 --- a/libguile/bytevectors.c +++ b/libguile/bytevectors.c @@ -195,8 +195,6 @@ #define SCM_BYTEVECTOR_SET_PARENT(_bv, _parent) \ SCM_SET_CELL_OBJECT_3 ((_bv), (_parent)) -#define SCM_BYTEVECTOR_TYPE_SIZE(var) \ - (scm_i_array_element_type_sizes[SCM_BYTEVECTOR_ELEMENT_TYPE (var)]/8) #define SCM_BYTEVECTOR_TYPED_LENGTH(var) \ (SCM_BYTEVECTOR_LENGTH (var) / SCM_BYTEVECTOR_TYPE_SIZE (var)) @@ -2129,9 +2127,7 @@ bytevector_ref_c64 (SCM bv, SCM index) } #undef FUNC_NAME -typedef SCM (*scm_t_bytevector_ref_fn)(SCM, SCM); - -static const scm_t_bytevector_ref_fn +const scm_t_bytevector_ref_fn bytevector_ref_fns[SCM_ARRAY_ELEMENT_TYPE_LAST + 1] = { NULL, /* SCM */ @@ -2157,10 +2153,10 @@ bv_handle_ref (scm_t_array_handle *h, size_t index) { SCM byte_index; scm_t_bytevector_ref_fn ref_fn; - + ref_fn = bytevector_ref_fns[h->element_type]; byte_index = - scm_from_size_t (index * scm_array_handle_uniform_element_size (h)); + scm_from_size_t (index * SCM_BYTEVECTOR_TYPE_SIZE (h->array)); return ref_fn (h->array, byte_index); } @@ -2195,9 +2191,7 @@ bytevector_set_c64 (SCM bv, SCM index, SCM value) } #undef FUNC_NAME -typedef SCM (*scm_t_bytevector_set_fn)(SCM, SCM, SCM); - -const scm_t_bytevector_set_fn bytevector_set_fns[SCM_ARRAY_ELEMENT_TYPE_LAST + 1] = +const scm_t_bytevector_set_fn bytevector_set_fns[SCM_ARRAY_ELEMENT_TYPE_LAST + 1] = { NULL, /* SCM */ NULL, /* CHAR */ @@ -2222,10 +2216,10 @@ bv_handle_set_x (scm_t_array_handle *h, size_t index, SCM val) { SCM byte_index; scm_t_bytevector_set_fn set_fn; - + set_fn = bytevector_set_fns[h->element_type]; byte_index = - scm_from_size_t (index * scm_array_handle_uniform_element_size (h)); + scm_from_size_t (index * SCM_BYTEVECTOR_TYPE_SIZE (h->array)); set_fn (h->array, byte_index, val); } diff --git a/libguile/bytevectors.h b/libguile/bytevectors.h index a5eeaea0c..f93058977 100644 --- a/libguile/bytevectors.h +++ b/libguile/bytevectors.h @@ -112,6 +112,13 @@ SCM_API SCM scm_utf8_to_string (SCM); SCM_API SCM scm_utf16_to_string (SCM, SCM); SCM_API SCM scm_utf32_to_string (SCM, SCM); +typedef SCM (*scm_t_bytevector_ref_fn)(SCM, SCM); +SCM_INTERNAL const scm_t_bytevector_ref_fn +bytevector_ref_fns[SCM_ARRAY_ELEMENT_TYPE_LAST + 1]; + +typedef SCM (*scm_t_bytevector_set_fn)(SCM, SCM, SCM); +SCM_INTERNAL const scm_t_bytevector_set_fn +bytevector_set_fns[SCM_ARRAY_ELEMENT_TYPE_LAST + 1]; /* Internal API. */ @@ -128,6 +135,8 @@ SCM_API SCM scm_utf32_to_string (SCM, SCM); (SCM_BYTEVECTOR_FLAGS (_bv) & 0xffUL) #define SCM_BYTEVECTOR_CONTIGUOUS_P(_bv) \ (SCM_BYTEVECTOR_FLAGS (_bv) >> 8UL) +#define SCM_BYTEVECTOR_TYPE_SIZE(var) \ + (scm_i_array_element_type_sizes[SCM_BYTEVECTOR_ELEMENT_TYPE (var)]/8) /* Hint that is passed to `scm_gc_malloc ()' and friends. */ #define SCM_GC_BYTEVECTOR "bytevector" diff --git a/libguile/srfi-4.c b/libguile/srfi-4.c index c45519b1d..2491284bc 100644 --- a/libguile/srfi-4.c +++ b/libguile/srfi-4.c @@ -252,7 +252,8 @@ SCM_DEFINE (scm_make_srfi_4_vector, "make-srfi-4-vector", 2, 1, 0, case SCM_ARRAY_ELEMENT_TYPE_C32: case SCM_ARRAY_ELEMENT_TYPE_C64: { - SCM ret = scm_i_make_typed_bytevector (scm_to_size_t (len), i); + size_t clen = scm_to_size_t (len); + SCM ret = scm_i_make_typed_bytevector (clen, i); if (SCM_UNBNDP (fill) || scm_is_eq (len, SCM_INUM0)) ; /* pass */ @@ -261,19 +262,12 @@ SCM_DEFINE (scm_make_srfi_4_vector, "make-srfi-4-vector", 2, 1, 0, SCM_BYTEVECTOR_LENGTH (ret)); else { - scm_t_array_handle h; - size_t len; - ssize_t pos, inc; - - scm_uniform_vector_writable_elements (ret, &h, &len, &inc); - - for (pos = 0; pos != h.dims[0].ubnd; pos += inc) - scm_array_handle_set (&h, pos, fill); - - /* Initialize the last element. */ - scm_array_handle_set (&h, pos, fill); - - scm_array_handle_release (&h); + scm_t_bytevector_set_fn set_fn = + bytevector_set_fns[SCM_BYTEVECTOR_ELEMENT_TYPE (ret)]; + size_t step = SCM_BYTEVECTOR_TYPE_SIZE (ret); + size_t pos = 0; + for (pos = 0, clen *= step; pos < clen; pos += step) + set_fn(ret, scm_from_size_t (pos), fill); } return ret; }