FVWM: ARGH!

From: Peter Seebach <seebs_at_intran.xerox.com>
Date: Tue, 31 Dec 1996 12:04:22 PST

No offense folks, but this is utterly insane:

>int mystrcasecmp(char *s1,char *s2)
>{
> int c1,c2;
> int n,n2;
>
> n=strlen(s1);
> n2=strlen(s2);
> if(n!=n2)
> return 1;

Oh, I see, so we don't preserve the >=< --> -1,0,1 semantics of strcmp,
we just return 0/non-zero.

> for (;;)
> {
> c1 = *s1;
> c2 = *s2;
> if (!c1 || !c2)
> return(c1 - c2);
> if (isupper(c1))
> c1 = 'a' - 1 + (c1 & 31);

What nonsense is this?
        c1 = tolower(c1);
is almost certainly faster, and certainly less ASCII-dependant, and more
readable.

> if (isupper(c2))
> c2 = 'a' - 1 + (c2 & 31);
> if (c1 != c2)
> return(c1 - c2);
> n--,s1++,s2++;

Why bother? This is absolutely no different from
        --n;
        ++s1;
        ++s2;

and, given the context, why on earth aren't these the body of the for loop?

Perhaps something more like
        while (*s1 && tolower(*s1) == tolower(*s2)) {
                ++s1;
                ++s2;
        }
        if (*tolower(s1) < *tolower(s2))
                return -1;
        if (*tolower(s2) > *tolower(s2))
                return 1;
        return 0;

would have worked?

I'm sorry, I'm just easily offended by gratuitous cruft, and I seem to
recall that this function turned out not to work with some set of compiler
options last time I tried to build fvwm-2.x.

As a general rule, you may safely assume that the <ctype.h> macros and
functions will be using fast lookup tables, and you will not be able
to outperform them without significant effort; unless the usage is inside
a *very* time-critical, heavily-used, routine, it is pretty much guaranteed
you cannot justify the time spent trying to beat them, least of all using
strange macros based on ASCII values.

Among other things, the '&31' is completely superfluous if you've already
guaranteed that the letter is uppercase; you can just use "c1 - 'A' + 'a'"
on ASCII machines, and gee, it's *still* slower than tolower.

While I'm griping, fvwm.c declares main incorrectly; main has returned an
int in C since 1972, and I can assure you, we on the committee have no
intent of changing this. Compilers are free to reject declarations of
main with any other return type, and are encouraged to do so.

(It is a very nice window manager, I just don't think the code is as clean
as it should be.)

-s
--
Visit the official FVWM web page at <URL:http://www.hpc.uh.edu/fvwm/>.
To unsubscribe from the list, send "unsubscribe fvwm" in the body of a
message to majordomo_at_hpc.uh.edu.
To report problems, send mail to fvwm-owner_at_hpc.uh.edu.
Received on Tue Dec 31 1996 - 14:00:54 GMT

This archive was generated by hypermail 2.3.0 : Mon Aug 29 2016 - 19:37:59 BST