mesa: use ffs() to shorten loop in _mesa_drawbuffers()
authorBrian Paul <brianp@vmware.com>
Mon, 2 Nov 2009 20:20:19 +0000 (13:20 -0700)
committerBrian Paul <brianp@vmware.com>
Tue, 3 Nov 2009 16:52:25 +0000 (09:52 -0700)
src/mesa/main/buffers.c

index b5acda8823c972f71a43ab9a45ab27f78e20ed7d..cdd16a8ad1dc0c4024cdaee6dffe5c667cacca60 100644 (file)
@@ -375,15 +375,19 @@ _mesa_drawbuffers(GLcontext *ctx, GLuint n, const GLenum *buffers,
       destMask = mask;
    }
 
+   /*
+    * If n==1, destMask[0] may have up to four bits set.
+    * Otherwise, destMask[x] can only have one bit set.
+    */
    if (n == 1) {
-      GLuint buf, count = 0;
+      GLuint count = 0, destMask0 = destMask[0];
       /* init to -1 to help catch errors */
       fb->_ColorDrawBufferIndexes[0] = -1;
-      for (buf = 0; buf < BUFFER_COUNT; buf++) {
-         if (destMask[0] & (1 << buf)) {
-            fb->_ColorDrawBufferIndexes[count] = buf;
-            count++;
-         }
+      while (destMask0) {
+         GLint bufIndex = _mesa_ffs(destMask0) - 1;
+         fb->_ColorDrawBufferIndexes[count] = bufIndex;
+         count++;
+         destMask0 &= ~(1 << bufIndex);
       }
       fb->ColorDrawBuffer[0] = buffers[0];
       fb->_NumColorDrawBuffers = count;