You are viewing a plain text version of this content. The canonical link for it is here.
Posted to apache-bugdb@apache.org by Ronald Tschal�r <ro...@innovation.ch> on 1998/11/18 02:18:34 UTC
other/3409: [PATCH] ap_md5_binary uses sprintf, which is unnecessarily slow
>Number: 3409
>Category: other
>Synopsis: [PATCH] ap_md5_binary uses sprintf, which is unnecessarily slow
>Confidential: no
>Severity: non-critical
>Priority: medium
>Responsible: apache
>State: open
>Class: sw-bug
>Submitter-Id: apache
>Arrival-Date: Tue Nov 17 17:20:00 PST 1998
>Last-Modified:
>Originator: ronald@innovation.ch
>Organization:
apache
>Release: 1.3.*
>Environment:
all
>Description:
ap_md5_binary() (in util_md5.c) uses sprintf to convert the hash to hex form,
but this is pretty slow (mod_digest spends ove 10% of its time in this sprintf).
The simple attached patch solves this.
>How-To-Repeat:
>Fix:
Diff for apache-1.3.4-dev:
--- main/util_md5.c.orig Sun Sep 6 12:12:18 1998
+++ main/util_md5.c Tue Nov 17 15:59:32 1998
@@ -89,6 +89,7 @@
API_EXPORT(char *) ap_md5_binary(pool *p, const unsigned char *buf, int length)
{
+ static char hex[] = "0123456789abcdef";
AP_MD5_CTX my_md5;
unsigned char hash[16];
char *r, result[33];
@@ -102,8 +103,10 @@
ap_MD5Update(&my_md5, buf, length);
ap_MD5Final(hash, &my_md5);
- for (i = 0, r = result; i < 16; i++, r += 2)
- sprintf(r, "%02x", hash[i]);
+ for (i = 0, r = result; i < 16; i++) {
+ *r++ = hex[hash[i] >> 4];
+ *r++ = hex[hash[i] & 0xF];
+ }
*r = '\0';
return ap_pstrdup(p, result);
>Audit-Trail:
>Unformatted:
[In order for any reply to be added to the PR database, ]
[you need to include <ap...@Apache.Org> in the Cc line ]
[and leave the subject line UNCHANGED. This is not done]
[automatically because of the potential for mail loops. ]
[If you do not include this Cc, your reply may be ig- ]
[nored unless you are responding to an explicit request ]
[from a developer. ]
[Reply only with text; DO NOT SEND ATTACHMENTS! ]