From: Mathias Fröhlich <mathias.froehl...@web.de> Replaces an iterate and test bit in a bitmask loop by a loop only iterating over the bits set in the bitmask.
v2: Use _mesa_bit_scan{,64} instead of open coding. Reviewed-by: Brian Paul <bri...@vmware.com> Signed-off-by: Mathias Fröhlich <mathias.froehl...@web.de> --- src/mesa/main/light.c | 11 ++++++----- src/mesa/tnl/t_vb_light.c | 10 ++++++---- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/mesa/main/light.c b/src/mesa/main/light.c index ae723e8..004449b 100644 --- a/src/mesa/main/light.c +++ b/src/mesa/main/light.c @@ -705,13 +705,14 @@ _mesa_update_material( struct gl_context *ctx, GLuint bitmask ) void _mesa_update_color_material( struct gl_context *ctx, const GLfloat color[4] ) { - const GLbitfield bitmask = ctx->Light._ColorMaterialBitmask; + GLbitfield bitmask = ctx->Light._ColorMaterialBitmask; struct gl_material *mat = &ctx->Light.Material; - int i; - for (i = 0 ; i < MAT_ATTRIB_MAX ; i++) - if (bitmask & (1<<i)) - COPY_4FV( mat->Attrib[i], color ); + while (bitmask) { + const int i = _mesa_bit_scan(&bitmask); + + COPY_4FV( mat->Attrib[i], color ); + } _mesa_update_material( ctx, bitmask ); } diff --git a/src/mesa/tnl/t_vb_light.c b/src/mesa/tnl/t_vb_light.c index 67daddd..55f2f6d 100644 --- a/src/mesa/tnl/t_vb_light.c +++ b/src/mesa/tnl/t_vb_light.c @@ -231,10 +231,12 @@ prepare_materials(struct gl_context *ctx, * with the color pointer for each one. */ if (ctx->Light.ColorMaterialEnabled) { - const GLuint bitmask = ctx->Light._ColorMaterialBitmask; - for (i = 0 ; i < MAT_ATTRIB_MAX ; i++) - if (bitmask & (1<<i)) - VB->AttribPtr[_TNL_ATTRIB_MAT_FRONT_AMBIENT + i] = VB->AttribPtr[_TNL_ATTRIB_COLOR0]; + GLbitfield bitmask = ctx->Light._ColorMaterialBitmask; + while (bitmask) { + const int i = _mesa_bit_scan(&bitmask); + VB->AttribPtr[_TNL_ATTRIB_MAT_FRONT_AMBIENT + i] = + VB->AttribPtr[_TNL_ATTRIB_COLOR0]; + } } /* Now, for each material attribute that's tracking vertex color, save -- 2.5.5 _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev