pre-sort exception list passed to driver->load_box()

... and use that to optimize the maildir driver somewhat.
This commit is contained in:
Oswald Buddenhagen 2016-11-04 21:09:02 +01:00
parent 7b567164ff
commit ae95490d52
5 changed files with 21 additions and 8 deletions

View File

@ -167,6 +167,7 @@ int map_name( const char *arg, char **result, int reserve, const char *in, const
DEFINE_ARRAY_TYPE(int)
void sort_int_array( int_array_t array );
int find_int_array( const int_array_t array, int value );
void arc4_init( void );
uchar arc4_getbyte( void );

View File

@ -2305,7 +2305,6 @@ imap_load_box( store_t *gctx, int minuid, int maxuid, int newuid, int_array_t ex
} else {
struct imap_cmd_refcounted_state *sts = imap_refcounted_new_state( cb, aux );
sort_int_array( excs );
for (i = 0; i < excs.size; ) {
for (bl = 0; i < excs.size && bl < 960; i++) {
if (bl)

View File

@ -831,7 +831,7 @@ maildir_scan( maildir_store_t *ctx, msg_t_array_alloc_t *msglist )
DBC *dbc;
#endif /* USE_DB */
msg_t *entry;
int i, j, uid, bl, fnl, ret;
int i, uid, bl, fnl, ret;
time_t now, stamps[2];
struct stat st;
char buf[_POSIX_PATH_MAX], nbuf[_POSIX_PATH_MAX];
@ -922,13 +922,8 @@ maildir_scan( maildir_store_t *ctx, msg_t_array_alloc_t *msglist )
uid = INT_MAX;
}
if (uid <= ctx->maxuid) {
if (uid < ctx->minuid) {
for (j = 0; j < ctx->excs.size; j++)
if (ctx->excs.data[j] == uid)
goto oke;
if (uid < ctx->minuid && !find_int_array( ctx->excs, uid ))
continue;
oke: ;
}
entry = msg_t_array_append( msglist );
entry->base = nfstrdup( e->d_name );
entry->uid = uid;

View File

@ -1276,6 +1276,7 @@ box_opened2( sync_vars_t *svars, int t )
minwuid = INT_MAX;
}
sync_ref( svars );
sort_int_array( mexcs.array );
load_box( svars, M, minwuid, mexcs.array );
if (!check_cancel( svars ))
load_box( svars, S, (ctx[S]->opts & OPEN_OLD) ? 1 : INT_MAX, (int_array_t){ 0, 0 } );

View File

@ -545,6 +545,23 @@ sort_int_array( int_array_t array )
qsort( array.data, array.size, sizeof(int), compare_ints );
}
int
find_int_array( int_array_t array, int value )
{
int bot = 0, top = array.size - 1;
while (bot <= top) {
int i = (bot + top) / 2;
int elt = array.data[i];
if (elt == value)
return 1;
if (elt < value)
bot = i + 1;
else
top = i - 1;
}
return 0;
}
static struct {
uchar i, j, s[256];