* lib/mu-container: remove some O(n*n) behavior from threading

mu_container_append_siblings was showing up high in profiles as it has to
  walk chains of next->next->next->... pointers to find the last one. we now
  cache the last link in the chain. for listing ~ 23K messages, this saves
  about 20%.
This commit is contained in:
djcb
2012-09-17 17:45:59 +03:00
parent 7fe594fb2a
commit e483291a1d
2 changed files with 44 additions and 19 deletions

View File

@ -29,8 +29,7 @@ enum _MuContainerFlag {
MU_CONTAINER_FLAG_SPLICE = 1 << 1,
MU_CONTAINER_FLAG_DUP = 1 << 2
};
typedef guint8 MuContainerFlag;
typedef enum _MuContainerFlag MuContainerFlag;
/*
* MuContainer data structure, as seen in JWZs document:
@ -38,10 +37,21 @@ typedef guint8 MuContainerFlag;
*/
struct _MuContainer {
struct _MuContainer *parent, *child, *next;
MuContainerFlag flags;
MuMsg *msg;
guint docid;
const char* msgid;
/* note: we cache the last of the string of next->next->...
* `mu_container_append_siblings' shows up high in the
* profiles since it needs to walk to the end, and this give
* O(n*n) behavior.
* */
struct _MuContainer *last;
MuMsg *msg;
const char *msgid;
unsigned docid;
MuContainerFlag flags;
};
typedef struct _MuContainer MuContainer;
@ -177,7 +187,8 @@ typedef int (*MuContainerCmpFunc) (MuContainer *c1, MuContainer *c2,
*
* @return a sorted container
*/
MuContainer* mu_container_sort (MuContainer *c, MuMsgFieldId mfid, gboolean revert,
MuContainer* mu_container_sort (MuContainer *c, MuMsgFieldId mfid,
gboolean revert,
gpointer user_data);