[PATCH] testbot: A small fix and optimization for Collection::IsEmpty().
Even after loading the collection $self->{Items} could be undefined if no row matched the filters. There is no need to extract the list of keys in order to determine whether the collection is empty. Signed-off-by: Francois Gouget <fgouget(a)codeweavers.com> --- testbot/lib/ObjectModel/Collection.pm | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/testbot/lib/ObjectModel/Collection.pm b/testbot/lib/ObjectModel/Collection.pm index 86dee057f..7fa977cda 100644 --- a/testbot/lib/ObjectModel/Collection.pm +++ b/testbot/lib/ObjectModel/Collection.pm @@ -420,7 +420,9 @@ sub IsEmpty($) $self->Load(); } - return scalar(keys %{$self->{Items}}) == 0; + # Even though scalar(hash) does not return the number of items in Perl 5.20 + # it returns 0 for an empty hash. + return !$self->{Items} || scalar(%{$self->{Items}}) == 0; } sub CombineKey($@) -- 2.16.1
participants (1)
-
Francois Gouget