[Mesa-dev] [PATCH 3/4] mesa: simplify and inline _mesa_lookup_parameter_index()

Matt Turner mattst88 at gmail.com
Fri Mar 18 01:19:34 UTC 2016


On Thu, Mar 17, 2016 at 6:14 PM, Timothy Arceri
<timothy.arceri at collabora.com> wrote:
> The function has only one user and strings are always null terminated.
> ---
>  src/mesa/program/ir_to_mesa.cpp   |  2 +-
>  src/mesa/program/prog_parameter.c | 38 --------------------------------------
>  src/mesa/program/prog_parameter.h | 19 +++++++++++++++++--
>  3 files changed, 18 insertions(+), 41 deletions(-)
>
> diff --git a/src/mesa/program/ir_to_mesa.cpp b/src/mesa/program/ir_to_mesa.cpp
> index 347d635..f02f406 100644
> --- a/src/mesa/program/ir_to_mesa.cpp
> +++ b/src/mesa/program/ir_to_mesa.cpp
> @@ -2359,7 +2359,7 @@ add_uniform_to_shader::visit_field(const glsl_type *type, const char *name,
>        file = PROGRAM_UNIFORM;
>     }
>
> -   int index = _mesa_lookup_parameter_index(params, -1, name);
> +   int index = _mesa_lookup_parameter_index(params, name);
>     if (index < 0) {
>        index = _mesa_add_parameter(params, file, name, size, type->gl_type,
>                                   NULL, NULL);
> diff --git a/src/mesa/program/prog_parameter.c b/src/mesa/program/prog_parameter.c
> index 19b57ee..25d3835 100644
> --- a/src/mesa/program/prog_parameter.c
> +++ b/src/mesa/program/prog_parameter.c
> @@ -415,41 +415,3 @@ _mesa_add_state_reference(struct gl_program_parameter_list *paramList,
>
>     return index;
>  }
> -
> -
> -/**
> - * Given a program parameter name, find its position in the list of parameters.
> - * \param paramList  the parameter list to search
> - * \param nameLen  length of name (in chars).
> - *                 If length is negative, assume that name is null-terminated.
> - * \param name  the name to search for
> - * \return index of parameter in the list.
> - */
> -GLint
> -_mesa_lookup_parameter_index(const struct gl_program_parameter_list *paramList,
> -                             GLsizei nameLen, const char *name)
> -{
> -   GLint i;
> -
> -   if (!paramList)
> -      return -1;
> -
> -   if (nameLen == -1) {
> -      /* name is null-terminated */
> -      for (i = 0; i < (GLint) paramList->NumParameters; i++) {
> -         if (paramList->Parameters[i].Name &&
> -            strcmp(paramList->Parameters[i].Name, name) == 0)
> -            return i;
> -      }
> -   }
> -   else {
> -      /* name is not null-terminated, use nameLen */
> -      for (i = 0; i < (GLint) paramList->NumParameters; i++) {
> -         if (paramList->Parameters[i].Name &&
> -            strncmp(paramList->Parameters[i].Name, name, nameLen) == 0
> -             && strlen(paramList->Parameters[i].Name) == (size_t)nameLen)
> -            return i;
> -      }
> -   }
> -   return -1;
> -}
> diff --git a/src/mesa/program/prog_parameter.h b/src/mesa/program/prog_parameter.h
> index c17d703..002b4e8 100644
> --- a/src/mesa/program/prog_parameter.h
> +++ b/src/mesa/program/prog_parameter.h
> @@ -34,6 +34,7 @@
>  #include "main/mtypes.h"
>  #include "prog_statevars.h"
>
> +#include <string.h>
>
>  #ifdef __cplusplus
>  extern "C" {
> @@ -124,9 +125,23 @@ extern GLint
>  _mesa_add_state_reference(struct gl_program_parameter_list *paramList,
>                            const gl_state_index stateTokens[STATE_LENGTH]);
>
> -extern GLint
> +
> +static inline GLint
>  _mesa_lookup_parameter_index(const struct gl_program_parameter_list *paramList,
> -                             GLsizei nameLen, const char *name);
> +                             const char *name)
> +{
> +   if (!paramList)
> +      return -1;
> +
> +   /* name must be null-terminated */
> +   for (GLint i = 0; i < (GLint) paramList->NumParameters; i++) {
> +      if (paramList->Parameters[i].Name &&
> +         strcmp(paramList->Parameters[i].Name, name) == 0)

Added a tab here.


More information about the mesa-dev mailing list