Am 17.05.2018 um 08:59 schrieb Tapani Pälli:
>
>
> On 05/10/2018 12:05 PM, Benedikt Schemmer wrote:
>> remove a memset too and yes, this is all functionally identical
>>
>> ---
>> src/mesa/main/shaderapi.c | 40 ++++++++++++++++++++--------------------
>> 1 file changed, 20 insertions(+), 20 deletions(-)
>>
>> diff --git a/src/mesa/main/shaderapi.c b/src/mesa/main/shaderapi.c
>> index e8acca4490..1d0ca5374b 100644
>> --- a/src/mesa/main/shaderapi.c
>> +++ b/src/mesa/main/shaderapi.c
>> @@ -241,11 +241,10 @@ _mesa_init_shader_state(struct gl_context *ctx)
>> /* Device drivers may override these to control what kind of
>> instructions
>> * are generated by the GLSL compiler.
>> */
>> - struct gl_shader_compiler_options options;
>> + struct gl_shader_compiler_options options = {};
>> gl_shader_stage sh;
>> int i;
>>
>> - memset(&options, 0, sizeof(options));
>> options.MaxUnrollIterations = 32;
>> options.MaxIfDepth = UINT_MAX;
>>
>> @@ -254,7 +253,7 @@ _mesa_init_shader_state(struct gl_context *ctx)
>>
>> ctx->Shader.Flags = _mesa_get_shader_flags();
>>
>> - if (ctx->Shader.Flags != 0)
>> + if (ctx->Shader.Flags)
>> ctx->Const.GenerateTemporaryNames = true;
>>
>> /* Extended for ARB_separate_shader_objects */
>> @@ -771,7 +770,8 @@ get_programiv(struct gl_context *ctx, GLuint program,
>> GLenum pname,
>> GLint *params)
>> {
>> struct gl_shader_program *shProg
>> - = _mesa_lookup_shader_program_err(ctx, program,
>> "glGetProgramiv(program)");
>> + = _mesa_lookup_shader_program_err(ctx, program,
>> + "glGetProgramiv(program)");
>>
>> /* Is transform feedback available in this context?
>> */
>> @@ -953,7 +953,7 @@ get_programiv(struct gl_context *ctx, GLuint program,
>> GLenum pname,
>> *params = shProg->BinaryRetreivableHint;
>> return;
>> case GL_PROGRAM_BINARY_LENGTH:
>> - if (ctx->Const.NumProgramBinaryFormats == 0) {
>> + if (!ctx->Const.NumProgramBinaryFormats) {
>
> Maybe it's just me having some OCD but with these 'Num' constants I find it
> much easier to read '== 0' than '!' (also below with NumProgramBinaryFormats
> and NumSubroutineUniformRemapTable).
>
> I don't feel strong about this though so no need to change this.
I dont have strong feelings about this either, I use a script to replace these
things.
In my opinion it just helps to see whether these comparisons have meaning. >=1
or ==0 don't really.
If they do I just use a define to make it clear. Otherwise I find the ! easier
to read and understand.
>
>> *params = 0;
>> } else {
>> _mesa_get_program_binary_length(ctx, shProg, params);
>> @@ -974,7 +974,7 @@ get_programiv(struct gl_context *ctx, GLuint program,
>> GLenum pname,
>> "linked)");
>> return;
>> }
>> - if (shProg->_LinkedShaders[MESA_SHADER_COMPUTE] == NULL) {
>> + if (!shProg->_LinkedShaders[MESA_SHADER_COMPUTE]) {
>> _mesa_error(ctx, GL_INVALID_OPERATION, "glGetProgramiv(no compute
>> "
>> "shaders)");
>> return;
>> @@ -1234,7 +1234,7 @@ _mesa_compile_shader(struct gl_context *ctx, struct
>> gl_shader *sh)
>> } else {
>> if (ctx->_Shader->Flags & GLSL_DUMP) {
>> _mesa_log("GLSL source for %s shader %d:\n",
>> - _mesa_shader_stage_to_string(sh->Stage), sh->Name);
>> + _mesa_shader_stage_to_string(sh->Stage), sh->Name);
>> _mesa_log("%s\n", sh->Source);
>> }
>>
>> @@ -1381,13 +1381,13 @@ link_program(struct gl_context *ctx, struct
>> gl_shader_program *shProg,
>> GLuint i;
>>
>> printf("Link %u shaders in program %u: %s\n",
>> - shProg->NumShaders, shProg->Name,
>> - shProg->data->LinkStatus ? "Success" : "Failed");
>> + shProg->NumShaders, shProg->Name,
>> + shProg->data->LinkStatus ? "Success" : "Failed");
>>
>> for (i = 0; i < shProg->NumShaders; i++) {
>> printf(" shader %u, stage %u\n",
>> - shProg->Shaders[i]->Name,
>> - shProg->Shaders[i]->Stage);
>> + shProg->Shaders[i]->Name,
>> + shProg->Shaders[i]->Stage);
>> }
>> }
>> }
>> @@ -1460,7 +1460,7 @@ void
>> _mesa_active_program(struct gl_context *ctx, struct gl_shader_program
>> *shProg,
>> const char *caller)
>> {
>> - if ((shProg != NULL) && !shProg->data->LinkStatus) {
>> + if ((shProg) && !shProg->data->LinkStatus) {
>
> remove extra parenthesis
>
>> _mesa_error(ctx, GL_INVALID_OPERATION,
>> "%s(program %u not linked)", caller, shProg->Name);
>> return;
>> @@ -1794,7 +1794,7 @@ void GLAPIENTRY
>> _mesa_GetObjectParameterfvARB(GLhandleARB object, GLenum pname,
>> GLfloat *params)
>> {
>> - GLint iparams[1] = {0}; /* XXX is one element enough? */
>> + GLint iparams[1] = {}; /* XXX is one element enough? */
>> _mesa_GetObjectParameterivARB(object, pname, iparams);
>> params[0] = (GLfloat) iparams[0];
>> }
>> @@ -1912,7 +1912,7 @@ shader_source(struct gl_context *ctx, GLuint
>> shaderObj, GLsizei count,
>> if (!sh)
>> return;
>>
>> - if (string == NULL) {
>> + if (!string) {
>> _mesa_error(ctx, GL_INVALID_VALUE, "glShaderSourceARB");
>> return;
>> }
>> @@ -1925,7 +1925,7 @@ shader_source(struct gl_context *ctx, GLuint
>> shaderObj, GLsizei count,
>> * last element will be set to the total length of the source code.
>> */
>> offsets = malloc(count * sizeof(GLint));
>> - if (offsets == NULL) {
>> + if (!offsets) {
>> _mesa_error(ctx, GL_OUT_OF_MEMORY, "glShaderSourceARB");
>> return;
>> }
>> @@ -1952,7 +1952,7 @@ shader_source(struct gl_context *ctx, GLuint
>> shaderObj, GLsizei count,
>> */
>> totalLength = offsets[count - 1] + 2;
>> source = malloc(totalLength * sizeof(GLcharARB));
>> - if (source == NULL) {
>> + if (!source) {
>> free((GLvoid *) offsets);
>> _mesa_error(ctx, GL_OUT_OF_MEMORY, "glShaderSourceARB");
>> return;
>> @@ -2245,7 +2245,7 @@ _mesa_GetProgramBinary(GLuint program, GLsizei
>> bufSize, GLsizei *length,
>> * Ensure that length always points to valid storage to avoid multiple
>> NULL
>> * pointer checks below.
>> */
>> - if (length == NULL)
>> + if (!length)
>> length = &length_dummy;
>>
>>
>> @@ -2263,7 +2263,7 @@ _mesa_GetProgramBinary(GLuint program, GLsizei
>> bufSize, GLsizei *length,
>> return;
>> }
>>
>> - if (ctx->Const.NumProgramBinaryFormats == 0) {
>> + if (!ctx->Const.NumProgramBinaryFormats) {
>> *length = 0;
>> _mesa_error(ctx, GL_INVALID_OPERATION,
>> "glGetProgramBinary(driver supports zero binary
>> formats)");
>> @@ -2858,7 +2858,7 @@ _mesa_UniformSubroutinesuiv(GLenum shadertype, GLsizei
>> count,
>> bool flushed = false;
>> do {
>> struct gl_uniform_storage *uni =
>> p->sh.SubroutineUniformRemapTable[i];
>> - if (uni == NULL) {
>> + if (!uni) {
>> i++;
>> continue;
>> }
>> @@ -3054,7 +3054,7 @@ _mesa_shader_write_subroutine_index(struct gl_context
>> *ctx,
>> {
>> int i, j;
>>
>> - if (p->sh.NumSubroutineUniformRemapTable == 0)
>> + if (!p->sh.NumSubroutineUniformRemapTable)
>> return;
>>
>> i = 0;
>>
_______________________________________________
mesa-dev mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/mesa-dev