You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Christophe JAILLET <ch...@wanadoo.fr> on 2011/05/30 21:48:25 UTC

ideas about 'ap_rputs'

Hi all,

several places in the source code of httpd have lines like these ones :

>>>>>>>>>>>>>>>>>>>>> (exemple taken from \modules\ssl\ssl_scache.c)
    ap_rputs("<hr>\n", r);
    ap_rputs("<table cellspacing=0 cellpadding=0>\n", r);
    ap_rputs("<tr><td bgcolor=\"#000000\">\n", r);
    ap_rputs("<b><font color=\"#ffffff\" face=\"Arial,Helvetica\">SSL/TLS
Session Cache Status:</font></b>\r", r);
    ...
>>>>>>>>>>>>>>>>>>>>>

This could, IMO be improved in 2 ways.
I would like to have feedback in order to know if patches to implement
theses ideas are interesting and should be proposed.
If yes, I can prepare a set of patches.



First, the whole could be behave the same with only one call to ap_rputs :
>>>>>>>>>>>>>>>>>>>>>
    ap_rputs("<hr>\n"
                  "<table cellspacing=0 cellpadding=0>\n"
                  "<tr><td bgcolor=\"#000000\">\n"
                  "<b><font color=\"#ffffff\"
face=\"Arial,Helvetica\">SSL/TLS Session Cache Status:</font></b>\r", r);
    ...
>>>>>>>>>>>>>>>>>>>>>
This way of doing things is also widely used in the code. It is still very
readable and should run faster.


Second, most of the time, 'ap_rputs' is called with a constant string as
argument (as in the exmaple above). 'ap_rputs' then computes the length of
the string using 'strlen' and then goes further in the processing.
Compilers (at least GCC) knows how to compute constant strings length at
compile time and avoid useless calls to 'strlen'. So, most of the time
letting the compiler compute the length at compile time would be a win.

This could be done easily by turning the function
   AP_DECLARE(int) ap_rputs(const char *str, request_rec *r)
into a macro that would look like :
   #define ap_rputs(a, b)     do { ap_rwrite((a), strlen(a), (b)) } while
(0);

I know that function are preferred to macro and that names of macro should
be in uppercase by convention, but please give me a feed back if you think
it could be a win.


Best regards,

Christophe Jaillet




Re: ideas about 'ap_rputs'

Posted by Stefan Fritsch <sf...@sfritsch.de>.
On Monday 30 May 2011, Ondřej Surý wrote:
> > I know that function are preferred to macro and that names of
> > macro should be in uppercase by convention, but please give me a
> > feed back if you think it could be a win.
> 
> Have you checked the generated code? It could be the case that the
> compiler is smart enough to optimize the code even without your
> hints...

I can't imagine how that could work, with ap_rputs being a non-inlined 
"extern" function.

I think both optimizations are valid, though I doubt that the 
difference would be measurable in practice.

Re: ideas about 'ap_rputs'

Posted by Ondřej Surý <on...@sury.org>.
> I know that function are preferred to macro and that names of macro should
> be in uppercase by convention, but please give me a feed back if you think
> it could be a win.

Have you checked the generated code? It could be the case that the compiler is smart enough to optimize the code even without your hints...

O.