Merge "Support caching the suffix array." am: 02416b52d7 am: 511311dd75

am: 86a694768c

Change-Id: I27254e218da083ef4ae40f05d7546d908f717999
This commit is contained in:
Sen Jiang authored and android-build-merger committed 2017-01-19 20:55:44 +00:00
commit 7437fef364
2 files changed
+27 -15

No files matched your search

+17 -14
View File
@@ -42,14 +42,6 @@ __FBSDID("$FreeBSD: src/usr.bin/bsdiff/bsdiff/bsdiff.c,v 1.1 2005/08/06 01:59:05
#include <algorithm>
#if _FILE_OFFSET_BITS == 64
#include "divsufsort64.h"
#define saidx_t saidx64_t
#define divsufsort divsufsort64
#else
#include "divsufsort.h"
#endif
namespace bsdiff {
static off_t matchlen(const u_char* old, off_t oldsize, const u_char* new_buf,
@@ -135,7 +127,7 @@ int bsdiff(const char* old_filename, const char* new_filename,
(read(fd,new_buf,newsize)!=newsize) ||
(close(fd)==-1)) err(1,"%s",new_filename);
int ret = bsdiff(old_buf, oldsize, new_buf, newsize, patch_filename);
int ret = bsdiff(old_buf, oldsize, new_buf, newsize, patch_filename, nullptr);
free(old_buf);
free(new_buf);
@@ -143,8 +135,12 @@ int bsdiff(const char* old_filename, const char* new_filename,
return ret;
}
// Generate bsdiff patch from |old_buf| to |new_buf|, save the patch file to
// |patch_filename|. Returns 0 on success.
// |I_cache| can be used to cache the suffix array if the same |old_buf| is used
// repeatedly, pass nullptr if not needed.
int bsdiff(const u_char* old_buf, off_t oldsize, const u_char* new_buf,
off_t newsize, const char* patch_filename) {
off_t newsize, const char* patch_filename, saidx_t** I_cache) {
saidx_t *I;
off_t scan,pos=0,len;
off_t lastscan,lastpos,lastoffset;
@@ -160,10 +156,16 @@ int bsdiff(const u_char* old_buf, off_t oldsize, const u_char* new_buf,
BZFILE * pfbz2;
int bz2err;
if((I=static_cast<saidx_t*>(malloc((oldsize+1)*sizeof(saidx_t))))==NULL)
err(1,NULL);
if (I_cache && *I_cache) {
I = *I_cache;
} else {
if ((I=static_cast<saidx_t*>(malloc((oldsize+1)*sizeof(saidx_t))))==NULL)
err(1,NULL);
if(divsufsort(old_buf, I, oldsize)) err(1, "divsufsort");
if (divsufsort(old_buf, I, oldsize)) err(1, "divsufsort");
if (I_cache)
*I_cache = I;
}
if(((db=static_cast<u_char*>(malloc(newsize+1)))==NULL) ||
((eb=static_cast<u_char*>(malloc(newsize+1)))==NULL)) err(1,NULL);
@@ -342,7 +344,8 @@ int bsdiff(const u_char* old_buf, off_t oldsize, const u_char* new_buf,
/* Free the memory we used */
free(db);
free(eb);
free(I);
if (I_cache == nullptr)
free(I);
return 0;
}
+10 -1
View File
@@ -7,6 +7,14 @@
#include <sys/types.h>
#if _FILE_OFFSET_BITS == 64
#include "divsufsort64.h"
#define saidx_t saidx64_t
#define divsufsort divsufsort64
#else
#include "divsufsort.h"
#endif
namespace bsdiff {
int bsdiff(const char* old_filename,
@@ -17,7 +25,8 @@ int bsdiff(const u_char* old_buf,
off_t oldsize,
const u_char* new_buf,
off_t newsize,
const char* patch_filename);
const char* patch_filename,
saidx_t** I_cache);
} // namespace bsdiff