[09/14] Remove indirection from tui_data_window::regs_content

Message ID 20190818172735.17477-10-tom@tromey.com
State New
Headers show
Series
  • TUI refactoring round N
Related show

Commit Message

Tom Tromey Aug. 18, 2019, 5:27 p.m.
tui_data_window::regs_content is currently a vector of unique_ptr.
However, due to the way this is managed now, there is no need to keep
the pointers -- it can simply be a vector of the objects themselves.
This patch removes this extra layer of indirection.

gdb/ChangeLog
2019-08-18  Tom Tromey  <tom@tromey.com>

	* tui/tui-regs.h (struct tui_data_window): Use
	DISABLE_COPY_AND_ASSIGN.
	<regs_content>: Change type, removing unique_ptr.
	<tui_data_window>: Add move constructor.
	* tui/tui-regs.c (tui_data_window::show_registers)
	(tui_data_window::show_register_group)
	(tui_data_window::display_registers_from)
	(tui_data_window::display_registers_from)
	(tui_data_window::first_data_item_displayed)
	(tui_data_window::delete_data_content_windows)
	(tui_data_window::rerender, tui_data_window::refresh_window)
	(tui_data_window::check_register_values): Update.
---
 gdb/ChangeLog      | 15 ++++++++++++++
 gdb/tui/tui-regs.c | 51 ++++++++++++++++------------------------------
 gdb/tui/tui-regs.h |  6 +++++-
 3 files changed, 38 insertions(+), 34 deletions(-)

-- 
2.17.2

Patch

diff --git a/gdb/tui/tui-regs.c b/gdb/tui/tui-regs.c
index 8adfb1520a2..675e1867d4b 100644
--- a/gdb/tui/tui-regs.c
+++ b/gdb/tui/tui-regs.c
@@ -163,10 +163,7 @@  tui_data_window::show_registers (struct reggroup *group)
 
       /* Clear all notation of changed values.  */
       for (auto &&data_item_win : regs_content)
-	{
-	  if (data_item_win != nullptr)
-	    data_item_win->highlight = false;
-	}
+	data_item_win.highlight = false;
       current_group = group;
       display_all_data ();
     }
@@ -214,16 +211,7 @@  tui_data_window::show_register_group (struct reggroup *group,
       nr_regs++;
     }
 
-  if (!refresh_values_only)
-    regs_content.clear ();
-
-  if (nr_regs < regs_content.size ())
-    regs_content.resize (nr_regs);
-  else
-    {
-      for (int i = regs_content.size (); i < nr_regs; ++i)
-	regs_content.emplace_back (new tui_data_item_window ());
-    }
+  regs_content.resize (nr_regs);
 
   /* Now set the register names and values.  */
   pos = 0;
@@ -242,7 +230,7 @@  tui_data_window::show_register_group (struct reggroup *group,
       if (name == 0 || *name == '\0')
 	continue;
 
-      data_item_win = regs_content[pos].get ();
+      data_item_win = &regs_content[pos];
       if (data_item_win)
 	{
 	  if (!refresh_values_only)
@@ -273,7 +261,7 @@  tui_data_window::display_registers_from (int start_element_no)
           int len;
 
           len = 0;
-          p = data_item_win->content.get ();
+          p = data_item_win.content.get ();
           if (p != 0)
 	    len = strlen (p);
 
@@ -301,7 +289,7 @@  tui_data_window::display_registers_from (int start_element_no)
 	      struct tui_data_item_window *data_item_win;
 
 	      /* Create the window if necessary.  */
-	      data_item_win = regs_content[i].get ();
+	      data_item_win = &regs_content[i];
               if (data_item_win->handle != NULL
                   && (data_item_win->height != 1
                       || data_item_win->width != item_win_width
@@ -408,7 +396,7 @@  tui_data_window::first_data_item_displayed ()
     {
       struct tui_gen_win_info *data_item_win;
 
-      data_item_win = regs_content[i].get ();
+      data_item_win = &regs_content[i];
       if (data_item_win->is_visible ())
 	return i;
     }
@@ -423,8 +411,8 @@  tui_data_window::delete_data_content_windows ()
 {
   for (auto &&win : regs_content)
     {
-      tui_delete_win (win->handle);
-      win->handle = NULL;
+      tui_delete_win (win.handle);
+      win.handle = NULL;
     }
 }
 
@@ -523,8 +511,8 @@  tui_data_window::rerender ()
   /* Delete all data item windows.  */
   for (auto &&win : regs_content)
     {
-      tui_delete_win (win->handle);
-      win->handle = NULL;
+      tui_delete_win (win.handle);
+      win.handle = NULL;
     }
   display_all_data ();
 }
@@ -536,10 +524,7 @@  tui_data_window::refresh_window ()
 {
   tui_gen_win_info::refresh_window ();
   for (auto &&win : regs_content)
-    {
-      if (win != NULL)
-	win->refresh_window ();
-    }
+    win.refresh_window ();
 }
 
 /* This function check all displayed registers for changes in values,
@@ -552,18 +537,18 @@  tui_data_window::check_register_values (struct frame_info *frame)
     show_registers (current_group);
   else
     {
-      for (auto &&data_item_win_ptr : regs_content)
+      for (auto &&data_item_win : regs_content)
 	{
 	  int was_hilighted;
 
-	  was_hilighted = data_item_win_ptr->highlight;
+	  was_hilighted = data_item_win.highlight;
 
-	  tui_get_register (frame, data_item_win_ptr.get (),
-			    data_item_win_ptr->item_no,
-			    &data_item_win_ptr->highlight);
+	  tui_get_register (frame, &data_item_win,
+			    data_item_win.item_no,
+			    &data_item_win.highlight);
 
-	  if (data_item_win_ptr->highlight || was_hilighted)
-	    tui_display_register (data_item_win_ptr.get ());
+	  if (data_item_win.highlight || was_hilighted)
+	    tui_display_register (&data_item_win);
 	}
     }
 }
diff --git a/gdb/tui/tui-regs.h b/gdb/tui/tui-regs.h
index e07abeda64d..24ec587ea2e 100644
--- a/gdb/tui/tui-regs.h
+++ b/gdb/tui/tui-regs.h
@@ -33,6 +33,10 @@  struct tui_data_item_window : public tui_gen_win_info
   {
   }
 
+  DISABLE_COPY_AND_ASSIGN (tui_data_item_window);
+
+  tui_data_item_window (tui_data_item_window &&) = default;
+
   const char *name = nullptr;
   /* The register number, or data display number.  */
   int item_no = -1;
@@ -60,7 +64,7 @@  struct tui_data_window : public tui_win_info
   }
 
   /* Windows that are used to display registers.  */
-  std::vector<std::unique_ptr<tui_data_item_window>> regs_content;
+  std::vector<tui_data_item_window> regs_content;
   int regs_column_count = 0;
   /* Should regs be displayed at all?  */
   bool display_regs = false;