From: Rose <83477269+AtariDreams@users.noreply.github.com> Date: Fri, 20 Jan 2023 18:23:45 +0000 (-0500) Subject: Use XOR for integers that are always 1 or 0 X-Git-Tag: v2.4.3~18^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5aa90ce57470d22845389de1e2f00d56876f0ce8;p=thirdparty%2Fcups.git Use XOR for integers that are always 1 or 0 This is more efficient than using the ! operator on older platforms. --- diff --git a/man/mantohtml.c b/man/mantohtml.c index c0c3ca44c1..a46b70ea3a 100644 --- a/man/mantohtml.c +++ b/man/mantohtml.c @@ -989,7 +989,7 @@ html_alternate(const char *s, /* I - String */ link = 0; } - i = 1 - i; + i ^= 1; /* * Skip trailing whitespace... diff --git a/scheduler/cups-driverd.cxx b/scheduler/cups-driverd.cxx index 4834fd37c8..ef45e92671 100644 --- a/scheduler/cups-driverd.cxx +++ b/scheduler/cups-driverd.cxx @@ -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... diff --git a/scheduler/cupsfilter.c b/scheduler/cupsfilter.c index 5107214e55..dc9ba898a1 100644 --- a/scheduler/cupsfilter.c +++ b/scheduler/cupsfilter.c @@ -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) { diff --git a/scheduler/job.c b/scheduler/job.c index 0659b2b85f..5ac782e759 100644 --- a/scheduler/job.c +++ b/scheduler/job.c @@ -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); diff --git a/scheduler/type.c b/scheduler/type.c index c6c531022b..cd252c450d 100644 --- a/scheduler/type.c +++ b/scheduler/type.c @@ -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 :