Simplify a function
Kristian Høgsberg
hoegsberg at gmail.com
Mon Jul 29 16:51:20 PDT 2013
On Thu, Jul 25, 2013 at 01:51:53AM +0300, Jiergir Ogoerg wrote:
> Hi,
> I think in wayland-client.c the function
> wl_display_dispatch_queue_pending(...)
> could be simplified
> from this:
> pthread_mutex_lock(&display->mutex);
> if (dispatch_queue(display, queue) == -1)
> goto err_unlock;
> pthread_mutex_unlock(&display->mutex);
> return 0;
> err_unlock:
> pthread_mutex_unlock(&display->mutex);
> return -1;
>
> to this:
> int ret;
> pthread_mutex_lock(&display->mutex);
> ret = dispatch_queue(display, queue);
> pthread_mutex_unlock(&display->mutex);
> return (ret == -1) ? -1 : 0;
I don't find that the ternary operater (a ? b : c) typically
simplifies things, it make C look more like Perl. But in case of
wl_display_dispatch_queue_pending(), the intended (and documented!)
behavior is to return "number of events dispatched or -1 on error", so
we should in fact just return ret.
In that case, it's indeed simpler to avoid the goto.
Kristian
>
>
>
> Just my 0.02$
> _______________________________________________
> wayland-devel mailing list
> wayland-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/wayland-devel
More information about the wayland-devel
mailing list