[vlc-commits] [Git][videolan/vlc][master] url: Optimize vlc_url_decode
Jean-Baptiste Kempf (@jbk)
gitlab at videolan.org
Sat Feb 19 12:06:33 UTC 2022
Jean-Baptiste Kempf pushed to branch master at VideoLAN / VLC
Commits:
88e3a4f0 by Hugo Beauzée-Luyssen at 2022-02-19T11:31:11+00:00
url: Optimize vlc_url_decode
- - - - -
1 changed file:
- src/text/url.c
Changes:
=====================================
src/text/url.c
=====================================
@@ -51,6 +51,20 @@ char *vlc_uri_decode_duplicate (const char *str)
return buf;
}
+static char hex_to_char( char c )
+{
+ unsigned char v = (unsigned char)c - '0';
+ if ( v < 10 )
+ return v;
+ v = (unsigned)c - 'a';
+ if ( v <= 5 )
+ return v + 10;
+ v = (unsigned)c - 'A';
+ if ( v <= 5 )
+ return v + 10;
+ return -1;
+}
+
char *vlc_uri_decode (char *str)
{
char *in = str, *out = str;
@@ -62,15 +76,15 @@ char *vlc_uri_decode (char *str)
{
if (c == '%')
{
- char hex[3];
+ char a, b;
- if (!(hex[0] = *(in++)) || !(hex[1] = *(in++)))
+ if ((a = hex_to_char(*(in++))) < 0 ||
+ (b = hex_to_char(*(in++))) < 0)
{
errno = EINVAL;
return NULL;
}
- hex[2] = '\0';
- *(out++) = strtoul (hex, NULL, 0x10);
+ *(out++) = a << 4 | b;
}
else
*(out++) = c;
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/88e3a4f0017196af2139576daf76ad4564864eb6
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/88e3a4f0017196af2139576daf76ad4564864eb6
You're receiving this email because of your account on code.videolan.org.
VideoLAN code repository instance
More information about the vlc-commits
mailing list