[Aptitude-svn-commit] r3527 - in branches/aptitude-0.3/aptitude: . src/vscreen

Daniel Burrows dburrows@costa.debian.org
Sat, 02 Jul 2005 13:15:29 +0000


Author: dburrows
Date: Sat Jul  2 13:15:27 2005
New Revision: 3527

Modified:
   branches/aptitude-0.3/aptitude/ChangeLog
   branches/aptitude-0.3/aptitude/src/vscreen/vs_layout_item.cc
   branches/aptitude-0.3/aptitude/src/vscreen/vs_layout_item.h
Log:
Remove a silly inefficiency in vs_layout_item.

Modified: branches/aptitude-0.3/aptitude/ChangeLog
==============================================================================
--- branches/aptitude-0.3/aptitude/ChangeLog	(original)
+++ branches/aptitude-0.3/aptitude/ChangeLog	Sat Jul  2 13:15:27 2005
@@ -1,5 +1,11 @@
 2005-07-02  Daniel Burrows  <dburrows@debian.org>
 
+	* src/vscreen/vs_layout_item.cc:
+
+	  Make vs_layout_item less absurdly inefficient by really caching
+	  all of its contents up-front, rather than calling layout() once
+	  for EVERY LINE IN THE ITEM.
+
 	* src/vscreen/vs_layout_item.cc, src/vscreen/vs_layout_item.h:
 
 	  Avoid several copies when displaying a vs_layout_item.

Modified: branches/aptitude-0.3/aptitude/src/vscreen/vs_layout_item.cc
==============================================================================
--- branches/aptitude-0.3/aptitude/src/vscreen/vs_layout_item.cc	(original)
+++ branches/aptitude-0.3/aptitude/src/vscreen/vs_layout_item.cc	Sat Jul  2 13:15:27 2005
@@ -43,7 +43,7 @@
 
 
 vs_layout_item::vs_layout_item(fragment *_f)
-  :f(_f), lastw(0)
+  :f(_f), lastw(0), lastbasex(-1)
 {
 }
 
@@ -80,18 +80,28 @@
 const fragment_line &vs_layout_item::get_line(vs_tree *win, size_t n,
 					      int basex, const style &st)
 {
-  if(win->getmaxx()!=lastw)
+  if(win->getmaxx()!=lastw || basex != lastbasex)
     {
-      // Indent it MANUALLY for now. (why?)
-      lines=f->layout(win->getmaxx()-basex,
-		      win->getmaxx()-basex,
-		      st);
+      fragment_contents tmplines=f->layout(win->getmaxx()-basex,
+					   win->getmaxx()-basex,
+					   st);
+
+      lines=fragment_contents();
+      attr_t attr=st.get_attrs();
+      for(fragment_contents::const_iterator i=tmplines.begin();
+	  i!=tmplines.end(); ++i)
+	lines.push_back(fragment_line(basex, wchtype(L' ', attr))+*i);
+
       for(child_list::iterator i=children.begin(); i!=children.end(); ++i)
 	delete *i;
+
       children.clear();
 
       for(size_t i=1; i<lines.size(); ++i)
 	children.push_back(new vs_layout_line(i, *this));
+
+      lastw=win->getmaxx();
+      lastbasex=basex;
     }
 
   if(n>=lines.size())
@@ -106,7 +116,7 @@
 
   const fragment_line &s=get_line(win, n, basex, st);
 
-  win->mvaddnstr(y, 0, fragment_line(basex, ' ', st.get_attrs())+s, basex+s.size());
+  win->mvaddnstr(y, 0, s, s.size());
 }
 
 void vs_layout_item::vs_layout_line::paint(vs_tree *win, int y,

Modified: branches/aptitude-0.3/aptitude/src/vscreen/vs_layout_item.h
==============================================================================
--- branches/aptitude-0.3/aptitude/src/vscreen/vs_layout_item.h	(original)
+++ branches/aptitude-0.3/aptitude/src/vscreen/vs_layout_item.h	Sat Jul  2 13:15:27 2005
@@ -23,6 +23,7 @@
   fragment_contents lines;
 
   int lastw;
+  int lastbasex;
 
 protected:
   class vs_layout_line:public vs_treeitem