Author: mordante
Date: Sat Nov 22 23:11:58 2008
New Revision: 30985

URL: http://svn.gna.org/viewcvs/wesnoth?rev=30985&view=rev
Log:
Remove more obsolete caching code.

Modified:
    trunk/src/gui/widgets/grid.cpp
    trunk/src/gui/widgets/grid.hpp

Modified: trunk/src/gui/widgets/grid.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/grid.cpp?rev=30985&r1=30984&r2=30985&view=diff
==============================================================================
--- trunk/src/gui/widgets/grid.cpp (original)
+++ trunk/src/gui/widgets/grid.cpp Sat Nov 22 23:11:58 2008
@@ -23,10 +23,6 @@
 tgrid::tgrid(const unsigned rows, const unsigned cols) 
        : rows_(rows)
        , cols_(cols)
-       , best_row_height_()
-       , best_col_width_()
-       , minimum_row_height_()
-       , minimum_col_width_()
        , row_height_()
        , col_width_()
        , row_grow_factor_(rows)
@@ -92,8 +88,6 @@
                                        && control->does_block_easy_close());
                }
        }
-
-       clear_cache();
 }
 
 twidget* tgrid::swap_child(
@@ -144,7 +138,6 @@
                delete cell.widget();
        }
        cell.set_widget(0);
-       clear_cache();
 }
 
 void tgrid::remove_child(const std::string& id, const bool find_all)
@@ -157,7 +150,6 @@
                                delete itor->widget();
                        }
                        itor->set_widget(0);
-                       clear_cache();
 
                        if(!find_all) {
                                break;
@@ -191,12 +183,6 @@
 
 void tgrid::layout_init()
 {
-       // Clear our cache.
-       best_row_height_.clear();
-       best_col_width_.clear();
-       minimum_row_height_.clear();
-       minimum_col_width_.clear();
-
        // Clear child caches.
        foreach(tchild& child, children_) {
 
@@ -212,8 +198,8 @@
        log_scope2(gui_layout, std::string("tgrid ") + __func__);
 
 
-       best_row_height_.resize(rows_, 0);
-       best_col_width_.resize(cols_, 0);
+       row_height_.resize(rows_, 0);
+       col_width_.resize(cols_, 0);
        
        // First get the sizes for all items.
        for(unsigned row = 0; row < rows_; ++row) {
@@ -221,30 +207,30 @@
 
                        const tpoint size = child(row, col).get_best_size();
 
-                       if(size.x > static_cast<int>(best_col_width_[col])) {
-                               best_col_width_[col] = size.x;
-                       }
-
-                       if(size.y > static_cast<int>(best_row_height_[row])) {
-                               best_row_height_[row] = size.y;
+                       if(size.x > static_cast<int>(col_width_[col])) {
+                               col_width_[col] = size.x;
+                       }
+
+                       if(size.y > static_cast<int>(row_height_[row])) {
+                               row_height_[row] = size.y;
                        }
 
                }
        }
 
        for(unsigned row = 0; row < rows_; ++row) {
-               DBG_G_L << "tgrid: the " << " best_row_height_ for row " << row 
-                       << " will be " << best_row_height_[row] << ".\n";
+               DBG_G_L << "tgrid: the " << " row_height_ for row " << row 
+                       << " will be " << row_height_[row] << ".\n";
        }
 
        for(unsigned col = 0; col < cols_; ++col) {
-               DBG_G_L << "tgrid: the " << " best_col_width_ for col " << col 
-                       << " will be " << best_col_width_[col]  << ".\n";
+               DBG_G_L << "tgrid: the " << " col_width_ for col " << col 
+                       << " will be " << col_width_[col]  << ".\n";
        }
 
        const tpoint result(
-               std::accumulate(best_col_width_.begin(), best_col_width_.end(), 
0),
-               std::accumulate(best_row_height_.begin(), 
best_row_height_.end(), 0));
+               std::accumulate(col_width_.begin(), col_width_.end(), 0),
+               std::accumulate(row_height_.begin(), row_height_.end(), 0));
        
        DBG_G_L << "tgrid: returning " << result << ".\n";
        return result;
@@ -302,17 +288,17 @@
        unsigned reduced = 0;
        for(size_t y = 0; y < rows_; ++y) {
 
-               const unsigned wanted_height = (too_high - reduced) >= 
best_row_height_[y] 
-                       ? 1 : best_row_height_[y] - (too_high - reduced);
+               const unsigned wanted_height = (too_high - reduced) >= 
row_height_[y] 
+                       ? 1 : row_height_[y] - (too_high - reduced);
 
                const unsigned height = row_use_vertical_scrollbar(y, 
wanted_height);
 
-               if(height < best_row_height_[y]) {
-                       DBG_G_L << "tgrid: reduced " << best_row_height_[y] - 
height 
+               if(height < row_height_[y]) {
+                       DBG_G_L << "tgrid: reduced " << row_height_[y] - height 
                                << " pixels for row " << y << ".\n";
 
-                       reduced += best_row_height_[y] - height;
-                       best_row_height_[y] = height;
+                       reduced += row_height_[y] - height;
+                       row_height_[y] = height;
                }
                
                if(reduced >= too_high) {
@@ -353,9 +339,8 @@
                return;
        }
 
-       const tpoint best_size = get_best_size();
-       row_height_ = best_row_height_;
-       col_width_ = best_col_width_;
+       // call the calculate so the size cache gets updated.
+       const tpoint best_size = calculate_best_size();
 
        assert(row_height_.size() == rows_);
        assert(col_width_.size() == cols_);
@@ -374,8 +359,6 @@
 
        /***** GROW *****/
        if(best_size < size) {
-               row_height_ = best_row_height_;
-               col_width_ = best_col_width_;
 
                // expand it.
                if(size.x > best_size.x) {
@@ -578,7 +561,6 @@
 
                widget = widget->find_widget(coordinate, must_be_active);
                if(widget) { 
-                       clear_cache();
                        return widget;
                }
                
@@ -626,7 +608,6 @@
 
                widget = widget->find_widget(id, must_be_active);
                if(widget) { 
-                       clear_cache();
                        return widget;
                }
                
@@ -707,7 +688,6 @@
        row_grow_factor_.resize(rows);
        col_grow_factor_.resize(cols);
        children_.resize(rows_ * cols_);
-       clear_cache();
 }
 
 void tgrid::set_dirty(const bool dirty)
@@ -906,15 +886,6 @@
        }
 
        return result;
-}
-
-void tgrid::clear_cache()
-{
-       best_row_height_.clear();
-       best_col_width_.clear();
-
-       minimum_row_height_.clear();
-       minimum_col_width_.clear();
 }
 
 void tgrid::layout(const tpoint& origin)

Modified: trunk/src/gui/widgets/grid.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/grid.hpp?rev=30985&r1=30984&r2=30985&view=diff
==============================================================================
--- trunk/src/gui/widgets/grid.hpp (original)
+++ trunk/src/gui/widgets/grid.hpp Sat Nov 22 23:11:58 2008
@@ -360,34 +360,11 @@
 
        /***** ***** ***** ***** size caching ***** ***** ***** *****/
 
-       /** Cache containing the best row heights. */
-       mutable std::vector<unsigned> best_row_height_;
-
-       /** Cache containing the best column widths. */
-       mutable std::vector<unsigned> best_col_width_;
-
-       /** Cache containing the best minimum heights. */
-       mutable std::vector<unsigned> minimum_row_height_;
-
-       /** Cache containing the minimum column widths. */
-       mutable std::vector<unsigned> minimum_col_width_;
-
-       /** 
-        * Clears the size caches. 
-        *
-        * @todo we need to evaluate how useful caching is in the first place 
since
-        * quite some functions invalidate the caches and most things are 
calculated
-        * only a few times. This means the caches might be overkill and adding
-        * complexity.
-        */
-       void clear_cache();
-
        /** The row heights in the grid. */
-       std::vector<unsigned> row_height_;
+       mutable std::vector<unsigned> row_height_;
 
        /** The column widths in the grid. */
-       std::vector<unsigned> col_width_;
-
+       mutable std::vector<unsigned> col_width_;
 
        /** The grow factor for all rows. */
        std::vector<unsigned> row_grow_factor_;
@@ -405,7 +382,7 @@
        const tchild& child(const unsigned row, const unsigned col) const
                { return children_[rows_ * col + row]; }
        tchild& child(const unsigned row, const unsigned col)
-               { clear_cache(); return children_[rows_ * col + row]; }
+               { return children_[rows_ * col + row]; }
 
        /** Layouts the children in the grid. */
        void layout(const tpoint& origin);


_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits

Reply via email to