summaryrefslogtreecommitdiff
path: root/libguile/vectors.c
diff options
context:
space:
mode:
authorDaniel Llorens <lloda@sarc.name>2021-08-17 16:47:04 +0200
committerDaniel Llorens <lloda@sarc.name>2021-08-17 16:47:04 +0200
commit9a62f7cacaf730fca07f6cfd400a1893c2c2acb6 (patch)
tree47af3f85a9adc4703da274c771e893c4b73ee3ae /libguile/vectors.c
parent926f70f9b589eaa43e9b066e8cdd58e0d67435ed (diff)
downloadguile-9a62f7cacaf730fca07f6cfd400a1893c2c2acb6.tar.gz
Extend bytevector-fill! to handle a partial fill
* libguile/bytevectors.c (bytevector-fill!): As stated. (scm_bytevector_fill_x): Stub to avoid changing the C API. * doc/ref/api-data.texi: Documentation. * libguile/vectors.c (vector-fill!): Less confusing variable names. * test-suite/tests/bytevectors.test: Test partial fill cases for bytevector-fill!.
Diffstat (limited to 'libguile/vectors.c')
-rw-r--r--libguile/vectors.c17
1 files changed, 7 insertions, 10 deletions
diff --git a/libguile/vectors.c b/libguile/vectors.c
index a71f51e28..8cbd201f5 100644
--- a/libguile/vectors.c
+++ b/libguile/vectors.c
@@ -412,27 +412,24 @@ static SCM scm_vector_fill_partial_x (SCM vec, SCM fill, SCM start, SCM end);
SCM_DEFINE_STATIC (scm_vector_fill_partial_x, "vector-fill!", 2, 2, 0,
(SCM vec, SCM fill, SCM start, SCM end),
- "Assign the value of every location in vector @var{vec} between\n"
- "@var{start} and @var{end} to @var{fill}. @var{start} defaults\n"
+ "Assign the value of every location in vector @var{vec} in the range\n"
+ "[@var{start} ... @var{end}) to @var{fill}. @var{start} defaults\n"
"to 0 and @var{end} defaults to the length of @var{vec}. The value\n"
"returned by @code{vector-fill!} is unspecified.")
#define FUNC_NAME s_scm_vector_fill_partial_x
{
SCM_VALIDATE_MUTABLE_VECTOR(1, vec);
- SCM *data;
size_t i = 0;
- size_t len = SCM_I_VECTOR_LENGTH (vec);
-
- data = SCM_I_VECTOR_WELTS (vec);
+ size_t c_end = SCM_I_VECTOR_LENGTH (vec);
+ SCM *data = SCM_I_VECTOR_WELTS (vec);
if (!SCM_UNBNDP (start))
- i = scm_to_unsigned_integer (start, 0, len);
-
+ i = scm_to_unsigned_integer (start, 0, c_end);
if (!SCM_UNBNDP (end))
- len = scm_to_unsigned_integer (end, i, len);
+ c_end = scm_to_unsigned_integer (end, i, c_end);
- for (; i < len; ++i)
+ for (; i < c_end; ++i)
data[i] = fill;
return SCM_UNSPECIFIED;