httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dean Gaudet <>
Subject Re: "locale" project
Date Fri, 19 Dec 1997 20:17:28 GMT
On Fri, 19 Dec 1997, [KOI8-R] áÎÄÒÅÊ þÅÒÎÏ× wrote:

> On Fri, 19 Dec 1997, Dean Gaudet wrote:
> > move this way as well... and as we replace string and alloc functions we
> > venture further and further away from libc.
> Just two examples from FreeBSD libc:
> string functions are mostly in assembler and malloc functions effecttively
> talk to kernel VM system to give more optimization and returning memory
> back to VM. All this features will lost with re-implementing :-(
> Ok, ok, I keep silence...

Ah, but writing strcpy and strcat in assembler does not necessary lead to
improved performance.  Consider this (assume there's no buffer overflows):

    void the_libc_way(char *d, char *s1, char *s2)
	strcpy(d, s1);
	strcat(d, s2);

    /* here's a function that I found in Lattice C for the Amiga libc,
     * it's strcpy, but returns a pointer to the NUL-terminator of d,
     * which is about 2000 times more useful than returning d.
    char *stpcpy(char *d, const char *s)
	while((*d = *s)) {
	return d;

    void a_faster_way(char *d, char *s1, char *s2)
	strcpy(stpcpy(d, s1), s2);

The first does 2*|s1|+|s2| work, the second does |s1|+|s2| work.

i.e. optimizing libc isn't going to make the lame code that's written to
use libc go faster.  You can find similar lame examples using strncpy,
and strncat.  Another case that causes extreme lameness is the \0
terminated string itself -- which forces you to make duplicates of
things just so that you can get a token which is \0-terminated to pass
to another routine.  If strings were struct { char *p; size_t len }
this copying wouldn't have to happen.

BTW we still use malloc(), we just wrap it in a bunch of our own stuff.  We
don't ever free() though.


View raw message