about summary refs log tree commit diff
path: root/src/libutil/hash.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/libutil/hash.cc')
-rw-r--r--src/libutil/hash.cc39
1 files changed, 24 insertions, 15 deletions
diff --git a/src/libutil/hash.cc b/src/libutil/hash.cc
index 262dbef20df2..3d20d2d50d50 100644
--- a/src/libutil/hash.cc
+++ b/src/libutil/hash.cc
@@ -282,30 +282,39 @@ Hash hashFile(HashType ht, const Path & path)
 }
 
 
-struct HashSink : Sink
+HashSink::HashSink(HashType ht) : ht(ht)
 {
-    HashType ht;
-    Ctx ctx;
-    virtual void operator ()
-        (const unsigned char * data, unsigned int len)
-    {
-        update(ht, ctx, data, len);
-    }
-};
+    ctx = new Ctx;
+    start(ht, *ctx);
+}
+    
+HashSink::~HashSink()
+{
+    delete ctx;
+}
 
+void HashSink::operator ()
+    (const unsigned char * data, unsigned int len)
+{
+    update(ht, *ctx, data, len);
+}
 
-Hash hashPath(HashType ht, const Path & path, PathFilter & filter)
+Hash HashSink::finish()
 {
-    HashSink sink;
-    sink.ht = ht;
     Hash hash(ht);
-    start(ht, sink.ctx);
-    dumpPath(path, sink, filter);
-    finish(ht, sink.ctx, hash.hash);
+    nix::finish(ht, *ctx, hash.hash);
     return hash;
 }
 
 
+Hash hashPath(HashType ht, const Path & path, PathFilter & filter)
+{
+    HashSink sink(ht);
+    dumpPath(path, sink, filter);
+    return sink.finish();
+}
+
+
 Hash compressHash(const Hash & hash, unsigned int newSize)
 {
     Hash h;