[notmuch] [PATCH] notmuch-restore.c: only update tags for messages that differ from dump file.

Carl Worth cworth at cworth.org
Tue Dec 8 01:50:51 PST 2009


On Mon,  7 Dec 2009 23:14:48 -0400, david at tethera.net wrote:
> The main feature of this patch is that it compares the list of current
> tags on a message with those read by restore. Only if the two lists
> differ is the tag list in the message replaced.  In my experiments this leads to
> a large performance improvement.

Hi David,

This is going to be a nice performance fix. Thanks for working on it!

I noticed that the code is in a style that is inconsistent with the
prevailing style of the notmuch code. So here are a few points on some
obvious style differences (there are other similar issues that I don't
mention specifically).

And I don't mean anything personal here. We all have different styles
that we prefer and find most legible. I do think it's important that the
code be in a consistent style throughout though, (and I will make a
CODING_STYLE document for the source tree soon).

> +/* for qsort */
> +static int scmp( const void *sp1, const void *sp2 )

The function name really needs to be on its own line (flush with the
left-most column). I don't like the interior whitespace for the argument
list. I really don't like a name as dramatically abbreviated as
"scmp". I'd prefer something like strcmp_for_qsort or whatever this is
actually doing.

> +    return( strcmp(*(const char **)sp1, *(const char **)sp2) );

More whitespace here. There should be a space *before* the '(' not
after, (and then not before the ')'). Finally, with void* arguments, I
like to take care of the ugly casts up front, (assigning to approriately
named local variables) rather than cluttering a function call with casts
like this.

> +    char **tag_array=NULL;
> +    int tag_array_size=DEFAULT_TAG_ARRAY_SIZE;

Need whitespace on either side of '=' here, (and similar throughout).

> +	while(*next){

More missing space. I would prefer:

	while (*next) {

> +	  while(*next && isspace(*next))
> +	    next++;

Current indentation in notmuch is 4 columns per indent level, not 2.

> +	      tag_array=realloc(tag_array,tag_array_size*sizeof(char *));

I can't read that at all with so much missing space. I'd prefer to see:

	      tag_array = realloc (tag_array, tag_array_size * sizeof (char *));

> +	while (notmuch_tags_has_more (tag_list) && i<tag_count &&
> +	       (strcmp(notmuch_tags_get (tag_list),tag_array[i])==0)){
> +	  notmuch_tags_advance (tag_list);
> +	  i++;
> +	}

While I don't mind an opening brace on the same line as an "if" or
"while" condition, I do mind it when the condition spans more than one
line. In that case, the opening brace really needs to be on a line of
its own. And again, lots of missing space in the above.

> +	  for (i=0; i<tag_count; i++) {

More missing space. Should be:

	  for (i = 0; i < tag_count; i++) {

-Carl

PS. Why is the commit mentioning using calloc, not talloc? Is there a
reason talloc is inappropriate here? Or were you just not familiar with
how to use it? I'd be glad to answer any questions you have about use of
talloc in notmuch.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://notmuchmail.org/pipermail/notmuch/attachments/20091208/a40323c3/attachment.pgp>


More information about the notmuch mailing list