diff options
author | Daniel Stenberg <daniel@haxx.se> | 2023-01-31 12:34:08 +0100 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2023-01-31 22:42:21 +0100 |
commit | fc8ad0b23c9fd922ebdb89348d467df037da1775 (patch) | |
tree | 897bbd1105a323cecdb05dcd904e98ad66a73bfb /lib/escape.c | |
parent | b1e8cd52d9f11fdb1743c1077c031eb723d184b8 (diff) | |
download | curl-fc8ad0b23c9fd922ebdb89348d467df037da1775.tar.gz |
escape: use table lookup when adding %-codes to output
On my dev host, this code runs 7.8 times faster.
Closes #10377
Diffstat (limited to 'lib/escape.c')
-rw-r--r-- | lib/escape.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/lib/escape.c b/lib/escape.c index 93db06cbd..56aa2b398 100644 --- a/lib/escape.c +++ b/lib/escape.c @@ -97,7 +97,7 @@ char *curl_easy_escape(struct Curl_easy *data, const char *string, return strdup(""); while(length--) { - unsigned char in = *string; /* we need to treat the characters unsigned */ + unsigned char in = *string++; /* treat the characters unsigned */ if(Curl_isunreserved(in)) { /* append this */ @@ -106,10 +106,13 @@ char *curl_easy_escape(struct Curl_easy *data, const char *string, } else { /* encode it */ - if(Curl_dyn_addf(&d, "%%%02X", in)) + const char hex[] = "0123456789ABCDEF"; + char out[3]={'%'}; + out[1] = hex[in>>4]; + out[2] = hex[in & 0xf]; + if(Curl_dyn_addn(&d, out, 3)) return NULL; } - string++; } return Curl_dyn_ptr(&d); |