perf(lua/name): improve to_name_ext performance

Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
perf(lua/name): improve to_name_ext performance