summaryrefslogtreecommitdiffstats
path: root/lib.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2015-09-07 07:21:02 -0700
committerKaz Kylheku <kaz@kylheku.com>2015-09-07 07:21:02 -0700
commita31ad16733b6da5a45803a9482e330d17f690636 (patch)
tree4bc8f872f823a0020652c6c6fe86c697982ec7a7 /lib.c
parentdcc75348c720acd6c2a0587bca34f7851e6c1283 (diff)
downloadtxr-a31ad16733b6da5a45803a9482e330d17f690636.tar.gz
txr-a31ad16733b6da5a45803a9482e330d17f690636.tar.bz2
txr-a31ad16733b6da5a45803a9482e330d17f690636.zip
Don't use prot1 for temporary gc protection.
* lib.c (split_str, split_str_set, list_str, int_str): Use gc_hint rather than prot1/rel1. More efficient, doesn't use space in the prot_stack array. * regex.c (search_regex): Likewise. * stream.c (vformat_str, formatv, run): Likewise. In formatv, rel1 wasn't being called in the uw_unwind block, so this fixes a bug.
Diffstat (limited to 'lib.c')
-rw-r--r--lib.c26
1 files changed, 8 insertions, 18 deletions
diff --git a/lib.c b/lib.c
index fbabda77..e855cb82 100644
--- a/lib.c
+++ b/lib.c
@@ -3011,15 +3011,13 @@ val split_str(val str, val sep)
if (*cstr) {
list_collect_decl (out, iter);
- prot1(&str);
-
for (; *cstr; cstr++) {
val piece = mkustring(one);
init_str(piece, cstr);
iter = list_collect(iter, piece);
}
- rel1(&str);
+ gc_hint(str);
return out;
} else {
@@ -3032,9 +3030,6 @@ val split_str(val str, val sep)
list_collect_decl (out, iter);
- prot1(&str);
- prot1(&sep);
-
for (;;) {
const wchar_t *psep = wcsstr(cstr, csep);
size_t span = (psep != 0) ? psep - cstr : wcslen(cstr);
@@ -3049,8 +3044,8 @@ val split_str(val str, val sep)
break;
}
- rel1(&sep);
- rel1(&str);
+ gc_hint(sep);
+ gc_hint(str);
return out;
}
@@ -3063,9 +3058,6 @@ val split_str_set(val str, val set)
const wchar_t *cset = c_str(set);
list_collect_decl (out, iter);
- prot1(&str);
- prot1(&set);
-
for (;;) {
size_t span = wcscspn(cstr, cset);
val piece = mkustring(num(span));
@@ -3079,8 +3071,8 @@ val split_str_set(val str, val set)
break;
}
- rel1(&set);
- rel1(&str);
+ gc_hint(set);
+ gc_hint(str);
return out;
}
@@ -3146,12 +3138,10 @@ val list_str(val str)
const wchar_t *cstr = c_str(str);
list_collect_decl (out, iter);
- prot1(&str);
-
while (*cstr)
iter = list_collect(iter, chr(*cstr++));
- rel1(&str);
+ gc_hint(str);
return out;
}
@@ -3283,12 +3273,12 @@ val int_str(val str, val base)
return nil;
if ((value == LONG_MAX || value == LONG_MIN) && errno == ERANGE) {
- val bignum = (prot1(&str), make_bignum());
+ val bignum = make_bignum();
unsigned char *ucs = utf8_dup_to_uc(wcs);
mp_err err = mp_read_radix(mp(bignum), ucs, b);
free(ucs); /* TODO: make wchar_t version of mp_read_radix. */
- rel1(&str);
+ gc_hint(str);
if (err != MP_OKAY)
return nil;