From 9c20d1aaa25fc4058c337f5e8ceb3755839f49b2 Mon Sep 17 00:00:00 2001 From: Tim Smith Date: Fri, 14 Aug 2020 13:35:23 -0700 Subject: Optimize our requires Only require once since Rubygems is painfully slow at doing no-op requires. Signed-off-by: Tim Smith --- lib/ffi_yajl/benchmark/encode.rb | 8 ++++---- lib/ffi_yajl/benchmark/encode_json_and_marshal.rb | 8 ++++---- lib/ffi_yajl/benchmark/encode_json_and_yaml.rb | 8 ++++---- lib/ffi_yajl/benchmark/encode_profile.rb | 2 +- lib/ffi_yajl/benchmark/http.rb | 10 +++++----- lib/ffi_yajl/benchmark/parse.rb | 6 +++--- lib/ffi_yajl/benchmark/parse_json_and_marshal.rb | 6 +++--- lib/ffi_yajl/benchmark/parse_json_and_yaml.rb | 8 ++++---- lib/ffi_yajl/benchmark/parse_profile.rb | 2 +- lib/ffi_yajl/benchmark/parse_profile_ruby_prof.rb | 2 +- lib/ffi_yajl/benchmark/parse_stream.rb | 6 +++--- lib/ffi_yajl/ext.rb | 4 ++-- lib/ffi_yajl/ffi.rb | 4 ++-- lib/ffi_yajl/ffi/encoder.rb | 2 +- 14 files changed, 38 insertions(+), 38 deletions(-) (limited to 'lib') diff --git a/lib/ffi_yajl/benchmark/encode.rb b/lib/ffi_yajl/benchmark/encode.rb index 81c1d26..dfab9ea 100644 --- a/lib/ffi_yajl/benchmark/encode.rb +++ b/lib/ffi_yajl/benchmark/encode.rb @@ -1,9 +1,9 @@ # Portions Originally Copyright (c) 2008-2011 Brian Lopez - http://github.com/brianmario # See MIT-LICENSE -require "rubygems" -require "benchmark" -require "stringio" +require "rubygems" unless defined?(Gem) +require "benchmark" unless defined?(Benchmark) +require "stringio" unless defined?(StringIO) if !defined?(RUBY_ENGINE) || RUBY_ENGINE !~ /jruby/ begin require "yajl" @@ -15,7 +15,7 @@ else end require_relative "../../ffi_yajl" begin - require "json" + require "json" unless defined?(JSON) rescue LoadError puts "INFO: json gem not installed" end diff --git a/lib/ffi_yajl/benchmark/encode_json_and_marshal.rb b/lib/ffi_yajl/benchmark/encode_json_and_marshal.rb index 4269056..5ef6f7d 100644 --- a/lib/ffi_yajl/benchmark/encode_json_and_marshal.rb +++ b/lib/ffi_yajl/benchmark/encode_json_and_marshal.rb @@ -1,12 +1,12 @@ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + "/..") $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + "/../lib") -require "rubygems" -require "benchmark" +require "rubygems" unless defined?(Gem) +require "benchmark" unless defined?(Benchmark) require "yajl" -require "stringio" +require "stringio" unless defined?(StringIO) begin - require "json" + require "json" unless defined?(JSON) rescue LoadError end diff --git a/lib/ffi_yajl/benchmark/encode_json_and_yaml.rb b/lib/ffi_yajl/benchmark/encode_json_and_yaml.rb index 72310c1..6a145f2 100644 --- a/lib/ffi_yajl/benchmark/encode_json_and_yaml.rb +++ b/lib/ffi_yajl/benchmark/encode_json_and_yaml.rb @@ -1,14 +1,14 @@ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + "/..") $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + "/../lib") -require "rubygems" -require "benchmark" +require "rubygems" unless defined?(Gem) +require "benchmark" unless defined?(Benchmark) require "yajl" begin - require "json" + require "json" unless defined?(JSON) rescue LoadError end -require "yaml" +require "yaml" unless defined?(YAML) # JSON Section filename = "benchmark/subjects/ohai.json" diff --git a/lib/ffi_yajl/benchmark/encode_profile.rb b/lib/ffi_yajl/benchmark/encode_profile.rb index 153912e..c78e637 100644 --- a/lib/ffi_yajl/benchmark/encode_profile.rb +++ b/lib/ffi_yajl/benchmark/encode_profile.rb @@ -1,7 +1,7 @@ # Portions Originally Copyright (c) 2008-2011 Brian Lopez - http://github.com/brianmario # See MIT-LICENSE -require "rubygems" +require "rubygems" unless defined?(Gem) require_relative "../../ffi_yajl" begin require "perftools" diff --git a/lib/ffi_yajl/benchmark/http.rb b/lib/ffi_yajl/benchmark/http.rb index 0b19387..50c9367 100644 --- a/lib/ffi_yajl/benchmark/http.rb +++ b/lib/ffi_yajl/benchmark/http.rb @@ -1,15 +1,15 @@ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + "/..") $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + "/../lib") -require "rubygems" -require "benchmark" +require "rubygems" unless defined?(Gem) +require "benchmark" unless defined?(Benchmark) require "yajl/http_stream" require "yajl/gzip" require "yajl/deflate" require "yajl/bzip2" unless defined?(Bzip2) -require "json" -require "uri" -require "net/http" +require "json" unless defined?(JSON) +require "uri" unless defined?(URI) +require "net/http" unless defined?(Net::HTTP) uri = URI.parse("http://search.twitter.com/search.json?q=github") # uri = URI.parse('http://localhost/yajl-ruby.git/benchmark/subjects/contacts.json') diff --git a/lib/ffi_yajl/benchmark/parse.rb b/lib/ffi_yajl/benchmark/parse.rb index 431f0a9..3c9108e 100644 --- a/lib/ffi_yajl/benchmark/parse.rb +++ b/lib/ffi_yajl/benchmark/parse.rb @@ -1,5 +1,5 @@ -require "rubygems" -require "benchmark" +require "rubygems" unless defined?(Gem) +require "benchmark" unless defined?(Benchmark) require "yajl" require_relative "../../ffi_yajl" if !defined?(RUBY_ENGINE) || RUBY_ENGINE !~ /jruby/ @@ -12,7 +12,7 @@ else puts "INFO: skipping yajl-ruby on jruby" end begin - require "json" + require "json" unless defined?(JSON) rescue LoadError end begin diff --git a/lib/ffi_yajl/benchmark/parse_json_and_marshal.rb b/lib/ffi_yajl/benchmark/parse_json_and_marshal.rb index 1148ebc..2835aea 100644 --- a/lib/ffi_yajl/benchmark/parse_json_and_marshal.rb +++ b/lib/ffi_yajl/benchmark/parse_json_and_marshal.rb @@ -1,11 +1,11 @@ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + "/..") $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + "/../lib") -require "rubygems" -require "benchmark" +require "rubygems" unless defined?(Gem) +require "benchmark" unless defined?(Benchmark) require "yajl" begin - require "json" + require "json" unless defined?(JSON) rescue LoadError end diff --git a/lib/ffi_yajl/benchmark/parse_json_and_yaml.rb b/lib/ffi_yajl/benchmark/parse_json_and_yaml.rb index b55d916..fe579a9 100644 --- a/lib/ffi_yajl/benchmark/parse_json_and_yaml.rb +++ b/lib/ffi_yajl/benchmark/parse_json_and_yaml.rb @@ -1,14 +1,14 @@ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + "/..") $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + "/../lib") -require "rubygems" -require "benchmark" +require "rubygems" unless defined?(Gem) +require "benchmark" unless defined?(Benchmark) require "yajl" begin - require "json" + require "json" unless defined?(JSON) rescue LoadError end -require "yaml" +require "yaml" unless defined?(YAML) # JSON section filename = "benchmark/subjects/ohai.json" diff --git a/lib/ffi_yajl/benchmark/parse_profile.rb b/lib/ffi_yajl/benchmark/parse_profile.rb index cccb6db..c4e4d64 100644 --- a/lib/ffi_yajl/benchmark/parse_profile.rb +++ b/lib/ffi_yajl/benchmark/parse_profile.rb @@ -1,7 +1,7 @@ # Portions Originally Copyright (c) 2008-2011 Brian Lopez - http://github.com/brianmario # See MIT-LICENSE -require "rubygems" +require "rubygems" unless defined?(Gem) require_relative "../../ffi_yajl" begin require "perftools" diff --git a/lib/ffi_yajl/benchmark/parse_profile_ruby_prof.rb b/lib/ffi_yajl/benchmark/parse_profile_ruby_prof.rb index bdfee7c..7b5114c 100644 --- a/lib/ffi_yajl/benchmark/parse_profile_ruby_prof.rb +++ b/lib/ffi_yajl/benchmark/parse_profile_ruby_prof.rb @@ -1,7 +1,7 @@ # Portions Originally Copyright (c) 2008-2011 Brian Lopez - http://github.com/brianmario # See MIT-LICENSE -require "rubygems" +require "rubygems" unless defined?(Gem) require_relative "../../ffi_yajl" module FFI_Yajl diff --git a/lib/ffi_yajl/benchmark/parse_stream.rb b/lib/ffi_yajl/benchmark/parse_stream.rb index 7fbbb9e..4dc9492 100644 --- a/lib/ffi_yajl/benchmark/parse_stream.rb +++ b/lib/ffi_yajl/benchmark/parse_stream.rb @@ -1,11 +1,11 @@ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + "/..") $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + "/../lib") -require "rubygems" -require "benchmark" +require "rubygems" unless defined?(Gem) +require "benchmark" unless defined?(Benchmark) require "yajl" begin - require "json" + require "json" unless defined?(JSON) rescue LoadError end begin diff --git a/lib/ffi_yajl/ext.rb b/lib/ffi_yajl/ext.rb index e6a7e6d..93d784a 100644 --- a/lib/ffi_yajl/ext.rb +++ b/lib/ffi_yajl/ext.rb @@ -20,7 +20,7 @@ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -require "rubygems" +require "rubygems" unless defined?(Gem) require_relative "encoder" require_relative "parser" @@ -28,7 +28,7 @@ require "ffi_yajl/ext/dlopen" require_relative "map_library_name" # needed so the encoder c-code can find these symbols -require "stringio" +require "stringio" unless defined?(StringIO) require "date" module FFI_Yajl diff --git a/lib/ffi_yajl/ffi.rb b/lib/ffi_yajl/ffi.rb index c6601f0..28fcc79 100644 --- a/lib/ffi_yajl/ffi.rb +++ b/lib/ffi_yajl/ffi.rb @@ -20,11 +20,11 @@ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -require "rubygems" +require "rubygems" unless defined?(Gem) require "libyajl2" begin - require "ffi" + require "ffi" unless defined?(FFI) rescue LoadError $stderr.puts "FATAL: to use the ffi extension instead of the compiled C extension, the ffi gem must be installed" $stderr.puts " (it is optional, so you must include it in your bundle manually)" diff --git a/lib/ffi_yajl/ffi/encoder.rb b/lib/ffi_yajl/ffi/encoder.rb index e5fbfdb..6910066 100644 --- a/lib/ffi_yajl/ffi/encoder.rb +++ b/lib/ffi_yajl/ffi/encoder.rb @@ -21,7 +21,7 @@ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. require "date" -require "stringio" +require "stringio" unless defined?(StringIO) module FFI_Yajl module FFI -- cgit v1.2.1