Optimized implementation for strlen