about summary refs log tree commit diff
path: root/src/libutil/hash.cc
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2006-03-09T17·07+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2006-03-09T17·07+0000
commit18c321308d2e71db7355a83200c0ef4d00900d0b (patch)
tree4b4d2acca1d39ec36ba474e2d8a3672e4a957c32 /src/libutil/hash.cc
parentb90c00e63fb476d8587ca29f15cbe8008760a584 (diff)
* Ugh, printHash() was very inefficient because it used
  ostringstreams.  Around 11% of execution time was spent here (now
  it's 0.5%).

Diffstat (limited to 'src/libutil/hash.cc')
-rw-r--r--src/libutil/hash.cc12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/libutil/hash.cc b/src/libutil/hash.cc
index 1604f1363ea3..b69c14832877 100644
--- a/src/libutil/hash.cc
+++ b/src/libutil/hash.cc
@@ -66,15 +66,17 @@ bool Hash::operator < (const Hash & h) const
 }
 
 
+const string base16Chars = "0123456789abcdef";
+
+
 string printHash(const Hash & hash)
 {
-    ostringstream str;
+    char buf[hash.hashSize * 2];
     for (unsigned int i = 0; i < hash.hashSize; i++) {
-        str.fill('0');
-        str.width(2);
-        str << hex << (int) hash.hash[i];
+        buf[i * 2] = base16Chars[hash.hash[i] >> 4];
+        buf[i * 2 + 1] = base16Chars[hash.hash[i] & 0x0f];
     }
-    return str.str();
+    return string(buf, hash.hashSize * 2);
 }