mirror of
https://gitlab.freedesktop.org/dbus/dbus.git
synced 2026-05-05 01:48:00 +02:00
Use 'continue' keyword in preference to 'goto' where possible
In some more complicated loops, we do need to use 'goto' to exit from an inner loop, or to jump to cleanup or an increment of an iterator immediately before the next loop iteration. However, in these simple cases, jumping to a label immediately before the 'while' keyword is unnecessary: we can use an equivalent 'continue' statement for flow control. This makes it easier for maintainers to notice the loops where we are doing something more complicated, which still use 'goto', and know that they need to pay more attention in those cases. Signed-off-by: Simon McVittie <smcv@collabora.com>
This commit is contained in:
parent
2f9d987c0a
commit
54b56ab875
6 changed files with 28 additions and 24 deletions
|
|
@ -552,7 +552,6 @@ process_test_valid_subdir (const DBusString *test_base_dir,
|
|||
else
|
||||
_dbus_test_diag ("Testing unknown files:");
|
||||
|
||||
next:
|
||||
while (_dbus_directory_get_next_file (dir, &filename, &error))
|
||||
{
|
||||
DBusString full_path;
|
||||
|
|
@ -572,7 +571,7 @@ process_test_valid_subdir (const DBusString *test_base_dir,
|
|||
_dbus_verbose ("Skipping non-.conf file %s\n",
|
||||
_dbus_string_get_const_data (&filename));
|
||||
_dbus_string_free (&full_path);
|
||||
goto next;
|
||||
continue;
|
||||
}
|
||||
|
||||
_dbus_test_diag (" %s", _dbus_string_get_const_data (&filename));
|
||||
|
|
|
|||
|
|
@ -3239,7 +3239,6 @@ process_test_valid_subdir (const DBusString *test_base_dir,
|
|||
else
|
||||
_dbus_test_diag ("Testing unknown files:");
|
||||
|
||||
next:
|
||||
while (_dbus_directory_get_next_file (dir, &filename, &error))
|
||||
{
|
||||
DBusString full_path;
|
||||
|
|
@ -3259,7 +3258,7 @@ process_test_valid_subdir (const DBusString *test_base_dir,
|
|||
_dbus_verbose ("Skipping non-.conf file %s\n",
|
||||
_dbus_string_get_const_data (&filename));
|
||||
_dbus_string_free (&full_path);
|
||||
goto next;
|
||||
continue;
|
||||
}
|
||||
|
||||
_dbus_test_diag (" %s", _dbus_string_get_const_data (&filename));
|
||||
|
|
@ -3556,7 +3555,6 @@ all_are_equiv (const DBusString *target_directory)
|
|||
|
||||
_dbus_test_diag ("Comparing equivalent files:");
|
||||
|
||||
next:
|
||||
while (_dbus_directory_get_next_file (dir, &filename, &error))
|
||||
{
|
||||
DBusString full_path;
|
||||
|
|
@ -3575,7 +3573,7 @@ all_are_equiv (const DBusString *target_directory)
|
|||
_dbus_verbose ("Skipping non-.conf file %s\n",
|
||||
_dbus_string_get_const_data (&filename));
|
||||
_dbus_string_free (&full_path);
|
||||
goto next;
|
||||
continue;
|
||||
}
|
||||
|
||||
_dbus_test_diag (" %s", _dbus_string_get_const_data (&filename));
|
||||
|
|
|
|||
|
|
@ -307,7 +307,6 @@ _dbus_auth_script_run (const DBusString *filename)
|
|||
state = DBUS_AUTH_STATE_NEED_DISCONNECT;
|
||||
line_no = 0;
|
||||
|
||||
next_iteration:
|
||||
while (_dbus_string_pop_line (&file, &line))
|
||||
{
|
||||
line_no += 1;
|
||||
|
|
@ -336,20 +335,20 @@ _dbus_auth_script_run (const DBusString *filename)
|
|||
if (_dbus_string_get_length (&line) == 0)
|
||||
{
|
||||
/* empty line */
|
||||
goto next_iteration;
|
||||
continue;
|
||||
}
|
||||
else if (_dbus_string_starts_with_c_str (&line,
|
||||
"#"))
|
||||
{
|
||||
/* Ignore this comment */
|
||||
goto next_iteration;
|
||||
continue;
|
||||
}
|
||||
#ifdef DBUS_WIN
|
||||
else if (_dbus_string_starts_with_c_str (&line,
|
||||
"WIN_ONLY"))
|
||||
{
|
||||
/* Ignore this line */
|
||||
goto next_iteration;
|
||||
continue;
|
||||
}
|
||||
else if (_dbus_string_starts_with_c_str (&line,
|
||||
"UNIX_ONLY"))
|
||||
|
|
@ -365,7 +364,7 @@ _dbus_auth_script_run (const DBusString *filename)
|
|||
"UNIX_ONLY"))
|
||||
{
|
||||
/* Ignore this line */
|
||||
goto next_iteration;
|
||||
continue;
|
||||
}
|
||||
else if (_dbus_string_starts_with_c_str (&line,
|
||||
"WIN_ONLY"))
|
||||
|
|
@ -837,7 +836,7 @@ _dbus_auth_script_run (const DBusString *filename)
|
|||
else
|
||||
goto parse_failed;
|
||||
|
||||
goto next_iteration; /* skip parse_failed */
|
||||
continue; /* skip parse_failed */
|
||||
|
||||
parse_failed:
|
||||
{
|
||||
|
|
|
|||
|
|
@ -82,7 +82,6 @@ process_test_subdir (const DBusString *test_base_dir,
|
|||
|
||||
_dbus_test_diag ("Testing %s:", subdir);
|
||||
|
||||
next:
|
||||
while (_dbus_directory_get_next_file (dir, &filename, &error))
|
||||
{
|
||||
DBusString full_path;
|
||||
|
|
@ -101,7 +100,7 @@ process_test_subdir (const DBusString *test_base_dir,
|
|||
_dbus_verbose ("Skipping non-.auth-script file %s\n",
|
||||
_dbus_string_get_const_data (&filename));
|
||||
_dbus_string_free (&full_path);
|
||||
goto next;
|
||||
continue;
|
||||
}
|
||||
|
||||
_dbus_test_diag (" %s", _dbus_string_get_const_data (&filename));
|
||||
|
|
|
|||
|
|
@ -510,7 +510,6 @@ process_test_subdir (const DBusString *test_base_dir,
|
|||
|
||||
_dbus_test_diag ("Testing %s:", subdir);
|
||||
|
||||
next:
|
||||
while (_dbus_directory_get_next_file (dir, &filename, &error))
|
||||
{
|
||||
DBusString full_path;
|
||||
|
|
@ -531,7 +530,7 @@ process_test_subdir (const DBusString *test_base_dir,
|
|||
_dbus_verbose ("Skipping non-.message-raw file %s\n",
|
||||
_dbus_string_get_const_data (&filename));
|
||||
_dbus_string_free (&full_path);
|
||||
goto next;
|
||||
continue;
|
||||
}
|
||||
|
||||
_dbus_test_diag (" %s",
|
||||
|
|
|
|||
|
|
@ -188,22 +188,27 @@ get_next_expected_result (DBusString *results,
|
|||
if (!_dbus_string_init (&line))
|
||||
_dbus_test_fatal ("no memory");
|
||||
|
||||
next_iteration:
|
||||
while (_dbus_string_pop_line (results, &line))
|
||||
{
|
||||
_dbus_string_delete_leading_blanks (&line);
|
||||
|
||||
if (_dbus_string_get_length (&line) == 0)
|
||||
goto next_iteration;
|
||||
{
|
||||
continue;
|
||||
}
|
||||
else if (_dbus_string_starts_with_c_str (&line, "#"))
|
||||
goto next_iteration;
|
||||
{
|
||||
continue;
|
||||
}
|
||||
else if (_dbus_string_starts_with_c_str (&line, "H>"))
|
||||
{
|
||||
/* don't print */
|
||||
}
|
||||
else if (_dbus_string_starts_with_c_str (&line, "D>") ||
|
||||
_dbus_string_starts_with_c_str (&line, "<D"))
|
||||
goto next_iteration;
|
||||
{
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
int i;
|
||||
|
|
@ -324,7 +329,6 @@ process_test_data (const char *test_data_dir)
|
|||
|
||||
success_count = 0;
|
||||
line_no = 0;
|
||||
next_iteration:
|
||||
while (_dbus_string_pop_line (&tests, &line))
|
||||
{
|
||||
line_no += 1;
|
||||
|
|
@ -332,9 +336,13 @@ process_test_data (const char *test_data_dir)
|
|||
_dbus_string_delete_leading_blanks (&line);
|
||||
|
||||
if (_dbus_string_get_length (&line) == 0)
|
||||
goto next_iteration;
|
||||
{
|
||||
continue;
|
||||
}
|
||||
else if (_dbus_string_starts_with_c_str (&line, "#"))
|
||||
goto next_iteration;
|
||||
{
|
||||
continue;
|
||||
}
|
||||
else if (_dbus_string_starts_with_c_str (&line, "H>"))
|
||||
{
|
||||
_dbus_test_diag ("SHA-1: %s", _dbus_string_get_const_data (&line));
|
||||
|
|
@ -353,7 +361,9 @@ process_test_data (const char *test_data_dir)
|
|||
}
|
||||
else if (_dbus_string_starts_with_c_str (&line, "D>") ||
|
||||
_dbus_string_starts_with_c_str (&line, "<D"))
|
||||
goto next_iteration;
|
||||
{
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
DBusString test;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue