[Mesa-dev] [PATCH 4/4] egl: use switch statements over if/else chain

Eric Engestrom eric.engestrom at imgtec.com
Thu Sep 7 16:57:53 UTC 2017


On Thursday, 2017-09-07 17:03:53 +0100, Emil Velikov wrote:
> From: Emil Velikov <emil.velikov at collabora.com>
> 
> Shorter, explicit and consistent with the rest of the co debase.

s/co debase/code base/

in the commit title of patch 2/4:
s/since line/single line/

I don't have time to properly review patch 1/4 today, I'll try and have
a look tomorrow, but patches 2-4 are:
Reviewed-by: Eric Engestrom <eric.engestrom at imgtec.com>

(3/4 obviously depends on 1/4 though, so don't land the former without
the latter :)

> 
> Signed-off-by: Emil Velikov <emil.velikov at collabora.com>
> ---
>  src/egl/main/eglapi.c | 59 ++++++++++++++++++++++++---------------------------
>  1 file changed, 28 insertions(+), 31 deletions(-)
> 
> diff --git a/src/egl/main/eglapi.c b/src/egl/main/eglapi.c
> index 9a59d9e0c35..4a9b3fe3925 100644
> --- a/src/egl/main/eglapi.c
> +++ b/src/egl/main/eglapi.c
> @@ -2393,13 +2393,6 @@ eglLabelObjectKHR(EGLDisplay dpy, EGLenum objectType, EGLObjectKHR object,
>     RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_BAD_PARAMETER);
>  }
>  
> -static EGLBoolean
> -_validDebugMessageLevel(EGLAttrib level)
> -{
> -   return (level >= EGL_DEBUG_MSG_CRITICAL_KHR &&
> -           level <= EGL_DEBUG_MSG_INFO_KHR);
> -}
> -
>  static EGLint EGLAPIENTRY
>  eglDebugMessageControlKHR(EGLDEBUGPROCKHR callback,
>                            const EGLAttrib *attrib_list)
> @@ -2415,20 +2408,24 @@ eglDebugMessageControlKHR(EGLDEBUGPROCKHR callback,
>        int i;
>  
>        for (i = 0; attrib_list[i] != EGL_NONE; i += 2) {
> -         if (_validDebugMessageLevel(attrib_list[i])) {
> +         switch (attrib_list[i]) {
> +         case EGL_DEBUG_MSG_CRITICAL_KHR:
> +         case EGL_DEBUG_MSG_ERROR_KHR:
> +         case EGL_DEBUG_MSG_WARN_KHR:
> +         case EGL_DEBUG_MSG_INFO_KHR:
>              if (attrib_list[i + 1])
>                 newEnabled |= DebugBitFromType(attrib_list[i]);
>              else
>                 newEnabled &= ~DebugBitFromType(attrib_list[i]);
> -            continue;
> +            break;
> +         default:
> +            // On error, set the last error code, call the current
> +            // debug callback, and return the error code.
> +            mtx_unlock(_eglGlobal.Mutex);
> +            _eglReportError(EGL_BAD_ATTRIBUTE, NULL,
> +                  "Invalid attribute 0x%04lx", (unsigned long) attrib_list[i]);
> +            return EGL_BAD_ATTRIBUTE;
>           }
> -
> -         // On error, set the last error code, call the current
> -         // debug callback, and return the error code.
> -         mtx_unlock(_eglGlobal.Mutex);
> -         _eglReportError(EGL_BAD_ATTRIBUTE, NULL,
> -                         "Invalid attribute 0x%04lx", (unsigned long) attrib_list[i]);
> -         return EGL_BAD_ATTRIBUTE;
>        }
>     }
>  
> @@ -2451,25 +2448,25 @@ eglQueryDebugKHR(EGLint attribute, EGLAttrib *value)
>  
>     mtx_lock(_eglGlobal.Mutex);
>  
> -   do {
> -      if (_validDebugMessageLevel(attribute)) {
> -         if (_eglGlobal.debugTypesEnabled & DebugBitFromType(attribute))
> -            *value = EGL_TRUE;
> -         else
> -            *value = EGL_FALSE;
> -         break;
> -      }
> -
> -      if (attribute == EGL_DEBUG_CALLBACK_KHR) {
> -         *value = (EGLAttrib) _eglGlobal.debugCallback;
> -         break;
> -      }
> -
> +   switch (attribute) {
> +   case EGL_DEBUG_MSG_CRITICAL_KHR:
> +   case EGL_DEBUG_MSG_ERROR_KHR:
> +   case EGL_DEBUG_MSG_WARN_KHR:
> +   case EGL_DEBUG_MSG_INFO_KHR:
> +      if (_eglGlobal.debugTypesEnabled & DebugBitFromType(attribute))
> +         *value = EGL_TRUE;
> +      else
> +         *value = EGL_FALSE;
> +      break;
> +   case EGL_DEBUG_CALLBACK_KHR:
> +      *value = (EGLAttrib) _eglGlobal.debugCallback;
> +      break;
> +   default:
>        mtx_unlock(_eglGlobal.Mutex);
>        _eglReportError(EGL_BAD_ATTRIBUTE, NULL,
>                        "Invalid attribute 0x%04lx", (unsigned long) attribute);
>        return EGL_FALSE;
> -   } while (0);
> +   }
>  
>     mtx_unlock(_eglGlobal.Mutex);
>     return EGL_TRUE;
> -- 
> 2.14.1
> 


More information about the mesa-dev mailing list