Francois Gouget : testbot: Optimize the validation of enum properties.
Alexandre Julliard
julliard at winehq.org
Mon Jun 4 15:43:21 CDT 2018
Module: tools
Branch: master
Commit: 9207a905482419124940cd83167b61112174b722
URL: https://source.winehq.org/git/tools.git/?a=commit;h=9207a905482419124940cd83167b61112174b722
Author: Francois Gouget <fgouget at codeweavers.com>
Date: Mon Jun 4 20:07:12 2018 +0200
testbot: Optimize the validation of enum properties.
Signed-off-by: Francois Gouget <fgouget at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
testbot/lib/ObjectModel/EnumPropertyDescriptor.pm | 15 ++++++---------
1 file changed, 6 insertions(+), 9 deletions(-)
diff --git a/testbot/lib/ObjectModel/EnumPropertyDescriptor.pm b/testbot/lib/ObjectModel/EnumPropertyDescriptor.pm
index d8f0d39..0846673 100644
--- a/testbot/lib/ObjectModel/EnumPropertyDescriptor.pm
+++ b/testbot/lib/ObjectModel/EnumPropertyDescriptor.pm
@@ -42,6 +42,7 @@ sub _initialize($$)
$self->{Class} = "Enum";
$self->{Values} = $Values;
+ map { $self->{Allowed}->{$_} = 1 } @{$Values};
if (!$self->{IsRequired})
{
die "Optional enum properties are not supported\n";
@@ -68,18 +69,14 @@ sub ValidateValue($$$)
{
my ($self, $Value, $IsNew) = @_;
- if ($self->GetIsRequired())
- {
- if (!$IsNew && (!defined($Value) || $Value eq ""))
- {
- return $self->GetDisplayName() . ": Must be entered";
- }
- }
+ return undef if (defined $Value and $self->{Allowed}->{$Value});
- foreach my $V (@{$self->{Values}})
+ if ($self->GetIsRequired() and !$IsNew and
+ (!defined $Value or $Value eq ""))
{
- return undef if ($V eq $Value);
+ return $self->GetDisplayName() . ": Must be entered";
}
+
return $self->GetDisplayName() . ": Is not valid";
}
More information about the wine-cvs
mailing list