[gnumeric] Compute the number of buckets for a dependency container only once.



commit 8fb8e3052cc455fa707b1ce580f1338746bdca37
Author: Morten Welinder <terra gnome org>
Date:   Tue Apr 21 19:59:47 2009 -0400

    Compute the number of buckets for a dependency container only once.
    
    * src/dependent.c (gnm_dep_container_new): Calculate the number of
    buckets here once and for all and store in container.
    (BUCKET_LAST): Remove.  All users changed to use above.
---
 ChangeLog       |    4 ++++
 src/dependent.c |   12 ++++++------
 src/dependent.h |    3 ++-
 3 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 96e96d7..62d17f7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2009-04-21  Morten Welinder  <terra gnome org>
 
+	* src/dependent.c (gnm_dep_container_new): Calculate the number of
+	buckets here once and for all and store in container.
+	(BUCKET_LAST): Remove.  All users changed to use above.
+
 	* src/sheet.c (sheet_destroy_contents): Use colrow_resize.
 	(gnm_sheet_resize): Initial implementation.
 
diff --git a/src/dependent.c b/src/dependent.c
index 2be0101..758a8b4 100644
--- a/src/dependent.c
+++ b/src/dependent.c
@@ -90,7 +90,6 @@ static GOMemChunk *cset_pool;
 
 #define BUCKET_SIZE	128
 #define BUCKET_OF_ROW(row) ((row) / BUCKET_SIZE)
-#define BUCKET_LAST (BUCKET_OF_ROW (gnm_sheet_get_last_row (sheet)))
 #define BUCKET_START_ROW(b) ((b) * BUCKET_SIZE)
 #define BUCKET_END_ROW(b) ((b) * BUCKET_SIZE + (BUCKET_SIZE - 1))
 
@@ -1749,7 +1748,7 @@ sheet_region_queue_recalc (Sheet const *sheet, GnmRange const *r)
 			dependent_flag_recalc (dep););
 
 		/* look for things that depend on the sheet */
-		for (i = BUCKET_LAST; i >= 0 ; i--) {
+		for (i = sheet->deps->buckets - 1; i >= 0 ; i--) {
 			GHashTable *hash = sheet->deps->range_hash[i];
 			if (hash != NULL)
 				g_hash_table_foreach (hash,
@@ -2353,7 +2352,7 @@ do_deps_destroy (Sheet *sheet)
 		sheet->revive = NULL;
 	}
 
-	for (i = BUCKET_LAST; i >= 0 ; i--) {
+	for (i = deps->buckets - 1; i >= 0 ; i--) {
 		GHashTable *hash = deps->range_hash[i];
 		if (hash != NULL)
 			dep_hash_destroy (hash, &dyn_deps, sheet);
@@ -2416,7 +2415,7 @@ do_deps_invalidate (Sheet *sheet)
 
 	deps = sheet->deps;
 
-	for (i = BUCKET_LAST; i >= 0 ; i--) {
+	for (i = deps->buckets - 1; i >= 0 ; i--) {
 		GHashTable *hash = deps->range_hash[i];
 		if (hash != NULL)
 			dep_hash_destroy (hash, &dyn_deps, sheet);
@@ -2668,7 +2667,8 @@ gnm_dep_container_new (Sheet *sheet)
 
 	deps->head = deps->tail = NULL;
 
-	deps->range_hash  = g_new0 (GHashTable *, BUCKET_LAST + 1);
+	deps->buckets = 1 + BUCKET_OF_ROW (gnm_sheet_get_last_row (sheet));
+	deps->range_hash  = g_new0 (GHashTable *, deps->buckets);
 	deps->range_pool  = go_mem_chunk_new ("range pool",
 					       sizeof (DependencyRange),
 					       16 * 1024 - 100);
@@ -2843,7 +2843,7 @@ gnm_dep_container_dump (GnmDepContainer const *deps,
 
 	gnm_dep_container_sanity_check (deps);
 
-	for (i = BUCKET_LAST; i >= 0 ; i--) {
+	for (i = deps->buckets - 1; i >= 0 ; i--) {
 		GHashTable *hash = deps->range_hash[i];
 		if (hash != NULL && g_hash_table_size (hash) > 0) {
 			g_printerr ("  Bucket %d (rows %d-%d): Range hash size %d: range over which cells in list depend\n",
diff --git a/src/dependent.h b/src/dependent.h
index bf2191c..80f90ea 100644
--- a/src/dependent.h
+++ b/src/dependent.h
@@ -62,8 +62,9 @@ struct _GnmDepContainer {
 	GnmDependent *head, *tail;
 
 	/* Large ranges hashed on 'range' to accelerate duplicate culling. This
-	 * is tranversed by g_hash_table_foreach mostly.
+	 * is traversed by g_hash_table_foreach mostly.
 	 */
+	int buckets;
 	GHashTable **range_hash;
 	GOMemChunk *range_pool;
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]