Perf tweaks

Uses 20% less CPU on my tests:
  avoid redundant strlen() calls