httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Christophe JAILLET" <christophe.jail...@wanadoo.fr>
Subject ideas about 'ap_rputs'
Date Mon, 30 May 2011 19:48:25 GMT
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




Mime
View raw message