aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2019-07-14 09:07:10 -0600
committerTom Tromey <tom@tromey.com>2019-08-30 12:57:03 -0600
commit0670413d0eb264302e10a1baa163bc9c8c279a21 (patch)
treec8fb97ae6ca24c887f3c538c8ffd597a88679642
parent18bb55c7225dfd07ec8d75226a83da1872db8b90 (diff)
downloadgdb-0670413d0eb264302e10a1baa163bc9c8c279a21.zip
gdb-0670413d0eb264302e10a1baa163bc9c8c279a21.tar.gz
gdb-0670413d0eb264302e10a1baa163bc9c8c279a21.tar.bz2
Remove some checks of .empty()
A few methods in tui_data_window check whether the contents are empty; but all the callers already check this, so these calls can be removed. gdb/ChangeLog 2019-08-30 Tom Tromey <tom@tromey.com> * tui/tui-regs.c (tui_data_window::last_regs_line_no) (tui_data_window::display_registers_from) (tui_data_window::display_reg_element_at_line) (tui_data_window::display_registers_from_line): Remove checks of "empty".
-rw-r--r--gdb/ChangeLog8
-rw-r--r--gdb/tui/tui-regs.c207
2 files changed, 104 insertions, 111 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index e5f3f21..c8b69f4 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,13 @@
2019-08-30 Tom Tromey <tom@tromey.com>
+ * tui/tui-regs.c (tui_data_window::last_regs_line_no)
+ (tui_data_window::display_registers_from)
+ (tui_data_window::display_reg_element_at_line)
+ (tui_data_window::display_registers_from_line): Remove checks of
+ "empty".
+
+2019-08-30 Tom Tromey <tom@tromey.com>
+
* tui/tui-regs.h (struct tui_data_window) <display_all_data>:
Don't declare.
* tui/tui-regs.c (tui_data_window::show_registers): Call
diff --git a/gdb/tui/tui-regs.c b/gdb/tui/tui-regs.c
index 7bac19d..636ae10 100644
--- a/gdb/tui/tui-regs.c
+++ b/gdb/tui/tui-regs.c
@@ -98,14 +98,9 @@ tui_get_register (struct frame_info *frame,
int
tui_data_window::last_regs_line_no () const
{
- int num_lines = (-1);
-
- if (!regs_content.empty ())
- {
- num_lines = regs_content.size () / regs_column_count;
- if (regs_content.size () % regs_column_count)
- num_lines++;
- }
+ int num_lines = regs_content.size () / regs_column_count;
+ if (regs_content.size () % regs_column_count)
+ num_lines++;
return num_lines;
}
@@ -245,74 +240,71 @@ tui_data_window::show_register_group (struct reggroup *group,
void
tui_data_window::display_registers_from (int start_element_no)
{
- if (!regs_content.empty ())
+ int j, item_win_width, cur_y;
+
+ int max_len = 0;
+ for (auto &&data_item_win : regs_content)
{
- int j, item_win_width, cur_y;
+ const char *p;
+ int len;
- int max_len = 0;
- for (auto &&data_item_win : regs_content)
- {
- const char *p;
- int len;
-
- len = 0;
- p = data_item_win.content.get ();
- if (p != 0)
- len = strlen (p);
-
- if (len > max_len)
- max_len = len;
- }
- item_win_width = max_len + 1;
- int i = start_element_no;
-
- regs_column_count = (width - 2) / item_win_width;
- if (regs_column_count == 0)
- regs_column_count = 1;
- item_win_width = (width - 2) / regs_column_count;
-
- /* Now create each data "sub" window, and write the display into
- it. */
- cur_y = 1;
- while (i < regs_content.size ()
- && cur_y <= viewport_height)
+ len = 0;
+ p = data_item_win.content.get ();
+ if (p != 0)
+ len = strlen (p);
+
+ if (len > max_len)
+ max_len = len;
+ }
+ item_win_width = max_len + 1;
+ int i = start_element_no;
+
+ regs_column_count = (width - 2) / item_win_width;
+ if (regs_column_count == 0)
+ regs_column_count = 1;
+ item_win_width = (width - 2) / regs_column_count;
+
+ /* Now create each data "sub" window, and write the display into
+ it. */
+ cur_y = 1;
+ while (i < regs_content.size ()
+ && cur_y <= viewport_height)
+ {
+ for (j = 0;
+ j < regs_column_count && i < regs_content.size ();
+ j++)
{
- for (j = 0;
- j < regs_column_count && i < regs_content.size ();
- j++)
+ struct tui_data_item_window *data_item_win;
+
+ /* Create the window if necessary. */
+ data_item_win = &regs_content[i];
+ if (data_item_win->handle != NULL
+ && (data_item_win->height != 1
+ || data_item_win->width != item_win_width
+ || data_item_win->origin.x != (item_win_width * j) + 1
+ || data_item_win->origin.y != cur_y))
{
- struct tui_data_item_window *data_item_win;
-
- /* Create the window if necessary. */
- data_item_win = &regs_content[i];
- if (data_item_win->handle != NULL
- && (data_item_win->height != 1
- || data_item_win->width != item_win_width
- || data_item_win->origin.x != (item_win_width * j) + 1
- || data_item_win->origin.y != cur_y))
- {
- tui_delete_win (data_item_win->handle);
- data_item_win->handle = 0;
- }
+ tui_delete_win (data_item_win->handle);
+ data_item_win->handle = 0;
+ }
- if (data_item_win->handle == NULL)
- {
- data_item_win->height = 1;
- data_item_win->width = item_win_width;
- data_item_win->origin.x = (item_win_width * j) + 1;
- data_item_win->origin.y = cur_y;
- data_item_win->make_visible (true);
- scrollok (data_item_win->handle, FALSE);
- }
- touchwin (data_item_win->handle);
-
- /* Get the printable representation of the register
- and display it. */
- tui_display_register (data_item_win);
- i++; /* Next register. */
+ if (data_item_win->handle == NULL)
+ {
+ data_item_win->height = 1;
+ data_item_win->width = item_win_width;
+ data_item_win->origin.x = (item_win_width * j) + 1;
+ data_item_win->origin.y = cur_y;
+ data_item_win->make_visible (true);
+ scrollok (data_item_win->handle, FALSE);
}
- cur_y++; /* Next row. */
+ touchwin (data_item_win->handle);
+
+ /* Get the printable representation of the register
+ and display it. */
+ tui_display_register (data_item_win);
+ i++; /* Next register. */
}
+ cur_y++; /* Next row. */
}
}
@@ -322,27 +314,24 @@ void
tui_data_window::display_reg_element_at_line (int start_element_no,
int start_line_no)
{
- if (!regs_content.empty ())
- {
- int element_no = start_element_no;
+ int element_no = start_element_no;
- if (start_element_no != 0 && start_line_no != 0)
- {
- int last_line_no, first_line_on_last_page;
-
- last_line_no = last_regs_line_no ();
- first_line_on_last_page = last_line_no - (height - 2);
- if (first_line_on_last_page < 0)
- first_line_on_last_page = 0;
-
- /* If the element_no causes us to scroll past the end of the
- registers, adjust what element to really start the
- display at. */
- if (start_line_no > first_line_on_last_page)
- element_no = first_reg_element_no_inline (first_line_on_last_page);
- }
- display_registers_from (element_no);
+ if (start_element_no != 0 && start_line_no != 0)
+ {
+ int last_line_no, first_line_on_last_page;
+
+ last_line_no = last_regs_line_no ();
+ first_line_on_last_page = last_line_no - (height - 2);
+ if (first_line_on_last_page < 0)
+ first_line_on_last_page = 0;
+
+ /* If the element_no causes us to scroll past the end of the
+ registers, adjust what element to really start the
+ display at. */
+ if (start_line_no > first_line_on_last_page)
+ element_no = first_reg_element_no_inline (first_line_on_last_page);
}
+ display_registers_from (element_no);
}
/* See tui-regs.h. */
@@ -351,34 +340,30 @@ int
tui_data_window::display_registers_from_line (int line_no)
{
check_and_display_highlight_if_needed ();
- if (!regs_content.empty ())
- {
- int element_no;
- if (line_no < 0)
- line_no = 0;
- else
+ int element_no;
+
+ if (line_no < 0)
+ line_no = 0;
+ else
+ {
+ /* Make sure that we don't display off the end of the
+ registers. */
+ if (line_no >= last_regs_line_no ())
{
- /* Make sure that we don't display off the end of the
- registers. */
- if (line_no >= last_regs_line_no ())
- {
- line_no = line_from_reg_element_no (regs_content.size () - 1);
- if (line_no < 0)
- line_no = 0;
- }
+ line_no = line_from_reg_element_no (regs_content.size () - 1);
+ if (line_no < 0)
+ line_no = 0;
}
-
- element_no = first_reg_element_no_inline (line_no);
- if (element_no < regs_content.size ())
- display_reg_element_at_line (element_no, line_no);
- else
- line_no = (-1);
-
- return line_no;
}
- return (-1); /* Nothing was displayed. */
+ element_no = first_reg_element_no_inline (line_no);
+ if (element_no < regs_content.size ())
+ display_reg_element_at_line (element_no, line_no);
+ else
+ line_no = (-1);
+
+ return line_no;
}