[Aptitude-devel] r3101 - in branches/aptitude-0.3/aptitude: . src/vscreen

Daniel Burrows dburrows@costa.debian.org
Tue, 26 Apr 2005 23:38:35 +0000


Author: dburrows
Date: Tue Apr 26 23:38:32 2005
New Revision: 3101

Modified:
   branches/aptitude-0.3/aptitude/ChangeLog
   branches/aptitude-0.3/aptitude/src/vscreen/fragment.cc
Log:
Tweak for great correctness.

Modified: branches/aptitude-0.3/aptitude/ChangeLog
==============================================================================
--- branches/aptitude-0.3/aptitude/ChangeLog	(original)
+++ branches/aptitude-0.3/aptitude/ChangeLog	Tue Apr 26 23:38:32 2005
@@ -2,6 +2,13 @@
 
 	* src/vscreen/fragment.cc:
 
+	  For more correctness, tie the cache to the last seen
+	  indentations.  (only the last values are preserved because I
+	  expect them never to change; this is so that in case they do for
+	  some odd reason, the results are still correct)
+
+	* src/vscreen/fragment.cc:
+
 	  Fix sequence_fragment::trailing_width to return the correct
 	  value (previously, it would always return 0, due to an
 	  accidental bool -> int conversion).

Modified: branches/aptitude-0.3/aptitude/src/vscreen/fragment.cc
==============================================================================
--- branches/aptitude-0.3/aptitude/src/vscreen/fragment.cc	(original)
+++ branches/aptitude-0.3/aptitude/src/vscreen/fragment.cc	Tue Apr 26 23:38:32 2005
@@ -113,9 +113,24 @@
  */
 class fragment_container:public fragment
 {
+  void update_width(size_t first_indent,
+		    size_t rest_indent) const
+  {
+    if(width_stale ||
+       first_indent != stale_first_indent ||
+       rest_indent != stale_rest_indent)
+      {
+	max_width_cache=calc_max_width(first_indent, rest_indent);
+	trailing_width_cache=calc_trailing_width(first_indent,
+						 rest_indent);
+	width_stale=false;
+	stale_first_indent=first_indent;
+	stale_rest_indent=rest_indent;
+      }
+  }
 public:
   fragment_container()
-    :max_width_stale(true), trailing_width_stale(true), final_nl_stale(true)
+    :width_stale(true), final_nl_stale(true)
   {
   }
 
@@ -133,25 +148,14 @@
   size_t max_width(size_t first_indent,
 		   size_t rest_indent) const
   {
-    if(max_width_stale)
-      {
-	max_width_cache=calc_max_width(first_indent, rest_indent);
-	max_width_stale=false;
-      }
-
+    update_width(first_indent, rest_indent);
     return max_width_cache;
   }
 
   size_t trailing_width(size_t first_indent,
 			size_t rest_indent) const
   {
-    if(trailing_width_stale)
-      {
-	trailing_width_cache=calc_trailing_width(first_indent,
-						 rest_indent);
-	trailing_width_stale=false;
-      }
-
+    update_width(first_indent, rest_indent);
     return trailing_width_cache;
   }
 
@@ -168,8 +172,9 @@
 
 private:
   mutable size_t max_width_cache, trailing_width_cache;
+  mutable size_t stale_first_indent, stale_rest_indent;
   mutable bool final_nl_cache:1;
-  mutable bool max_width_stale:1, trailing_width_stale:1, final_nl_stale:1;
+  mutable bool width_stale:1, final_nl_stale:1;
 };
 
 /** A fragment generated by composing a sequence of other fragments. */