Use the ARRAY_LENGTH() macro when possible
authorAndrea Canciani <ranma42@gmail.com>
Thu, 3 Nov 2011 09:51:27 +0000 (10:51 +0100)
committerAndrea Canciani <ranma42@gmail.com>
Wed, 9 Nov 2011 08:17:00 +0000 (09:17 +0100)
This patch has been generated by the following Coccinelle semantic patch:

// Use the ARRAY_LENGTH() macro when possible
//
// Replace open-coded array length computations with the
// ARRAY_LENGTH() macro

@@
type T;
T[] E;
@@
- (sizeof(E)/sizeof(T))
+ ARRAY_LENGTH (E)

test/blitters-test.c
test/fetch-test.c
test/gradient-crash-test.c
test/lowlevel-blt-bench.c
test/oob-test.c
test/trap-crasher.c

index 6355632..55b6c73 100644 (file)
@@ -280,7 +280,7 @@ test_composite (int testnum, int verbose)
 
     lcg_srand (testnum);
 
-    op = op_list[lcg_rand_n (sizeof (op_list) / sizeof (op_list[0]))];
+    op = op_list[lcg_rand_n (ARRAY_LENGTH (op_list))];
 
     if (lcg_rand_n (8))
     {
index fa79ad7..04e8cc5 100644 (file)
@@ -103,7 +103,7 @@ static testcase_t testcases[] =
     },
 };
 
-int n_test_cases = sizeof(testcases)/sizeof(testcases[0]);
+int n_test_cases = ARRAY_LENGTH (testcases);
 
 
 static uint32_t
index c85712d..73e5bbc 100644 (file)
@@ -106,17 +106,17 @@ main (int argc, char **argv)
        if (i == 0)
        {
            stops = onestop;
-           num_stops = sizeof(onestop) / sizeof(onestop[0]);
+           num_stops = ARRAY_LENGTH (onestop);
        }
        else if (i == 1)
        {
            stops = subsetstops;
-           num_stops = sizeof(subsetstops) / sizeof(subsetstops[0]);
+           num_stops = ARRAY_LENGTH (subsetstops);
        }
        else
        {
            stops = stops01;
-           num_stops = sizeof(stops01) / sizeof(stops01[0]);
+           num_stops = ARRAY_LENGTH (stops01);
        }
        
        for (j = 0; j < 3; ++j)
index 67cd939..ba7f307 100644 (file)
@@ -703,7 +703,7 @@ main (int argc, char *argv[])
             x / 1000000., x / 4000000);
     printf ("---\n");
 
-    for (i = 0; i < sizeof(tests_tbl) / sizeof(tests_tbl[0]); i++)
+    for (i = 0; i < ARRAY_LENGTH (tests_tbl); i++)
     {
        if (strcmp (pattern, "all") == 0 || strstr (tests_tbl[i].testname, pattern))
        {
index 9c1a25d..0d19b50 100644 (file)
@@ -94,7 +94,7 @@ main (int argc, char **argv)
 {
     int i;
 
-    for (i = 0; i < sizeof (info) / sizeof (info[0]); ++i)
+    for (i = 0; i < ARRAY_LENGTH (info); ++i)
        test_composite (&info[i]);
     
     return 0;
index db7e01a..4e4cac2 100644 (file)
@@ -22,6 +22,6 @@ main()
 
     dst = pixman_image_create_bits (PIXMAN_a8, 1, 1, NULL, -1);
 
-    pixman_add_trapezoids (dst, 0, 0, sizeof (traps)/sizeof (traps[0]), traps);
+    pixman_add_trapezoids (dst, 0, 0, ARRAY_LENGTH (traps), traps);
     return (0);
 }