aboutsummaryrefslogtreecommitdiff
path: root/src/backend/libpq/md5.c
diff options
context:
space:
mode:
authorNeil Conway <neilc@samurai.com>2005-02-23 22:46:17 +0000
committerNeil Conway <neilc@samurai.com>2005-02-23 22:46:17 +0000
commit3350b3740e5960da294384ba9c1806f13b72ba6f (patch)
treeb1d627e6ae2d76bf6a19867b016517a9a2318bbb /src/backend/libpq/md5.c
parentb9a87e5219ad609657c59601b636475b23bd571e (diff)
downloadpostgresql-3350b3740e5960da294384ba9c1806f13b72ba6f.tar.gz
postgresql-3350b3740e5960da294384ba9c1806f13b72ba6f.zip
This patch optimizes the md5_text() function (which is used to
implement the md5() SQL-level function). The old code did the following: 1. de-toast the datum 2. convert it to a cstring via textout() 3. get the length of the cstring via strlen() Since we are treating the datum context as a blob of binary data, the latter two steps are unnecessary. Once the data has been detoasted, we can just use it as-is, and derive its length from the varlena metadata. This patch improves some run-of-the-mill md5() computations by just under 10% in my limited tests, and passes the regression tests. I also noticed that md5_text() wasn't checking the return value of md5_hash(); encountering OOM at precisely the right moment could result in returning a random md5 hash. This patch corrects that. A better fix would be to make md5_hash() only return on success (and/or allocate via palloc()), but since it's used in the frontend as well I don't see an easy way to do that.
Diffstat (limited to 'src/backend/libpq/md5.c')
-rw-r--r--src/backend/libpq/md5.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/backend/libpq/md5.c b/src/backend/libpq/md5.c
index 16649abe24f..3c7fcd69127 100644
--- a/src/backend/libpq/md5.c
+++ b/src/backend/libpq/md5.c
@@ -14,7 +14,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/libpq/md5.c,v 1.27 2004/12/31 21:59:50 pgsql Exp $
+ * $PostgreSQL: pgsql/src/backend/libpq/md5.c,v 1.28 2005/02/23 22:46:17 neilc Exp $
*/
@@ -289,8 +289,8 @@ bytesToHex(uint8 b[16], char *s)
* characters. you thus need to provide an array
* of 33 characters, including the trailing '\0'.
*
- * RETURNS 0 on failure (out of memory for internal buffers) or
- * non-zero on success.
+ * RETURNS false on failure (out of memory for internal buffers) or
+ * true on success.
*
* STANDARDS MD5 is described in RFC 1321.
*