From 3dd9e12b515dea2c8a14b33c762807bb54625aef Mon Sep 17 00:00:00 2001 From: Ashwin Maroli Date: Thu, 10 Sep 2020 23:28:35 +0530 Subject: [PATCH] [ruby/fileutils] Reduce iteration through list for `:mkdir_p` By calling the instruction to `list.map` within `list.each` itself. https://github.com/ruby/fileutils/commit/e690eec937 --- lib/fileutils.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/fileutils.rb b/lib/fileutils.rb index c8f4b49067..179d764fde 100644 --- a/lib/fileutils.rb +++ b/lib/fileutils.rb @@ -208,7 +208,9 @@ module FileUtils fu_output_message "mkdir -p #{mode ? ('-m %03o ' % mode) : ''}#{list.join ' '}" if verbose return *list if noop - list.map {|path| remove_trailing_slash(path)}.each do |path| + list.each do |item| + path = remove_trailing_slash(item) + # optimize for the most common case begin fu_mkdir path, mode