Use cheaper predicate to see if an iterator is empty.

This commit is contained in:
Justus Winter 2024-10-09 14:54:59 +02:00
parent b885328662
commit 1239977a90
No known key found for this signature in database
GPG Key ID: 686F55B4AB2B3386
2 changed files with 5 additions and 5 deletions

View File

@ -125,11 +125,11 @@ pub fn dispatch(sq: Sq, c: keyring::Command) -> Result<()> {
.retain_subkeys(|c| {
! any_key_predicates || key_predicate(c.key())
});
if (c.userids().count() == 0
&& c.user_attributes().count() == 0
&& c.keys().subkeys().count() == 0)
if (c.userids().next().is_none()
&& c.user_attributes().next().is_none()
&& c.keys().subkeys().next().is_none())
|| ((any_key_predicates
&& c.keys().subkeys().count() == 0)
&& c.keys().subkeys().next().is_none())
&& (any_cert_predicates
&& ! cert_predicate(c.primary_key().key())))
{

View File

@ -360,7 +360,7 @@ impl Command {
.filter(|cmd| cmd.get_name() != "help")
.map(|cmd| Command::from_command(&parent, cmd))
.collect();
new.leaf = cmd.get_subcommands().count() == 0;
new.leaf = cmd.get_subcommands().next().is_none();
new
}