[microproject idea]
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Mar 4, 2014, 21:11 UTC
- Message-ID
- <xmqq4n3dk6te.fsf@gitster.dls.corp.google.com>
- In-Reply-To
- <1393921868-4382-1-git-send-email-mhagger@alum.mit.edu>
Find places where we scan a string twice unnecessarily, once with strchr() and then with strlen(), e.g.
const char *colon = strchr(name, ':'); int namelen = colon ? colon - name : strlen(name);
and rewrite such a pattern using strchrnul() as appropriate.
The above example can become
const char *colon = strchrnul(name, ':');
int namelen = colon - name;