kwo pushed a commit to branch master.

http://git.enlightenment.org/legacy/imlib2.git/commit/?id=4f3da0de038b97d6956390817b81c79f564449e2

commit 4f3da0de038b97d6956390817b81c79f564449e2
Author: Kim Woelders <k...@woelders.dk>
Date:   Sat Apr 10 03:46:27 2021 +0200

    Cleanups: while->for loops (context list)
---
 src/lib/context.c | 63 +++++++++++++++++++++++++------------------------------
 1 file changed, 29 insertions(+), 34 deletions(-)

diff --git a/src/lib/context.c b/src/lib/context.c
index 6c4f4e1..63deb42 100644
--- a/src/lib/context.c
+++ b/src/lib/context.c
@@ -26,73 +26,68 @@ __imlib_GetMaxContexts(void)
 void
 __imlib_FlushContexts(void)
 {
-   Context            *ct, *pct, *ctt;
+   Context            *ct, *ct_prev, *ct_next;
 
-   ct = context;
-   pct = NULL;
-   while (ct)
+   for (ct = context, ct_prev = NULL; ct; ct = ct_next)
      {
-        ctt = ct;
-        ct = ct->next;
+        ct_next = ct->next;
+
         /* it hasn't been referenced in the last max_context_count references 
*/
         /* thus old and getrid of it */
-        if (ctt->last_use < (context_counter - max_context_count))
+        if (ct->last_use < (context_counter - max_context_count))
           {
-             if (pct)
-                pct->next = ctt->next;
+             if (ct_prev)
+                ct_prev->next = ct->next;
              else
-                context = ctt->next;
-
-             if (ctt->palette)
+                context = ct->next;
+             if (ct->palette)
                {
                   int                 i, num[] = { 256, 128, 64, 32, 16, 8, 1 
};
                   unsigned long       pixels[256];
 
-                  for (i = 0; i < num[ctt->palette_type]; i++)
-                     pixels[i] = (unsigned long)ctt->palette[i];
-                  XFreeColors(ctt->display, ctt->colormap, pixels,
-                              num[ctt->palette_type], 0);
+                  for (i = 0; i < num[ct->palette_type]; i++)
+                     pixels[i] = (unsigned long)ct->palette[i];
+                  XFreeColors(ct->display, ct->colormap, pixels,
+                              num[ct->palette_type], 0);
 
-                  free(ctt->palette);
-                  free(ctt->r_dither);
-                  free(ctt->g_dither);
-                  free(ctt->b_dither);
+                  free(ct->palette);
+                  free(ct->r_dither);
+                  free(ct->g_dither);
+                  free(ct->b_dither);
                }
-             else if (ctt->r_dither)
+             else if (ct->r_dither)
                {
-                  free(ctt->r_dither);
-                  free(ctt->g_dither);
-                  free(ctt->b_dither);
+                  free(ct->r_dither);
+                  free(ct->g_dither);
+                  free(ct->b_dither);
                }
-             free(ctt);
+             free(ct);
           }
         else
-           pct = ctt;
+          {
+             ct_prev = ct;
+          }
      }
 }
 
 Context            *
 __imlib_FindContext(Display * d, Visual * v, Colormap c, int depth)
 {
-   Context            *ct, *pct;
+   Context            *ct, *ct_prev;
 
-   pct = NULL;
-   ct = context;
-   while (ct)
+   for (ct = context, ct_prev = NULL; ct; ct_prev = ct, ct = ct->next)
      {
         if ((ct->display == d) && (ct->visual == v) &&
             (ct->colormap == c) && (ct->depth == depth))
           {
-             if (pct)
+             if (ct_prev)
                {
-                  pct->next = ct->next;
+                  ct_prev->next = ct->next;
                   ct->next = context;
                   context = ct;
                }
              return ct;
           }
-        pct = ct;
-        ct = ct->next;
      }
    return NULL;
 }

-- 


Reply via email to