summaryrefslogtreecommitdiff
path: root/src/c
diff options
context:
space:
mode:
authorGravatar Adam Chlipala <adam@chlipala.net>2011-01-11 14:03:54 -0500
committerGravatar Adam Chlipala <adam@chlipala.net>2011-01-11 14:03:54 -0500
commitb6c2ebc6168eea0f7bdd203dd85cb87eeab5f293 (patch)
tree07c262b05b9acf20fbb9aaaef74b8a2b300ad330 /src/c
parentfb8539bea137355f9a7891bb8e4a775512971d5e (diff)
String processing optimizations
Diffstat (limited to 'src/c')
-rw-r--r--src/c/urweb.c41
1 files changed, 33 insertions, 8 deletions
diff --git a/src/c/urweb.c b/src/c/urweb.c
index 17e4bed2..0b4054e9 100644
--- a/src/c/urweb.c
+++ b/src/c/urweb.c
@@ -2133,23 +2133,48 @@ uw_unit uw_Basis_htmlifyTime_w(uw_context ctx, uw_Basis_time t) {
}
uw_Basis_char uw_Basis_strsub(uw_context ctx, uw_Basis_string s, uw_Basis_int n) {
- if (n >= 0 && n < strlen(s))
- return s[n];
- else
- uw_error(ctx, FATAL, "Out-of-bounds strsub");
+ while (n >= 0) {
+ if (*s == 0)
+ uw_error(ctx, FATAL, "Out-of-bounds strsub");
+
+ if (n == 0)
+ return *s;
+
+ --n;
+ ++s;
+ }
+
+ uw_error(ctx, FATAL, "Negative strsub bound");
}
uw_Basis_string uw_Basis_strsuffix(uw_context ctx, uw_Basis_string s, uw_Basis_int n) {
- if (n >= 0 && n < strlen(s))
- return &s[n];
- else
- uw_error(ctx, FATAL, "Out-of-bounds strsuffix");
+ while (n >= 0) {
+ if (*s == 0 || n == 0)
+ return s;
+
+ --n;
+ ++s;
+ }
+
+ uw_error(ctx, FATAL, "Negative strsuffix bound");
}
uw_Basis_int uw_Basis_strlen(uw_context ctx, uw_Basis_string s) {
return strlen(s);
}
+uw_Basis_bool uw_Basis_strlenGe(uw_context ctx, uw_Basis_string s, uw_Basis_int n) {
+ while (n > 0) {
+ if (*s == 0)
+ return uw_Basis_False;
+
+ --n;
+ ++s;
+ }
+
+ return uw_Basis_True;
+}
+
uw_Basis_string uw_Basis_strchr(uw_context ctx, uw_Basis_string s, uw_Basis_char ch) {
return strchr(s, ch);
}