[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Guile-commits] 27/27: Reuse SCM_ASSERT_RANGE in scm_c_vector_ref, scm_c
From: |
Daniel Llorens |
Subject: |
[Guile-commits] 27/27: Reuse SCM_ASSERT_RANGE in scm_c_vector_ref, scm_c_vector_set_x |
Date: |
Thu, 20 Feb 2020 03:45:48 -0500 (EST) |
lloda pushed a commit to branch wip-vector-cleanup
in repository guile.
commit 6c995bc6f34c4e956cbf3b3fbf5ecc1f8f8f2ae5
Author: Daniel Llorens <address@hidden>
AuthorDate: Thu Feb 13 13:05:09 2020 +0100
Reuse SCM_ASSERT_RANGE in scm_c_vector_ref, scm_c_vector_set_x
---
libguile/vectors.c | 18 ++++--------------
1 file changed, 4 insertions(+), 14 deletions(-)
diff --git a/libguile/vectors.c b/libguile/vectors.c
index 8047729..b0e8ee2 100644
--- a/libguile/vectors.c
+++ b/libguile/vectors.c
@@ -162,10 +162,7 @@ scm_c_vector_ref (SCM v, size_t k)
#define FUNC_NAME s_scm_vector_ref
{
SCM_VALIDATE_VECTOR (1, v);
-
- if (k >= SCM_I_VECTOR_LENGTH (v))
- scm_out_of_range (NULL, scm_from_size_t (k));
-
+ SCM_ASSERT_RANGE (2, scm_from_size_t (k), k < SCM_I_VECTOR_LENGTH (v));
return SCM_VECTOR_REF (v, k);
}
#undef FUNC_NAME
@@ -193,10 +190,7 @@ scm_c_vector_set_x (SCM v, size_t k, SCM obj)
#define FUNC_NAME s_scm_vector_set_x
{
SCM_VALIDATE_MUTABLE_VECTOR (1, v);
-
- if (k >= SCM_I_VECTOR_LENGTH (v))
- scm_out_of_range (NULL, scm_from_size_t (k));
-
+ SCM_ASSERT_RANGE (2, scm_from_size_t (k), k < SCM_I_VECTOR_LENGTH (v));
SCM_VECTOR_SET (v, k, obj);
}
#undef FUNC_NAME
@@ -223,14 +217,10 @@ SCM
scm_c_make_vector (size_t k, SCM fill)
#define FUNC_NAME s_scm_make_vector
{
- SCM vector;
- size_t j;
-
SCM_ASSERT_RANGE (1, scm_from_size_t (k), k <= VECTOR_MAX_LENGTH);
+ SCM vector = scm_words ((k << 8) | scm_tc7_vector, k + 1);
- vector = scm_words ((k << 8) | scm_tc7_vector, k + 1);
-
- for (j = 0; j < k; ++j)
+ for (size_t j = 0; j < k; ++j)
SCM_VECTOR_SET (vector, j, fill);
return vector;
- [Guile-commits] 09/27: Simplify interfaces to scm_TYPEvector_(writable_)elements, (continued)
- [Guile-commits] 09/27: Simplify interfaces to scm_TYPEvector_(writable_)elements, Daniel Llorens, 2020/02/20
- [Guile-commits] 16/27: Pull generalized-vectors from under bitvector/string/vector, Daniel Llorens, 2020/02/20
- [Guile-commits] 18/27: Pull generalized-vectors from under bytevectors, Daniel Llorens, 2020/02/20
- [Guile-commits] 20/27: Update branch news file, Daniel Llorens, 2020/02/20
- [Guile-commits] 26/27: Simplify vector constructor, Daniel Llorens, 2020/02/20
- [Guile-commits] 24/27: Move uniform-array->bytevector from (rnrs bytevectors) to core, Daniel Llorens, 2020/02/20
- [Guile-commits] 17/27: Pull generalized-vectors from under typed vectors, Daniel Llorens, 2020/02/20
- [Guile-commits] 15/27: Rewrite vector-copy! using memmove, Daniel Llorens, 2020/02/20
- [Guile-commits] 05/27: Simple vectors are just vectors, Daniel Llorens, 2020/02/20
- [Guile-commits] 23/27: Remove 'contiguous' flag in arrays, Daniel Llorens, 2020/02/20
- [Guile-commits] 27/27: Reuse SCM_ASSERT_RANGE in scm_c_vector_ref, scm_c_vector_set_x,
Daniel Llorens <=
- [Guile-commits] 21/27: Merge generalized-arrays.[ch] in arrays.[ch], Daniel Llorens, 2020/02/20
- [Guile-commits] 19/27: Remove generalized-vectors.[hc], Daniel Llorens, 2020/02/20
- [Guile-commits] 25/27: Remove superfluous type check in bitvector->list, Daniel Llorens, 2020/02/20