aboutsummaryrefslogtreecommitdiffstats
path: root/src/mdx_hash.cpp
diff options
context:
space:
mode:
authorlloyd <[email protected]>2006-08-05 13:20:31 +0000
committerlloyd <[email protected]>2006-08-05 13:20:31 +0000
commitb1557adf97fdcd4075da339e05bb5cab6e80eb12 (patch)
tree91c3e5f3173a74330df39dcbb6d84729e1bd6a06 /src/mdx_hash.cpp
parentb7c25924c014c14ed0d08084bf41b08778d6be54 (diff)
Alter how buffering is performed in MDx_HashFunction:add_data; rather
than always placing the first block into the temp buffer, we only copy the data into there if we have to (ie, if we have an incomplete block). So calling add_data with a block that is a multiple of the hash function's internal block size is entirely zero-copy.
Diffstat (limited to 'src/mdx_hash.cpp')
-rw-r--r--src/mdx_hash.cpp30
1 files changed, 19 insertions, 11 deletions
diff --git a/src/mdx_hash.cpp b/src/mdx_hash.cpp
index 93fbff1e8..736ead70e 100644
--- a/src/mdx_hash.cpp
+++ b/src/mdx_hash.cpp
@@ -37,21 +37,29 @@ void MDx_HashFunction::clear() throw()
void MDx_HashFunction::add_data(const byte input[], u32bit length)
{
count += length;
- buffer.copy(position, input, length);
- if(position + length >= HASH_BLOCK_SIZE)
+
+ if(position)
{
- hash(buffer.begin());
- input += (HASH_BLOCK_SIZE - position);
- length -= (HASH_BLOCK_SIZE - position);
- while(length >= HASH_BLOCK_SIZE)
+ buffer.copy(position, input, length);
+
+ if(position + length >= HASH_BLOCK_SIZE)
{
- hash(input);
- input += HASH_BLOCK_SIZE;
- length -= HASH_BLOCK_SIZE;
+ hash(buffer.begin());
+ input += (HASH_BLOCK_SIZE - position);
+ length -= (HASH_BLOCK_SIZE - position);
+ position = 0;
}
- buffer.copy(input, length);
- position = 0;
}
+
+ while(length >= HASH_BLOCK_SIZE)
+ {
+ hash(input);
+ input += HASH_BLOCK_SIZE;
+ length -= HASH_BLOCK_SIZE;
+ }
+
+ buffer.copy(position, input, length);
+
position += length;
}