summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2015-09-26 08:41:51 -0700
committerKaz Kylheku <kaz@kylheku.com>2015-09-26 08:41:51 -0700
commite5145afe93cd5290878ac432aea87da9c70d1263 (patch)
treed077e689f6fab67a5c8e7925e45f4e16d3f5b011
parentfedad1f30832e6b92ac87aaa39758758e783ceb7 (diff)
downloadtxr-e5145afe93cd5290878ac432aea87da9c70d1263.tar.gz
txr-e5145afe93cd5290878ac432aea87da9c70d1263.tar.bz2
txr-e5145afe93cd5290878ac432aea87da9c70d1263.zip
Don't force lazy string in string input streams.
* stream.c (find_char): Don't extract C string from string; use abstract access to find the character, without calculating length. (string_in_get_line, string_in_get_char): Don't calculate the length of the string to compare it to the position; use the lazy-safe length_str_gt function instead.
-rw-r--r--stream.c16
1 files changed, 5 insertions, 11 deletions
diff --git a/stream.c b/stream.c
index 5e249267..d001f704 100644
--- a/stream.c
+++ b/stream.c
@@ -1233,15 +1233,9 @@ static void string_in_stream_mark(val stream)
static val find_char(val string, val start, val ch)
{
- const wchar_t *str = c_str(string);
- cnum pos = c_num(start);
- cnum len = c_num(length_str(string));
- wchar_t c = c_chr(ch);
-
- for (; pos < len; pos++) {
- if (str[pos] == c)
- return num(pos);
- }
+ for (; length_str_gt(string, start); start = succ(start))
+ if (chr_str(string, start) == ch)
+ return start;
return nil;
}
@@ -1250,7 +1244,7 @@ static val string_in_get_line(val stream)
{
struct string_in *s = coerce(struct string_in *, stream->co.handle);
- if (lt(s->pos, length_str(s->string))) {
+ if (length_str_gt(s->string, s->pos)) {
val nlpos = find_char(s->string, s->pos, chr('\n'));
val result = sub_str(s->string, s->pos, nlpos);
set(mkloc(s->pos, stream), nlpos ? plus(nlpos, one) : length_str(s->string));
@@ -1264,7 +1258,7 @@ static val string_in_get_char(val stream)
{
struct string_in *s = coerce(struct string_in *, stream->co.handle);
- if (lt(s->pos, length_str(s->string))) {
+ if (length_str_gt(s->string, s->pos)) {
set(mkloc(s->pos, stream), plus(s->pos, one));
return chr_str(s->string, s->pos);
}