update total_size as early as possible
authorHelmut Grohne <helmut@subdivi.de>
Sun, 24 Mar 2013 16:21:53 +0000 (17:21 +0100)
committerHelmut Grohne <helmut@subdivi.de>
Sun, 24 Mar 2013 16:21:53 +0000 (17:21 +0100)
This improves the success rate of ssdeep_try_reduce_blockhash and
thereby gives a significant speedup.

fuzzy.c

diff --git a/fuzzy.c b/fuzzy.c
index 83cf3ce..a6e238c 100644 (file)
--- a/fuzzy.c
+++ b/fuzzy.c
@@ -159,7 +159,7 @@ static void ssdeep_try_reduce_blockhash(struct ssdeep_context *self) {
 static const char *b64 =
        "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
 
-static int ssdeep_engine_step(struct ssdeep_context *self, unsigned char c) {
+static void ssdeep_engine_step(struct ssdeep_context *self, unsigned char c) {
        size_t h;
        unsigned int i;
        /* At each character we update the rolling hash and the normal hashes.
@@ -203,15 +203,13 @@ static int ssdeep_engine_step(struct ssdeep_context *self, unsigned char c) {
                } else
                        ssdeep_try_reduce_blockhash(self);
        }
-       ++self->total_size;
-       return 0;
 }
 
 static int ssdeep_engine(struct ssdeep_context *self,
                const unsigned char *buffer, size_t buffer_size) {
+       self->total_size += buffer_size;
        for( ;buffer_size > 0; ++buffer, --buffer_size)
-               if(ssdeep_engine_step(self, *buffer) < 0)
-                       return -1;
+               ssdeep_engine_step(self, *buffer);
        return 0;
 }