[PATCH 2/4] tools: move out of loop strlen for better codegeneration by compiler and refactor