Skip to content
  • Gábor Szeder's avatar
    strbuf.cocci: suggest strbuf_addbuf() to add one strbuf to an other · 28c23cd4
    Gábor Szeder authored and Junio C Hamano's avatar Junio C Hamano committed
    
    
    The best way to add one strbuf to an other is via:
    
      strbuf_addbuf(&sb, &sb2);
    
    This is a bit more idiomatic and efficient than:
    
      strbuf_addstr(&sb, sb2.buf);
    
    because the size of the second strbuf is known and thus it can spare a
    strlen() call, and much more so than:
    
      strbuf_addf(&sb, "%s", sb2.buf);
    
    because it can spare the whole vsnprintf() formatting magic.
    
    Add new semantic patches to 'contrib/coccinelle/strbuf.cocci' to catch
    these undesired patterns and to suggest strbuf_addbuf() instead.
    
    Luckily, our codebase is already clean from any such undesired
    patterns (but one of the in-flight topics just tried to sneak in such
    a strbuf_addf() call).
    
    Signed-off-by: default avatarSZEDER Gábor <szeder.dev@gmail.com>
    Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
    28c23cd4