rewrite bytevector-append in c
This commit is contained in:
parent
cba4a6ebf5
commit
bdd15261b1
|
@ -651,14 +651,6 @@
|
|||
v)
|
||||
(bytevector-u8-set! v i (car l))))))
|
||||
|
||||
(define (bytevector-append . vs)
|
||||
(define (bytevector-append-2-inv w v)
|
||||
(let ((res (make-bytevector (+ (bytevector-length v) (bytevector-length w)))))
|
||||
(bytevector-copy! res 0 v)
|
||||
(bytevector-copy! res (bytevector-length v) w)
|
||||
res))
|
||||
(fold bytevector-append-2-inv #u8() vs))
|
||||
|
||||
(define (bytevector->list v start end)
|
||||
(do ((i start (+ i 1))
|
||||
(res '()))
|
||||
|
@ -686,7 +678,6 @@
|
|||
(export bytevector
|
||||
bytevector->list
|
||||
list->bytevector
|
||||
bytevector-append
|
||||
utf8->string
|
||||
string->utf8)
|
||||
|
||||
|
|
29
src/blob.c
29
src/blob.c
|
@ -154,6 +154,34 @@ pic_blob_bytevector_copy(pic_state *pic)
|
|||
return pic_obj_value(to);
|
||||
}
|
||||
|
||||
static pic_value
|
||||
pic_blob_bytevector_append(pic_state *pic)
|
||||
{
|
||||
size_t argc, i, j, len;
|
||||
pic_value *argv;
|
||||
pic_blob *blob;
|
||||
|
||||
pic_get_args(pic, "*", &argc, &argv);
|
||||
|
||||
len = 0;
|
||||
for (i = 0; i < argc; ++i) {
|
||||
pic_assert_type(pic, argv[i], blob);
|
||||
len += pic_blob_ptr(argv[i])->len;
|
||||
}
|
||||
|
||||
blob = pic_blob_new(pic, len);
|
||||
|
||||
len = 0;
|
||||
for (i = 0; i < argc; ++i) {
|
||||
for (j = 0; j < pic_blob_ptr(argv[i])->len; ++j) {
|
||||
blob->data[len + j] = pic_blob_ptr(argv[i])->data[j];
|
||||
}
|
||||
len += pic_blob_ptr(argv[i])->len;
|
||||
}
|
||||
|
||||
return pic_obj_value(blob);
|
||||
}
|
||||
|
||||
void
|
||||
pic_init_blob(pic_state *pic)
|
||||
{
|
||||
|
@ -164,4 +192,5 @@ pic_init_blob(pic_state *pic)
|
|||
pic_defun(pic, "bytevector-u8-set!", pic_blob_bytevector_u8_set);
|
||||
pic_defun(pic, "bytevector-copy!", pic_blob_bytevector_copy_i);
|
||||
pic_defun(pic, "bytevector-copy", pic_blob_bytevector_copy);
|
||||
pic_defun(pic, "bytevector-append", pic_blob_bytevector_append);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue