summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2021-07-22 07:56:26 -0700
committerKaz Kylheku <kaz@kylheku.com>2021-07-22 07:56:26 -0700
commit8e4a0206b97df82a9c7419b158d9858da95168ab (patch)
tree7d00a72dc084ef84d12e70646c45228bc22afe7b
parent3cbe3674849b7324e410d2e7c6590f08f28ec2e8 (diff)
downloadtxr-8e4a0206b97df82a9c7419b158d9858da95168ab.tar.gz
txr-8e4a0206b97df82a9c7419b158d9858da95168ab.tar.bz2
txr-8e4a0206b97df82a9c7419b158d9858da95168ab.zip
pure-rel-path-p: rewrite without regex.
* stream.c (volume_name_p): New static function. (plp_regex): Static variable removed. (pure_rel_path_p): Rewrite using lower-level string manipulation, and using volume_name_p instead of a cached regex. (stream_init): Remove reference to plp_regex.
-rw-r--r--stream.c36
1 files changed, 21 insertions, 15 deletions
diff --git a/stream.c b/stream.c
index 68ace85a..00e0228d 100644
--- a/stream.c
+++ b/stream.c
@@ -4913,6 +4913,19 @@ static val volume_prefix_p(const wchar_t *str)
return nil;
}
+static val volume_name_p(const wchar_t *str)
+{
+ for (; *str; str++) {
+ if (iswalnum(*str))
+ continue;
+ if (*str == ':')
+ return t;
+ break;
+ }
+
+ return nil;
+}
+
val portable_abs_path_p(val path)
{
val self = lit("portable-abs-path-p");
@@ -4942,30 +4955,24 @@ val abs_path_p(val path)
return volume_prefix_p(str);
}
-static val plp_regex;
-
val pure_rel_path_p(val path)
{
- val ch;
- val len = length_str(path);
+ val self = lit("pure-rel-path-p");
+ const wchar_t *str = c_str(path, self);
- if (len == zero)
+ if (str[0] == 0)
return t;
- if ((ch = chr_str(path, zero)) == chr('/') || ch == chr('\\'))
+ if (str[0] == '/' || str[0] == '\\')
return nil;
- if (len == one)
- return ch == chr('.') ? nil : t;
+ if (str[1] == 0)
+ return str[0] == '.' ? nil : t;
- if (ch == chr('.') &&
- ((ch = chr_str(path, one)) == chr('/') || ch == chr('\\')))
+ if (str[0] == '.' && (str[1] == '/' || str[1] == '\\'))
return nil;
- if (!plp_regex)
- plp_regex = regex_compile(lit("[A-Za-z0-9]+:"), nil);
-
- if (match_regex(path, plp_regex, zero))
+ if (volume_name_p(str))
return nil;
return t;
@@ -5378,7 +5385,6 @@ void iobuf_list_empty(void)
void stream_init(void)
{
- prot1(&plp_regex);
prot1(&top_stderr);
detect_format_string();