guile-commits
[Top][All Lists]
Advanced

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

[Guile-commits] 01/04: Avoid double initialization in 'vector-copy'.


From: Ludovic Courtès
Subject: [Guile-commits] 01/04: Avoid double initialization in 'vector-copy'.
Date: Mon, 23 Mar 2020 17:50:32 -0400 (EDT)

civodul pushed a commit to branch master
in repository guile.

commit 168ad279e6bb4be0393a0a23943af535925767fb
Author: Ludovic Courtès <address@hidden>
AuthorDate: Mon Mar 23 11:33:03 2020 +0100

    Avoid double initialization in 'vector-copy'.
    
    * libguile/vectors.c (make_vector): New function.
    (scm_c_make_vector): Use it instead of 'scm_words'.
    (scm_vector_copy): Use it instead of 'scm_c_make_vector'.
---
 libguile/vectors.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/libguile/vectors.c b/libguile/vectors.c
index 1578841..0f1e608 100644
--- a/libguile/vectors.c
+++ b/libguile/vectors.c
@@ -1,4 +1,4 @@
-/* Copyright 1995-1996,1998-2001,2006,2008-2012,2014,2018-2019
+/* Copyright 1995-1996,1998-2001,2006,2008-2012,2014,2018-2020
      Free Software Foundation, Inc.
 
    This file is part of Guile.
@@ -241,6 +241,11 @@ SCM_DEFINE (scm_make_vector, "make-vector", 1, 1, 0,
 }
 #undef FUNC_NAME
 
+static SCM
+make_vector (size_t size)
+{
+  return scm_words ((size << 8) | scm_tc7_vector, size + 1);
+}
 
 SCM
 scm_c_make_vector (size_t k, SCM fill)
@@ -251,8 +256,7 @@ scm_c_make_vector (size_t k, SCM fill)
 
   SCM_ASSERT_RANGE (1, scm_from_size_t (k), k <= VECTOR_MAX_LENGTH);
 
-  vector = scm_words ((k << 8) | scm_tc7_vector, k + 1);
-
+  vector = make_vector (k);
   for (j = 0; j < k; ++j)
     SCM_SIMPLE_VECTOR_SET (vector, j, fill);
 
@@ -273,7 +277,7 @@ SCM_DEFINE (scm_vector_copy, "vector-copy", 1, 0, 0,
 
   src = scm_vector_elements (vec, &handle, &len, &inc);
 
-  result = scm_c_make_vector (len, SCM_UNDEFINED);
+  result = make_vector (len);
   dst = SCM_I_VECTOR_WELTS (result);
   for (i = 0; i < len; i++, src += inc)
     dst[i] = *src;



reply via email to

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