Commit 5f89b34b authored by Kim Vandry's avatar Kim Vandry

refactor: Move the enum message_type field directly into struct msgpath

'struct msgpath' is easier to work with for the upcoming IMAP feature
if the union discriminator is located inside the structure itself.
parent 453fb270
......@@ -844,7 +844,7 @@ static void find_threading(struct database *db)/*{{{*/
return;
}
/*}}}*/
static int lookup_msgpath(struct msgpath *sorted_paths, int n_msgs, char *key)/*{{{*/
static int lookup_msgpath(struct msgpath *sorted_paths, int n_msgs, char *key, enum message_type type)/*{{{*/
{
/* Implement bisection search */
int l, h, m, r;
......@@ -853,7 +853,13 @@ static int lookup_msgpath(struct msgpath *sorted_paths, int n_msgs, char *key)/*
while (h > l) {
m = (h + l) >> 1;
/* Should only get called on 'file' type messages - TBC */
r = strcmp(sorted_paths[m].src.mpf.path, key);
if (sorted_paths[m].type < type) {
r = -1;
} else if (sorted_paths[m].type > type) {
r = 1;
} else {
r = strcmp(sorted_paths[m].src.mpf.path, key);
}
if (r == 0) break;
if (l == m) return -1;
if (r > 0) h = m;
......@@ -929,7 +935,7 @@ int update_database(struct database *db, struct msgpath *sorted_paths, int n_msg
for (i=0; i<db->n_msgs; i++) {
switch (db->type[i]) {
case MTY_FILE:
matched_index = lookup_msgpath(sorted_paths, n_msgs, db->msgs[i].src.mpf.path);
matched_index = lookup_msgpath(sorted_paths, n_msgs, db->msgs[i].src.mpf.path, MTY_FILE);
if (matched_index >= 0) {
if (do_fast_index) {
/* Assume the presence of a matching path is good enough without
......
......@@ -35,7 +35,6 @@ struct msgpath_array *new_msgpath_array(void)/*{{{*/
struct msgpath_array *result;
result = new(struct msgpath_array);
result->paths = NULL;
result->type = NULL;
result->n = 0;
result->max = 0;
return result;
......@@ -46,7 +45,7 @@ void free_msgpath_array(struct msgpath_array *x)/*{{{*/
int i;
if (x->paths) {
for (i=0; i<x->n; i++) {
switch (x->type[i]) {
switch (x->paths[i].type) {
case MTY_FILE:
free(x->paths[i].src.mpf.path);
break;
......@@ -56,7 +55,6 @@ void free_msgpath_array(struct msgpath_array *x)/*{{{*/
break;
}
}
free(x->type);
free(x->paths);
}
free(x);
......@@ -67,9 +65,8 @@ static void add_file_to_list(char *x, struct msgpath_array *arr) {/*{{{*/
if (arr->n == arr->max) {
arr->max += 1024;
arr->paths = grow_array(struct msgpath, arr->max, arr->paths);
arr->type = grow_array(enum message_type, arr->max, arr->type);
}
arr->type[arr->n] = MTY_FILE;
arr->paths[arr->n].type = MTY_FILE;
arr->paths[arr->n].src.mpf.path = y;
++arr->n;
return;
......@@ -356,7 +353,8 @@ static int message_compare(const void *a, const void *b)/*{{{*/
/* FIXME : Is this a sensible way to do this with mbox messages in the picture? */
struct msgpath *aa = (struct msgpath *) a;
struct msgpath *bb = (struct msgpath *) b;
/* This should only get called on 'file' type messages - TBC! */
if (aa->type < bb->type) return -1;
if (aa->type > bb->type) return 1;
return strcmp(aa->src.mpf.path, bb->src.mpf.path);
}
/*}}}*/
......
......@@ -286,7 +286,7 @@ static int check_message_list_for_duplicates(struct msgpath_array *msgs)/*{{{*/
n = msgs->n;
sorted_paths = new_array(char *, n);
for (i=0, nn=0; i<n; i++) {
switch (msgs->type[i]) {
switch (msgs->paths[i].type) {
case MTY_MBOX:
break;
case MTY_DEAD:
......
......@@ -33,9 +33,16 @@
#include "memmac.h"
enum message_type {/*{{{*/
MTY_DEAD, /* msg no longer exists, i.e. don't report in searches,
prune it on a '-p' run. */
MTY_FILE, /* msg <-> file in 1-1 correspondence e.g. maildir, MH */
MTY_MBOX /* multiple msgs per file : MBOX format file */
};
/*}}}*/
struct msgpath {/*{{{*/
/* The 'selector' for this union is the corresponding entry of type 'enum
* message_type' */
enum message_type type; /* selector for union 'src' */
union {
struct {
char *path;
......@@ -61,15 +68,7 @@ struct msgpath {/*{{{*/
};
/*}}}*/
enum message_type {/*{{{*/
MTY_DEAD, /* msg no longer exists, i.e. don't report in searches,
prune it on a '-p' run. */
MTY_FILE, /* msg <-> file in 1-1 correspondence e.g. maildir, MH */
MTY_MBOX /* multiple msgs per file : MBOX format file */
};
/*}}}*/
struct msgpath_array {/*{{{*/
enum message_type *type;
struct msgpath *paths;
int n;
int max;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment