<URL: http://bugs.freeciv.org/Ticket/Display.html?id=40013 >

Madeline Book wrote:
> ... would it
> not seem terribly inefficient to have to find the end of the string
> on every single call to a cat/CAT* function? 

Briefly, no.

1) I'm not the original designer of this code, I'm just fixing crashing bugs
    at the moment....  Spending most of 1 day just fixing this in place line
    by line was much more efficient than spending 3+ days redesigning it.
    There are plans to move more of the data into rulesets someday, at which
    time redesign might be fruitful.

2) Finding the end of a string is pretty fast, vastly faster than the
    *printf() formatting.  If it weren't for the odd translation problems,
    I'd probably have used cat_snprintf() for everything!  But strlcat() is
    better where there's no c-format, as it avoids/fixes escaping issues.

3) These functions are called by the client in response to a user bringing
    up the help dialog, something that is done rarely -- and the client has
    time to dance a tarantella between every user click.  Speed is not an
    issue here!

> Why not just make a dynamic buffer type, and do any with all this
> gigantic static buffer nonsense? E.g.
4) memory allocation, reallocation, and deallocation are fairly slow,
    especially compared to strlen(), strlcat(), etc.  Also leads to memory
    fragmentation, and heap recovery is exceptionally slow!  On long games,
    we've seen huge swap space and perceptible delays.  Some of that is due
    to memory leaks, many fixed in 2.2 -- but stack buffers don't suffer
    from memory fragmentation or leaks!

5) The functions you desire are already defined in utility/astring.[ch]

6) Generally, I've been ripping out astr_* rather than adding more....

Freeciv-dev mailing list

Reply via email to