guile-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Guile-commits] 02/27: Require vector as argument to vector->list


From: Daniel Llorens
Subject: [Guile-commits] 02/27: Require vector as argument to vector->list
Date: Wed, 8 Apr 2020 04:03:45 -0400 (EDT)

lloda pushed a commit to branch wip-vector-cleanup
in repository guile.

commit c5ed75e553df695af4439fb500972ecc0bfee07d
Author: Daniel Llorens <address@hidden>
AuthorDate: Mon Feb 3 11:42:01 2020 +0100

    Require vector as argument to vector->list
    
    * libguile/vectors.c (vector->list): As stated. Simplify.
    * test-suite/tests/vectors.test: Remove shared array test.
---
 libguile/vectors.c            | 19 ++++++-------------
 test-suite/tests/vectors.test |  6 +-----
 2 files changed, 7 insertions(+), 18 deletions(-)

diff --git a/libguile/vectors.c b/libguile/vectors.c
index 5d2eaf9..fe07c6b 100644
--- a/libguile/vectors.c
+++ b/libguile/vectors.c
@@ -280,8 +280,8 @@ SCM_DEFINE (scm_vector_copy, "vector-copy", 1, 0, 0,
 
 
 SCM_DEFINE (scm_vector_to_list, "vector->list", 1, 0, 0, 
-           (SCM v),
-           "Return a newly allocated list composed of the elements of 
@var{v}.\n"
+           (SCM vec),
+           "Return a newly allocated list composed of the elements of 
@var{vec}.\n"
            "\n"
            "@lisp\n"
            "(vector->list '#(dah dah didah)) @result{}  (dah dah didah)\n"
@@ -289,19 +289,12 @@ SCM_DEFINE (scm_vector_to_list, "vector->list", 1, 0, 0,
            "@end lisp")
 #define FUNC_NAME s_scm_vector_to_list
 {
+  SCM_VALIDATE_VECTOR(1, vec);
   SCM res = SCM_EOL;
-  const SCM *data;
-  scm_t_array_handle handle;
-  size_t i, count, len;
-  ssize_t inc;
-
-  data = scm_vector_elements (v, &handle, &len, &inc);
-  for (i = (len - 1) * inc, count = 0;
-       count < len;
-       i -= inc, count++)
+  ssize_t len = SCM_I_VECTOR_LENGTH (vec);
+  const SCM * data = SCM_I_VECTOR_ELTS (vec);
+  for (ssize_t i = len-1; i >= 0; --i)
     res = scm_cons (data[i], res);
-
-  scm_array_handle_release (&handle);
   return res;
 }
 #undef FUNC_NAME
diff --git a/test-suite/tests/vectors.test b/test-suite/tests/vectors.test
index 97b3f18..6db608c 100644
--- a/test-suite/tests/vectors.test
+++ b/test-suite/tests/vectors.test
@@ -41,11 +41,7 @@
 
   (pass-if "string-vector 2"
     (equal? '("abc\u0100" "def\u0101" "ghi\u0102") 
-            (vector->list #("abc\u0100" "def\u0101" "ghi\u0102"))))
-
-  (pass-if "shared array"
-    (let ((b (make-shared-array #(1) (lambda (x) '(0)) 2)))
-      (equal? b (list->vector (vector->list b))))))
+            (vector->list #("abc\u0100" "def\u0101" "ghi\u0102")))))
 
 (with-test-prefix "make-vector"
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]