On Tue, 2004-02-24 at 11:02, John Beppu wrote:

> The has() method in this release has a bug.
> 
> Here's how it looks right now:
> 
>     sub has
>     {
>           my ($class, $define) = @_;
>           scalar grep { exists $$sdl_config{$_}{$define} } keys %$sdl_config;
>     }
> 
> Unfortunately, even if certain attributes are set to 0,
> the existence check still passes.  For example, I don't
> have SDL_ttf on my system, and the $sdl_config hashref
> knows this.  However, 
>          
>     SDL::Config->has('SDL_ttf')
> 
> returns 1;
> 
> Get rid of "exists" and it'll work as advertised.

True, but it'll eat up memory in the hash if you pass undefined
subsystem names.  That's why the original version was:

   sub has
   {
        my ($class, $define) = @_;

        while (my ($name, $subsystems) =  each %$sdl_config)
        {
            next unless exists $subsystems->{ $define };
            return $subsystems->{ $define } ? 1 : 0;
        }

        return;
    }

Maybe it was silly to optimize this never to use any more memory or to
keep an O(n) operation O(n/2) or better, but it's not susceptible to
this bug.

On the other hand, I suspect the new version performs better in list
context.

-- c

Reply via email to