Iterate over strings only once.

Previous implementation performed `strlen` twice and `strcmp` once. Each
operation is `O(n)` for a total of `O(3*n)`. Instead, use pointer arithmetic
to compare each character in turn, for a total of `O(n)`.