Re: [PATCH] branch: reset instead of release a strbuf
From: Junio C Hamano <hidden>
Date: 2017-10-04 02:19:40
Jeff King [off-list ref] writes:
quoted
/** * Release a string buffer and the memory it used. You should not use the - * string buffer after using this function, unless you initialize it again. + * string buffer after using this function. */ extern void strbuf_release(struct strbuf *);I think it's actually OK to use the string buffer after this function. It's just an empty string. Perhaps we should be more explicit: this releases any resources and resets to a pristine, empty state. I suspect strbuf_detach() probably should make the same claim. Earlier you mentioned:quoted
It is still not advisable to call strbuf_release until done using a strbuf because it is wasteful, so keep that part of the advice.Is this what you meant? If so, I think we should probably be more explicit in giving people a hint to use strbuf_reset() for efficiency.
Yes, "should not use" above is simply misleading. Either drop it altogether, or say something like If you find yourself reusing the same strbuf in a loop and calling strbuf_release() each iteration, you may want to consider if it makes more sense to use strbuf_reset() instead in each iteration and calling strbuf_release() at the end. perhaps.