From 439e23e6d15df248157c668a4f96a3028ec42195 Mon Sep 17 00:00:00 2001 From: Tim Smith Date: Fri, 31 Jul 2020 15:22:30 -0700 Subject: [PATCH] Use require_relative instead of require to speed up requires (#175) require_relative is faster as it doesn't require traversing the filesystem looking for the require. See benchmarks here: https://github.com/rspec/rspec-expectations/pull/476#issuecomment-35848905 Signed-off-by: Tim Smith --- .gitignore | 1 + lib/rbvmomi.rb | 8 ++++---- lib/rbvmomi/connection.rb | 10 +++++----- lib/rbvmomi/pbm.rb | 2 +- lib/rbvmomi/sms.rb | 2 +- lib/rbvmomi/utils/deploy.rb | 2 +- 6 files changed, 13 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index 17bd17f7..ad50f828 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ Gemfile.lock /pkg/ /vendor/bundle/ /vmodl/ +*.gem diff --git a/lib/rbvmomi.rb b/lib/rbvmomi.rb index f78ab04d..ec0ef2ec 100644 --- a/lib/rbvmomi.rb +++ b/lib/rbvmomi.rb @@ -10,7 +10,7 @@ def self.connect(opts) end end -require 'rbvmomi/connection' -require 'rbvmomi/sso' -require 'rbvmomi/version' -require 'rbvmomi/vim' +require_relative 'rbvmomi/connection' +require_relative 'rbvmomi/sso' +require_relative 'rbvmomi/version' +require_relative 'rbvmomi/vim' diff --git a/lib/rbvmomi/connection.rb b/lib/rbvmomi/connection.rb index 30d6d8fb..56c6a915 100644 --- a/lib/rbvmomi/connection.rb +++ b/lib/rbvmomi/connection.rb @@ -3,11 +3,11 @@ require 'time' require 'date' -require 'rbvmomi/trivial_soap' -require 'rbvmomi/basic_types' -require 'rbvmomi/fault' -require 'rbvmomi/type_loader' -require 'rbvmomi/deserialization' +require_relative 'trivial_soap' +require_relative 'basic_types' +require_relative 'fault' +require_relative 'type_loader' +require_relative 'deserialization' module RbVmomi diff --git a/lib/rbvmomi/pbm.rb b/lib/rbvmomi/pbm.rb index 71002c3e..2b777e18 100644 --- a/lib/rbvmomi/pbm.rb +++ b/lib/rbvmomi/pbm.rb @@ -1,7 +1,7 @@ # Copyright (c) 2012-2017 VMware, Inc. All Rights Reserved. # SPDX-License-Identifier: MIT -require 'rbvmomi' +require_relative '../rbvmomi' module RbVmomi diff --git a/lib/rbvmomi/sms.rb b/lib/rbvmomi/sms.rb index 8c468587..2378f819 100644 --- a/lib/rbvmomi/sms.rb +++ b/lib/rbvmomi/sms.rb @@ -1,7 +1,7 @@ # Copyright (c) 2013-2017 VMware, Inc. All Rights Reserved. # SPDX-License-Identifier: MIT -require 'rbvmomi' +require_relative '../rbvmomi' module RbVmomi # A connection to one vSphere SMS endpoint. diff --git a/lib/rbvmomi/utils/deploy.rb b/lib/rbvmomi/utils/deploy.rb index 61c66343..1975714b 100644 --- a/lib/rbvmomi/utils/deploy.rb +++ b/lib/rbvmomi/utils/deploy.rb @@ -3,7 +3,7 @@ require 'open-uri' require 'nokogiri' -require 'rbvmomi' +require_relative '../../rbvmomi' # The cached ovf deployer is an optimization on top of regular OVF deployment # as it is offered by the VIM::OVFManager. Creating a VM becomes a multi-stage