rewrite vector-fill! in c
This commit is contained in:
parent
4e895c97d0
commit
09bb977c50
|
@ -667,16 +667,6 @@
|
||||||
res))
|
res))
|
||||||
(fold vector-append-2-inv #() vs))
|
(fold vector-append-2-inv #() vs))
|
||||||
|
|
||||||
(define (vector-fill! v fill . opts)
|
|
||||||
(let ((start (if (pair? opts) (car opts) 0))
|
|
||||||
(end (if (>= (length opts) 2)
|
|
||||||
(cadr opts)
|
|
||||||
(vector-length v))))
|
|
||||||
(do ((i start (+ i 1)))
|
|
||||||
((= i end)
|
|
||||||
#f)
|
|
||||||
(vector-set! v i fill))))
|
|
||||||
|
|
||||||
(define (vector->string . args)
|
(define (vector->string . args)
|
||||||
(list->string (apply vector->list args)))
|
(list->string (apply vector->list args)))
|
||||||
|
|
||||||
|
|
24
src/vector.c
24
src/vector.c
|
@ -173,6 +173,29 @@ pic_vec_vector_copy(pic_state *pic)
|
||||||
return pic_obj_value(to);
|
return pic_obj_value(to);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static pic_value
|
||||||
|
pic_vec_vector_fill_i(pic_state *pic)
|
||||||
|
{
|
||||||
|
pic_vec *vec;
|
||||||
|
pic_value obj;
|
||||||
|
int n, start, end;
|
||||||
|
|
||||||
|
n = pic_get_args(pic, "vo|ii", &vec, &obj, &start, &end);
|
||||||
|
|
||||||
|
switch (n) {
|
||||||
|
case 2:
|
||||||
|
start = 0;
|
||||||
|
case 3:
|
||||||
|
end = vec->len;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (start < end) {
|
||||||
|
vec->data[start++] = obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
return pic_none_value();
|
||||||
|
}
|
||||||
|
|
||||||
static pic_value
|
static pic_value
|
||||||
pic_vec_list_to_vector(pic_state *pic)
|
pic_vec_list_to_vector(pic_state *pic)
|
||||||
{
|
{
|
||||||
|
@ -225,6 +248,7 @@ pic_init_vector(pic_state *pic)
|
||||||
pic_defun(pic, "vector-set!", pic_vec_vector_set);
|
pic_defun(pic, "vector-set!", pic_vec_vector_set);
|
||||||
pic_defun(pic, "vector-copy!", pic_vec_vector_copy_i);
|
pic_defun(pic, "vector-copy!", pic_vec_vector_copy_i);
|
||||||
pic_defun(pic, "vector-copy", pic_vec_vector_copy);
|
pic_defun(pic, "vector-copy", pic_vec_vector_copy);
|
||||||
|
pic_defun(pic, "vector-fill!", pic_vec_vector_fill_i);
|
||||||
pic_defun(pic, "list->vector", pic_vec_list_to_vector);
|
pic_defun(pic, "list->vector", pic_vec_list_to_vector);
|
||||||
pic_defun(pic, "vector->list", pic_vec_vector_to_list);
|
pic_defun(pic, "vector->list", pic_vec_vector_to_list);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue