[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Guile-commits] 04/16: Reuse SCM_BYTEVECTOR_TYPED_LENGTH in scm_array_ge
From: |
Daniel Llorens |
Subject: |
[Guile-commits] 04/16: Reuse SCM_BYTEVECTOR_TYPED_LENGTH in scm_array_get_handle |
Date: |
Thu, 05 Nov 2015 09:13:00 +0000 |
lloda pushed a commit to branch lloda-array-support
in repository guile.
commit 0d6474b6d6d14047c6f5c0c13cfe8a340b54e41e
Author: Daniel Llorens <address@hidden>
Date: Wed Feb 11 12:58:01 2015 +0100
Reuse SCM_BYTEVECTOR_TYPED_LENGTH in scm_array_get_handle
* libguile/bytevectors.h (SCM_BYTEVECTOR_TYPE_SIZE,
SCM_BYTEVECTOR_TYPED_LENGTH): moved from libguile/bytevectors.c.
* libguile/array-handle.c (scm_array_get_handle): reuse
SCM_BYTEVECTOR_TYPED_LENGTH.
---
libguile/array-handle.c | 12 +++++-------
libguile/bytevectors.c | 13 ++++---------
libguile/bytevectors.h | 5 +++++
3 files changed, 14 insertions(+), 16 deletions(-)
diff --git a/libguile/array-handle.c b/libguile/array-handle.c
index 2252ecc..17be456 100644
--- a/libguile/array-handle.c
+++ b/libguile/array-handle.c
@@ -1,6 +1,6 @@
/* Copyright (C) 1995,1996,1997,1998,2000,2001,2002,2003,2004, 2005,
* 2006, 2009, 2011, 2013, 2014 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
* as published by the Free Software Foundation; either version 3 of
@@ -185,15 +185,13 @@ scm_array_get_handle (SCM array, scm_t_array_handle *h)
break;
case scm_tc7_bytevector:
{
- size_t byte_length, length, element_byte_size;
+ size_t length;
scm_t_array_element_type element_type;
scm_t_vector_ref vref;
scm_t_vector_set vset;
- byte_length = scm_c_bytevector_length (array);
element_type = SCM_BYTEVECTOR_ELEMENT_TYPE (array);
- element_byte_size = scm_i_array_element_type_sizes[element_type] / 8;
- length = byte_length / element_byte_size;
+ length = SCM_BYTEVECTOR_TYPED_LENGTH (array);
switch (element_type)
{
@@ -248,7 +246,7 @@ scm_array_handle_pos (scm_t_array_handle *h, SCM indices)
scm_t_array_dim *s = scm_array_handle_dims (h);
ssize_t pos = 0, i;
size_t k = scm_array_handle_rank (h);
-
+
while (k > 0 && scm_is_pair (indices))
{
i = scm_to_signed_integer (SCM_CAR (indices), s->lbnd, s->ubnd);
@@ -340,7 +338,7 @@ scm_init_array_handle (void)
{
#define DEFINE_ARRAY_TYPE(tag, TAG) \
scm_i_array_element_types[SCM_ARRAY_ELEMENT_TYPE_##TAG] =
scm_from_utf8_symbol (#tag)
-
+
scm_i_array_element_types[SCM_ARRAY_ELEMENT_TYPE_SCM] = SCM_BOOL_T;
DEFINE_ARRAY_TYPE (a, CHAR);
DEFINE_ARRAY_TYPE (b, BIT);
diff --git a/libguile/bytevectors.c b/libguile/bytevectors.c
index 41d5b6c..15c88e4 100644
--- a/libguile/bytevectors.c
+++ b/libguile/bytevectors.c
@@ -192,11 +192,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))
-
/* The empty bytevector. */
SCM scm_null_bytevector = SCM_UNSPECIFIED;
@@ -414,7 +409,7 @@ scm_i_print_bytevector (SCM bv, SCM port, scm_print_state
*pstate SCM_UNUSED)
{
ssize_t ubnd, inc, i;
scm_t_array_handle h;
-
+
scm_array_get_handle (bv, &h);
scm_putc_unlocked ('#', port);
@@ -643,7 +638,7 @@ SCM_DEFINE (scm_uniform_array_to_bytevector,
"uniform-array->bytevector",
size_t len, sz, byte_len;
scm_t_array_handle h;
const void *elts;
-
+
contents = scm_array_contents (array, SCM_BOOL_T);
if (scm_is_false (contents))
scm_wrong_type_arg_msg (FUNC_NAME, 0, array, "uniform contiguous array");
@@ -1939,7 +1934,7 @@ utf_encoding_name (char *name, size_t utf_width, SCM
endianness)
memcpy (SCM_BYTEVECTOR_CONTENTS (utf), c_utf, c_utf_len); \
scm_dynwind_end (); \
\
- return (utf);
+ return (utf);
@@ -2000,7 +1995,7 @@ SCM_DEFINE (scm_string_to_utf32, "string->utf32",
if (!scm_is_eq (SCM_UNBNDP (endianness) ? scm_endianness_big : endianness,
scm_i_native_endianness))
swap_u32 (wchars, wchar_len);
-
+
bv = make_bytevector (bytes_len, SCM_ARRAY_ELEMENT_TYPE_VU8);
memcpy (SCM_BYTEVECTOR_CONTENTS (bv), wchars, bytes_len);
free (wchars);
diff --git a/libguile/bytevectors.h b/libguile/bytevectors.h
index a5eeaea..af4ac1c 100644
--- a/libguile/bytevectors.h
+++ b/libguile/bytevectors.h
@@ -129,6 +129,11 @@ SCM_API SCM scm_utf32_to_string (SCM, SCM);
#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)
+#define SCM_BYTEVECTOR_TYPED_LENGTH(var) \
+ (SCM_BYTEVECTOR_LENGTH (var) / SCM_BYTEVECTOR_TYPE_SIZE (var))
+
/* Hint that is passed to `scm_gc_malloc ()' and friends. */
#define SCM_GC_BYTEVECTOR "bytevector"
- [Guile-commits] branch lloda-array-support updated (c00c74c -> 5adfbef), Daniel Llorens, 2015/11/05
- [Guile-commits] 01/16: Avoid unneeded internal use of array handles, Daniel Llorens, 2015/11/05
- [Guile-commits] 04/16: Reuse SCM_BYTEVECTOR_TYPED_LENGTH in scm_array_get_handle,
Daniel Llorens <=
- [Guile-commits] 03/16: Unuse array 'contiguous' flag, Daniel Llorens, 2015/11/05
- [Guile-commits] 06/16: New functions array-from, array-from*, array-set-from!, Daniel Llorens, 2015/11/05
- [Guile-commits] 05/16: Compile in C99 mode, Daniel Llorens, 2015/11/05
- [Guile-commits] 08/16: Rename array-set-from!, scm_array_set_from_x to array-amend!, scm_array_amend_x, Daniel Llorens, 2015/11/05
- [Guile-commits] 02/16: Remove scm_from_contiguous_array, Daniel Llorens, 2015/11/05
- [Guile-commits] 07/16: Tests & doc for array-from, array-from*, array-set-from!, Daniel Llorens, 2015/11/05
- [Guile-commits] 09/16: Don't use array handles in scm_c_array_rank, Daniel Llorens, 2015/11/05
- [Guile-commits] 11/16: Remove deprecated array functions, Daniel Llorens, 2015/11/05
- [Guile-commits] 13/16: Remove deprecated and unused generalized-vector functions, Daniel Llorens, 2015/11/05
- [Guile-commits] 10/16: Fix compilation of rank 0 typed array literals, Daniel Llorens, 2015/11/05