According to Mark Mitchell, strchr(p,'\0') is more efficient than p+strlen(p).
#include <string.h> void * f (char *p) { return p + strlen (p); } void * g (char *p) { return strchr (p, '\0'); } g: xorl %esi, %esi jmp __rawmemchr f: pushq %rbx movq %rdi, %rbx call strlen leaq (%rbx,%rax), %rax popq %rbx ret -- Summary: Convert p+strlen(p) to strchr(p, '\0') if profitable Product: gcc Version: 4.3.0 Status: UNCONFIRMED Keywords: missed-optimization Severity: enhancement Priority: P3 Component: tree-optimization AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: kazu at gcc dot gnu dot org http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32650