]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
Use XOR for integers that are always 1 or 0 591/head
authorRose <83477269+AtariDreams@users.noreply.github.com>
Fri, 20 Jan 2023 18:23:45 +0000 (13:23 -0500)
committerRose <83477269+AtariDreams@users.noreply.github.com>
Sat, 13 May 2023 15:23:02 +0000 (11:23 -0400)
This is more efficient than using the ! operator on older platforms.

man/mantohtml.c
scheduler/cups-driverd.cxx
scheduler/cupsfilter.c
scheduler/job.c
scheduler/type.c

index c0c3ca44c1f8b850efd801c6bf553b141d625ff4..a46b70ea3a8a78dceea1e214c9e80653a3693a96 100644 (file)
@@ -989,7 +989,7 @@ html_alternate(const char *s,               /* I - String */
       link = 0;
     }
 
-    i = 1 - i;
+    i ^= 1;
 
    /*
     * Skip trailing whitespace...
index 4834fd37c86a33246f0133d5fb5a918ba728b317..ef45e92671f9039ef60a59dec3f46f659ee2c22a 100644 (file)
@@ -1978,7 +1978,6 @@ load_ppd(const char  *filename,           /* I - Real filename */
   cups_array_t *products,              /* Product array */
                *psversions,            /* PSVersion array */
                *cups_languages;        /* cupsLanguages array */
-  int          new_ppd;                /* Is this a new PPD? */
   struct                               /* LanguageVersion translation table */
   {
     const char *version,               /* LanguageVersion string */
@@ -2278,9 +2277,7 @@ load_ppd(const char  *filename,           /* I - Real filename */
   * Record the PPD file...
   */
 
-  new_ppd = !ppd;
-
-  if (new_ppd)
+  if (!ppd)
   {
    /*
     * Add new PPD file...
index 5107214e55043a61bf9016067111c7f7b9477561..dc9ba898a1ca70080340c942564ff9fa4c7225cf 100644 (file)
@@ -1169,19 +1169,16 @@ exec_filters(mime_type_t   *srctype,    /* I - Source type */
   * Execute all of the filters...
   */
 
-  pids            = cupsArrayNew((cups_array_func_t)compare_pids, NULL);
-  current         = 0;
-  filterfds[0][0] = -1;
+  pids            =  cupsArrayNew((cups_array_func_t)compare_pids, NULL);
+  current         =  1;
+  filterfds[0][0] =  infile ? -1 : 0;
   filterfds[0][1] = -1;
   filterfds[1][0] = -1;
   filterfds[1][1] = -1;
 
-  if (!infile)
-    filterfds[0][0] = 0;
-
   for (filter = (mime_filter_t *)cupsArrayFirst(filters);
        filter;
-       filter = next, current = 1 - current)
+       filter = next, current ^= 1)
   {
     next = (mime_filter_t *)cupsArrayNext(filters);
 
@@ -1191,31 +1188,30 @@ exec_filters(mime_type_t   *srctype,    /* I - Source type */
       snprintf(program, sizeof(program), "%s/filter/%s", ServerBin,
               filter->filter);
 
-    if (filterfds[!current][1] > 1)
+    if (filterfds[current][1] > 1)
     {
-      close(filterfds[1 - current][0]);
-      close(filterfds[1 - current][1]);
+      close(filterfds[current][0]);
+      close(filterfds[current][1]);
 
-      filterfds[1 - current][0] = -1;
-      filterfds[1 - current][1] = -1;
+      filterfds[current][0] = -1;
+      filterfds[current][1] = -1;
     }
 
     if (next)
-      open_pipe(filterfds[1 - current]);
+      open_pipe(filterfds[current]);
     else if (outfile)
     {
-      filterfds[1 - current][1] = open(outfile, O_CREAT | O_TRUNC | O_WRONLY,
-                                       0666);
+      filterfds[current][1] = open(outfile, O_CREAT | O_TRUNC | O_WRONLY, 0666);
 
-      if (filterfds[1 - current][1] < 0)
+      if (filterfds[current][1] < 0)
         fprintf(stderr, "ERROR: Unable to create \"%s\" - %s\n", outfile,
                strerror(errno));
     }
     else
-      filterfds[1 - current][1] = 1;
+      filterfds[current][1] = 1;
 
     pid = exec_filter(program, (char **)argv, (char **)envp,
-                      filterfds[current][0], filterfds[1 - current][1]);
+                      filterfds[current ^ 1][0], filterfds[current][1]);
 
     if (pid > 0)
     {
index 0659b2b85fc65166377244bf8c780574755f05a5..5ac782e7599d44aa7aed19174fd06a849a76c9f9 100644 (file)
@@ -1201,12 +1201,12 @@ cupsdContinueJob(cupsd_job_t *job)      /* I - Job */
       filterfds[slot][1] = job->print_pipes[1];
     }
 
-    pid = cupsdStartProcess(command, argv, envp, filterfds[!slot][0],
+    pid = cupsdStartProcess(command, argv, envp, filterfds[slot ^ 1][0],
                             filterfds[slot][1], job->status_pipes[1],
                            job->back_pipes[0], job->side_pipes[0], 0,
                            job->profile, job, job->filters + i);
 
-    cupsdClosePipe(filterfds[!slot]);
+    cupsdClosePipe(filterfds[slot ^ 1]);
 
     if (pid == 0)
     {
@@ -1228,7 +1228,7 @@ cupsdContinueJob(cupsd_job_t *job)        /* I - Job */
       argv[6] = NULL;
     }
 
-    slot = !slot;
+    slot ^= 1;
   }
 
   cupsArrayDelete(filters);
@@ -1262,7 +1262,7 @@ cupsdContinueJob(cupsd_job_t *job)        /* I - Job */
       filterfds[slot][0] = -1;
       filterfds[slot][1] = -1;
 
-      pid = cupsdStartProcess(command, argv, envp, filterfds[!slot][0],
+      pid = cupsdStartProcess(command, argv, envp, filterfds[slot ^ 1][0],
                              filterfds[slot][1], job->status_pipes[1],
                              job->back_pipes[1], job->side_pipes[1],
                              backroot, job->bprofile, job, &(job->backend));
@@ -1338,8 +1338,8 @@ cupsdContinueJob(cupsd_job_t *job)        /* I - Job */
   FilterLevel -= job->cost;
   job->cost = 0;
 
-  for (slot = 0; slot < 2; slot ++)
-    cupsdClosePipe(filterfds[slot]);
+  cupsdClosePipe(filterfds[0]);
+  cupsdClosePipe(filterfds[1]);
 
   cupsArrayDelete(filters);
 
index c6c531022bd16f66dece416c064a19b001007f8d..cd252c450d1619bf5d63922e158c45f98530a469 100644 (file)
@@ -1184,21 +1184,21 @@ mime_check_rules(
          * short then don't compare - it can't match...
          */
 
-         if ((rules->offset + rules->length) > (fb->offset + fb->length))
-         {
-           result = 0;
-         }
-         else
+         result = 0;
+         if ((rules->offset + rules->length) <= (fb->offset + fb->length))
          {
            if (fb->length > rules->region)
              region = rules->region - rules->length;
            else
              region = fb->length - rules->length;
 
-           for (n = 0; n < region; n ++)
-             if ((result = (memcmp(fb->buffer + rules->offset - fb->offset + n, rules->value.stringv, (size_t)rules->length) == 0)) != 0)
-               break;
-          }
+                 for (n = 0; n < region; n ++)
+             if (!memcmp(fb->buffer + rules->offset - fb->offset + n, rules->value.stringv, (size_t)rules->length))
+                   {
+                     result = 1;
+                     break;
+                   }
+         }
          break;
 
       default :