[OPEN-ILS-DEV] buffer_chomp()

Scott McKellar mck9 at swbell.net
Mon Dec 1 23:30:50 EST 2008


The other day I noticed the new buffer_chomp function.  It removes the
last character of a growing_buffer, and returns the new length.

(I suppose it's too late to rename this struct a shrinking_buffer.)

I propose that instead of returning the new length, the function return
the character removed.  Since buffer_chomp() is used in only one place,
where we ignore the return value, such a change would not affect any
other existing code.

The new length of the buffer string is already available by other means.
The calling code can inspect the n_used member directly.  If we don't 
like that approach because it violates encapsulation, we can provide a 
function or macro that returns the value of n_used.

The lost last character, on the other hand, is not currently available
by any means, once buffer_chomp() is finished.  There's no guarantee
that it will ever be useful, but we aren't using the current return
value either.

In fact several growing buffer functions return the value of n_used,
which we seldom or never pay any attention to.  Returning an unused
return value exacts a performance penalty -- admittedly a minor one,
but we use these functions extensively.  If we provide a buffer_length
function or macro, we can eventually turn some of the other buffer 
functions into slightly sleeker void functions.

I can incorporate these two changes into my next patch to utils.[ch] --
which will probably be soon, because I want to get rid of the new
buffer_append_uescape function in favor of the newer function 
buffer_append_utf8().

Scott McKellar
http://home.swbell.net/mck9/ct/



More information about the Open-ils-dev mailing list