diff options
author | Jérémie Courrèges-Anglas <jca@wxcvbn.org> | 2014-03-03 10:33:48 +0100 |
---|---|---|
committer | Jérémie Courrèges-Anglas <jca@wxcvbn.org> | 2014-03-03 10:33:48 +0100 |
commit | c7bc35e610b165f49201537ca4d2425b46bd31bb (patch) | |
tree | a9f8d454316c6f17b447ebc65ba590dcb526b401 | |
parent | 1e9ec347b28a884f6fee8f1f42c6d5360546dd08 (diff) | |
download | ratpoison-c7bc35e610b165f49201537ca4d2425b46bd31bb.zip |
Better, faster, prettier groups_find_by_group_name
* there are really two operation modes that could even be put into separate
functions. So disentangle the logic and put the operation mode check
outside of the loop parsing the groups list.
-rw-r--r-- | src/group.c | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/src/group.c b/src/group.c index 037e570..02d2073 100644 --- a/src/group.c +++ b/src/group.c @@ -232,12 +232,19 @@ groups_find_group_by_name (char *s, int exact_match) { rp_group *cur; - list_for_each_entry (cur, &rp_groups, node) + if (!exact_match) + { + list_for_each_entry (cur, &rp_groups, node) + { + if (cur->name && str_comp (s, cur->name, strlen (s))) + return cur; + } + } + else { - if (cur->name) + list_for_each_entry (cur, &rp_groups, node) { - if ((!exact_match && str_comp (s, cur->name, strlen (s))) || - (exact_match && !strcmp (cur->name, s))) + if (cur->name && !strcmp (cur->name, s)) return cur; } } |