Index: modules/other/gail/gailtreeview.c
===================================================================
--- modules/other/gail/gailtreeview.c	(revision 21582)
+++ modules/other/gail/gailtreeview.c	(working copy)
@@ -331,7 +331,6 @@
 static gboolean         get_tree_path_from_row_index    (GtkTreeModel           *model,
                                                          gint                   row_index,
                                                          GtkTreePath            **tree_path);
-static gint             get_row_count                   (GtkTreeModel           *model);
 static gboolean         get_path_column_from_index      (GtkTreeView            *tree_view,
                                                          gint                   index,
                                                          GtkTreePath            **path,
@@ -432,6 +431,7 @@
   view->caption = NULL;
   view->summary = NULL;
   view->row_data = NULL;
+  view->row_count = 0;
   view->col_data = NULL;
   view->cell_data = NULL;
   view->focus_cell = NULL;
@@ -476,9 +476,11 @@
     (GCallback) focus_out, NULL, NULL, 0);
 
   view->tree_model = tree_model;
+  view->row_count = 0;
   if (tree_model)
     {
       g_object_add_weak_pointer (G_OBJECT (view->tree_model), (gpointer *)&view->tree_model);
+      count_rows (tree_model, NULL, NULL, &view->row_count, 0, G_MAXINT);
       connect_model_signals (tree_view, view);
 
       if (GTK_IS_TREE_STORE (tree_model))
@@ -560,12 +562,14 @@
         disconnect_model_signals (gailview);
       clear_cached_data (gailview);
       gailview->tree_model = tree_model;
+      gailview->row_count = 0;
       /*
        * if there is no model the GtkTreeView is probably being destroyed
        */
       if (tree_model)
         {
           g_object_add_weak_pointer (G_OBJECT (gailview->tree_model), (gpointer *)&gailview->tree_model);
+          count_rows (tree_model, NULL, NULL, &gailview->row_count, 0, G_MAXINT);
           connect_model_signals (tree_view, gailview);
 
           if (GTK_IS_TREE_STORE (tree_model))
@@ -770,7 +774,7 @@
   /*
    * We get the total number of rows including those which are collapsed
    */
-  n_rows = get_row_count (tree_model);
+  n_rows = GAIL_TREE_VIEW (obj)->row_count;
   /*
    * We get the total number of columns including those which are not visible
    */
@@ -2498,7 +2502,7 @@
       */
       if (!column_found)
         {
-          gint n_cols, n_rows, row;
+          gint n_cols, row;
 
           if (!stale_set)
             {
@@ -2511,9 +2515,8 @@
           g_signal_emit_by_name (atk_obj, "column_inserted", column_count, 1);
 
           /* Generate children-changed signals */
-          n_rows = get_row_count (gtk_tree_view_get_model (tree_view));
           n_cols = get_n_actual_columns (tree_view);
-          for (row = 0; row < n_rows; row++)
+          for (row = 0; row < gailview->row_count; row++)
             {
              /*
               * Pass NULL as the child object, i.e. 4th argument.
@@ -2548,7 +2551,7 @@
         */
       if (!column_found)
         {
-          gint n_rows, n_cols, row;
+          gint n_cols, row;
 
           clean_cols (gailview,
                       (GtkTreeViewColumn *)g_array_index (gailview->col_data,
@@ -2565,9 +2568,8 @@
           g_signal_emit_by_name (atk_obj, "column_deleted", i, 1);
 
           /* Generate children-changed signals */
-          n_rows = get_row_count (gtk_tree_view_get_model (tree_view));
           n_cols = get_n_actual_columns (tree_view);
-          for (row = 0; row < n_rows; row++)
+          for (row = 0; row < gailview->row_count; row++)
             {
              /*
               * Pass NULL as the child object, 4th argument.
@@ -2831,6 +2833,8 @@
   GailTreeView *gailview = GAIL_TREE_VIEW (atk_obj);
   gint row, n_inserted, child_row;
 
+  gailview->row_count++;
+
   if (gailview->idle_expand_id)
     {
       g_source_remove (gailview->idle_expand_id);
@@ -2926,6 +2930,9 @@
   atk_obj = gtk_widget_get_accessible (GTK_WIDGET (tree_view));
   gailview = GAIL_TREE_VIEW (atk_obj);
 
+  gailview->row_count--;
+  g_assert (gailview->row_count >= 0);
+
   if (gailview->idle_expand_id)
     {
       g_source_remove (gailview->idle_expand_id);
@@ -4576,19 +4583,6 @@
     }  
 }
 
-/*
- * This function returns the number of rows, including those which are collapsed
- */
-static gint
-get_row_count (GtkTreeModel *model)
-{
-  gint n_rows = 1;
-
-  count_rows (model, NULL, NULL, &n_rows, 0, G_MAXINT);
-
-  return n_rows;
-}
-
 static gboolean
 get_path_column_from_index (GtkTreeView       *tree_view,
                             gint              index,
