Thread (12 messages) 12 messages, 3 authors, 2016-06-15

Re: [PATCH/RFC v1 0/5] add strbuf_set operations

From: Duy Nguyen <hidden>
Date: 2016-06-15 23:01:32

On Mon, Jun 9, 2014 at 3:36 PM, Jeremiah Mahler [off-list ref] wrote:
Currently, the data in a strbuf is modified using add operations.  To
set the buffer to some data a reset must be performed before an add.

  strbuf_reset(buf);
  strbuf_add(buf, cb.buf.buf, cb.buf.len);

And this is a common sequence of operations with 70 occurrences found in
the current source code.  This includes all the different variations
(add, addf, addstr, addbuf, addch).

  FILES=`find ./ -name '*.c'`
  CNT=$(pcregrep -M "strbuf_reset.*\n.*strbuf_add" $FILES | wc -l)
Hmm.. I wonder if git-grep could do this.. There's pcre support but I
never tried.
  CNT=$(echo "$CNT / 2" | bc)
  echo $CNT
  70
The change in this series looks nice. There's another pattern, save
strbuf length, then strbuf_setlen() at the beginning or the end of a
loop. But I think it's less often.
-- 
Duy
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help