ast_frdup optimization: only call strlen once and save the result