summaryrefslogtreecommitdiffstats
path: root/sub/filter_sdh.c
diff options
context:
space:
mode:
authorDudemanguy <random342@airmail.cc>2024-01-13 12:25:12 -0600
committerDudemanguy <random342@airmail.cc>2024-01-15 16:05:17 +0000
commit9bf4b9d5d40abc1265a38bed7ea851874013c530 (patch)
tree4ed70a11661af982572e6ff35332161196f79049 /sub/filter_sdh.c
parent13ed292ab054ba09f9257d9c510cd7ce39f4b7d3 (diff)
downloadmpv-9bf4b9d5d40abc1265a38bed7ea851874013c530.tar.bz2
mpv-9bf4b9d5d40abc1265a38bed7ea851874013c530.tar.xz
filter_sdh: optimize get_char_bytes
strlen is only relevant if the length is less than [1, 4], so this can be replaced with strnlen instead which will only traverse characters upto the maxlen insted of the entire string length. It also makes MPMIN unneeded. Also fix a comment.
Diffstat (limited to 'sub/filter_sdh.c')
-rw-r--r--sub/filter_sdh.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/sub/filter_sdh.c b/sub/filter_sdh.c
index a4b1aeb097..5adc1f99ef 100644
--- a/sub/filter_sdh.c
+++ b/sub/filter_sdh.c
@@ -67,18 +67,18 @@ static inline int append(struct sd_filter *sd, struct buffer *buf, char c)
static int get_char_bytes(char *str)
{
- // In case the final character is non-ASCII.
+ // In case the first character is non-ASCII.
// Will only work with UTF-8 but you shouldn't be
// using anything else anyway.
if (str && str[0]) {
if (!(str[0] >> 7 & 1)) {
- return MPMIN(strlen(str), 1);
+ return strnlen(str, 1);
} else if (!(str[0] >> 5 & 1)) {
- return MPMIN(strlen(str), 2);
+ return strnlen(str, 2);
} else if (!(str[0] >> 4 & 1)) {
- return MPMIN(strlen(str), 3);
+ return strnlen(str, 3);
} else if (!(str[0] >> 3 & 1)) {
- return MPMIN(strlen(str), 4);
+ return strnlen(str, 4);
}
}
return 0;