The first strlen() call required that the searchName is iterated entirely, even if the following strncmp() would be able to early-out when the first characters don't match.
The pre-calculated length is only used to constrain the string comparison, but strcmp() will handle the ends of both strings just fine, and early-out as soon as possible.
The second call to strlen() was to ensure that searchName didn't just match a prefix of a longer currentName. strcmp() also accounts for this, but will early-out if the string is a single character longer, without having to walk the entire currentName.
The first
strlen()
call required that thesearchName
is iterated entirely, even if the followingstrncmp()
would be able to early-out when the first characters don't match.The pre-calculated length is only used to constrain the string comparison, but
strcmp()
will handle the ends of both strings just fine, and early-out as soon as possible.The second call to
strlen()
was to ensure thatsearchName
didn't just match a prefix of a longercurrentName
.strcmp()
also accounts for this, but will early-out if the string is a single character longer, without having to walk the entirecurrentName
.