lib/faster_require.rb in faster_require-0.7.3 vs lib/faster_require.rb in faster_require-0.7.4
- old
+ new
@@ -1,10 +1,20 @@
-require 'rbconfig'
+if(defined?($already_using_faster_require))
+ p 'warning: faster_require double load expected?' if $FAST_REQUIRE_DEBUG
+ local_version = File.read(File.dirname(__FILE__) + "/../VERSION")
+ raise 'mismatched faster_require version' unless local_version == FastRequire::VERSION
+else
+$already_using_faster_require = true
+
+# now load it...
+
+require 'rbconfig' # maybe could cache this one, too?
+
module FastRequire
$FAST_REQUIRE_DEBUG ||= $DEBUG # can set via $DEBUG, or on its own.
-
+ VERSION = File.read(File.dirname(__FILE__) + "/../VERSION")
def self.setup
begin
@@dir = File.expand_path('~/.ruby_faster_require_cache')
rescue ArgumentError => e # like couldn't find HOME environment or the like
whoami = `whoami`.strip
@@ -175,15 +185,16 @@
# fakely add the load path, too, so that autoload for the same file/path in gems will work <sigh> [rspec2]
no_suffix_full_path = known_loc.gsub(/\.[^.]+$/, '')
no_suffix_lib = lib.gsub(/\.[^.]+$/, '')
libs_path = no_suffix_full_path.gsub(no_suffix_lib, '')
libs_path = File.expand_path(libs_path) # strip off trailing '/'
- $: << libs_path unless $:.index(libs_path)
+ $: << libs_path unless $:.index(libs_path) # might not need this anymore, but it feels more sane...does it slow us down, though?
+
# try some more autoload conivings...so that it won't attempt to autoload if it runs into it later...
relative_full_path = known_loc.sub(libs_path, '')[1..-1]
+ $LOADED_FEATURES << relative_full_path unless $LOADED_FEATURES.index(relative_full_path) # add in with .rb, too, for autoload
# $LOADED_FEATURES << relative_full_path.gsub('.rb', '') # don't think you need this one
- $LOADED_FEATURES << relative_full_path # add in with .rb, too.
# load(known_loc, false) # too slow
contents = File.open(known_loc, 'rb') {|f| f.read}
if contents =~ /require_relative/ # =~ is faster than .include? it appears
load(known_loc, false) # slow, but dependent on a ruby core bug: http://redmine.ruby-lang.org/issues/4487
@@ -201,10 +212,11 @@
end
end
else
# we don't know the location--let Ruby's original require do the heavy lifting for us here
old = $LOADED_FEATURES.dup
+ p 'doing old non-known location require ' + lib if $FAST_REQUIRE_DEBUG
if(original_non_cached_require(lib))
# debugger might land here the first time you run a script and it doesn't have a require
# cached yet...
new = $LOADED_FEATURES - old
found = new.last
@@ -263,14 +275,10 @@
end
module Kernel
- if(defined?(@already_using_faster_require))
- raise 'loading twice not allowed...we should never get here!'
- end
- @already_using_faster_require = true
# overwrite old require...
include FastRequire
if defined?(gem_original_require)
class << self
alias :original_remove_method :remove_method
@@ -296,5 +304,8 @@
else
alias :original_non_cached_require :require
alias :require :require_cached
end
end
+
+
+end
\ No newline at end of file