mirror of
https://github.com/justinethier/cyclone.git
synced 2025-07-15 16:57:35 +02:00
Bugfixes:
- Avoid unnecessary calls to `strlen` - Type check the `fill` parameter to `make-string`
This commit is contained in:
parent
4a77296ddf
commit
6aaa600ebc
1 changed files with 10 additions and 5 deletions
|
@ -951,11 +951,16 @@
|
||||||
"(void *data, int argc, closure _, object k, object count, object fill)"
|
"(void *data, int argc, closure _, object k, object count, object fill)"
|
||||||
" object s = NULL;
|
" object s = NULL;
|
||||||
char ch_buf[5];
|
char ch_buf[5];
|
||||||
|
char_type c;
|
||||||
|
int buflen, num_cp, len;
|
||||||
Cyc_check_int(data, count);
|
Cyc_check_int(data, count);
|
||||||
char_type c = obj_obj2char(fill);
|
if (!obj_is_char(fill)) {
|
||||||
Cyc_utf8_encode_char(ch_buf, 5, c);
|
Cyc_rt_raise2(data, \"Expected character buf received\", fill);
|
||||||
int num_cp = obj_obj2int(count);
|
}
|
||||||
int len = num_cp * strlen(ch_buf);
|
c = obj_obj2char(fill);
|
||||||
|
buflen = Cyc_utf8_encode_char(ch_buf, 5, c);
|
||||||
|
num_cp = obj_obj2int(count);
|
||||||
|
len = num_cp * buflen;
|
||||||
if (len >= MAX_STACK_OBJ) {
|
if (len >= MAX_STACK_OBJ) {
|
||||||
int heap_grown;
|
int heap_grown;
|
||||||
s = gc_alloc(((gc_thread_data *)data)->heap,
|
s = gc_alloc(((gc_thread_data *)data)->heap,
|
||||||
|
@ -982,7 +987,7 @@
|
||||||
memset(((string_type *)s)->str, ch_buf[0], len);
|
memset(((string_type *)s)->str, ch_buf[0], len);
|
||||||
} else {
|
} else {
|
||||||
char *buf = ((string_type *)s)->str;
|
char *buf = ((string_type *)s)->str;
|
||||||
int bi, si, slen = strlen(ch_buf);
|
int bi, si, slen = buflen;
|
||||||
for (bi = 0, si = 0; bi < len; bi++, si++) {
|
for (bi = 0, si = 0; bi < len; bi++, si++) {
|
||||||
buf[bi] = ch_buf[si % slen];
|
buf[bi] = ch_buf[si % slen];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue