From 7a07c80767950787601924b2b8091c8a0cb3371a Mon Sep 17 00:00:00 2001 From: Milan Crha Date: Wed, 20 Oct 2010 13:31:46 +0200 Subject: Bug #630504 - Precache collate keys before sorting in EReflowModel --- widgets/text/e-reflow-model.c | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) (limited to 'widgets/text/e-reflow-model.c') diff --git a/widgets/text/e-reflow-model.c b/widgets/text/e-reflow-model.c index 6f8223ae9a..d7a5ffec48 100644 --- a/widgets/text/e-reflow-model.c +++ b/widgets/text/e-reflow-model.c @@ -108,25 +108,51 @@ e_reflow_model_incarnate (EReflowModel *e_reflow_model, gint n, GnomeCanvasGroup return E_REFLOW_MODEL_GET_CLASS (e_reflow_model)->incarnate (e_reflow_model, n, parent); } +/** + * e_reflow_model_create_cmp_cache: + * @e_reflow_model: The e-reflow-model to operate on + * + * Creates a compare cache for quicker sorting. The sorting function + * may not depend on the cache, but it should benefit from it if available. + * + * Returns: Newly created GHashTable with cached compare values. This will be + * automatically freed with g_hash_table_destroy() when no longer needed. + **/ +GHashTable * +e_reflow_model_create_cmp_cache (EReflowModel *e_reflow_model) +{ + g_return_val_if_fail (e_reflow_model != NULL, NULL); + g_return_val_if_fail (E_IS_REFLOW_MODEL (e_reflow_model), NULL); + + if (!E_REFLOW_MODEL_GET_CLASS (e_reflow_model)->create_cmp_cache) + return NULL; + + return E_REFLOW_MODEL_GET_CLASS (e_reflow_model)->create_cmp_cache (e_reflow_model); +} + /** * e_reflow_model_compare: * @e_reflow_model: The e-reflow-model to operate on * @n1: The first item to compare * @n2: The second item to compare + * @cmp_cache: #GHashTable of cached compare values, created by + * e_reflow_model_create_cmp_cache(). This can be NULL, when + * caching is not available, even when @e_reflow_model defines + * the create_cmp_cache function. * * Compares item n1 and item n2 to see which should come first. * * Returns: strcmp like semantics for the comparison value. */ gint -e_reflow_model_compare (EReflowModel *e_reflow_model, gint n1, gint n2) +e_reflow_model_compare (EReflowModel *e_reflow_model, gint n1, gint n2, GHashTable *cmp_cache) { #if 0 g_return_val_if_fail (e_reflow_model != NULL, 0); g_return_val_if_fail (E_IS_REFLOW_MODEL (e_reflow_model), 0); #endif - return E_REFLOW_MODEL_GET_CLASS (e_reflow_model)->compare (e_reflow_model, n1, n2); + return E_REFLOW_MODEL_GET_CLASS (e_reflow_model)->compare (e_reflow_model, n1, n2, cmp_cache); } /** -- cgit v1.2.3