mirror of
https://github.com/moparisthebest/pacman
synced 2025-03-01 09:51:50 -05:00
libalpm md5: use larger and dynamic buffer
This gave at least a 10% improvement on a few tested platforms due to the reduced number of read calls from files when computing the md5sum. It really is just a precursor to another patch to come which is to use MD5 functions that do the job a lot better than anything we can do. Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
parent
5a25f54757
commit
24d8a15308
@ -36,6 +36,8 @@
|
||||
* int md5_file( char *path, unsigned char *output )
|
||||
* to
|
||||
* int md5_file( const char *path, unsigned char *output )
|
||||
* * use a dynamically-allocated buffer in md5_file, and increase the size
|
||||
* for performance reasons
|
||||
* * various static/inline changes
|
||||
*
|
||||
* NOTE: XySSL has been renamed to PolarSSL, which is available at
|
||||
@ -44,6 +46,7 @@
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "md5.h"
|
||||
|
||||
@ -309,11 +312,16 @@ int md5_file( const char *path, unsigned char output[16] )
|
||||
FILE *f;
|
||||
size_t n;
|
||||
md5_context ctx;
|
||||
unsigned char buf[1024];
|
||||
unsigned char *buf;
|
||||
|
||||
if( ( f = fopen( path, "rb" ) ) == NULL )
|
||||
if( ( buf = calloc(8192, sizeof(unsigned char)) ) == NULL )
|
||||
return( 1 );
|
||||
|
||||
if( ( f = fopen( path, "rb" ) ) == NULL ) {
|
||||
free( buf );
|
||||
return( 1 );
|
||||
}
|
||||
|
||||
md5_starts( &ctx );
|
||||
|
||||
while( ( n = fread( buf, 1, sizeof( buf ), f ) ) > 0 )
|
||||
@ -322,6 +330,7 @@ int md5_file( const char *path, unsigned char output[16] )
|
||||
md5_finish( &ctx, output );
|
||||
|
||||
memset( &ctx, 0, sizeof( md5_context ) );
|
||||
free( buf );
|
||||
|
||||
if( ferror( f ) != 0 )
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user