summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith84@gmail.com>2020-08-12 14:15:48 -0700
committerTim Smith <tsmith84@gmail.com>2020-08-12 14:15:48 -0700
commit0b79eabe7f4f5f841dd0503d899a6bd84c40c795 (patch)
tree4ee2d21722ec7f38d35abaf67bde3db2eb507a89
parentf0eb5fad78a63a1a57aed6f5c879f6f5fb59dd22 (diff)
downloadmixlib-shellout-requires.tar.gz
Optimize requires for non-omnibus installsrequires
require is quite slow in Ruby and doing requires for things you've already required is also slow. We've used this simple hack in Chef to speed up our requires. In the omnibus installs we patch how rubygems works to make this somewhat pointless, but this will help non-omnibus installs Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r--lib/mixlib/shellout.rb4
-rw-r--r--lib/mixlib/shellout/helper.rb2
2 files changed, 3 insertions, 3 deletions
diff --git a/lib/mixlib/shellout.rb b/lib/mixlib/shellout.rb
index 2b998ab..dc186a2 100644
--- a/lib/mixlib/shellout.rb
+++ b/lib/mixlib/shellout.rb
@@ -16,8 +16,8 @@
# limitations under the License.
#
-require "etc"
-require "tmpdir"
+require "etc" unless defined?(Etc)
+require "tmpdir" unless defined?(Dir.mktmpdir)
require "fcntl"
require_relative "shellout/exceptions"
diff --git a/lib/mixlib/shellout/helper.rb b/lib/mixlib/shellout/helper.rb
index ac63494..4543cf1 100644
--- a/lib/mixlib/shellout/helper.rb
+++ b/lib/mixlib/shellout/helper.rb
@@ -16,7 +16,7 @@
# limitations under the License.
require_relative "../shellout"
-require "chef-utils"
+require "chef-utils" unless defined?(ChefUtils)
require "chef-utils/dsl/default_paths"
require "chef-utils/internal"