faster_require 0.7.0 → 0.7.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. data/ChangeLog +3 -0
  2. data/README +7 -8
  3. data/Rakefile +2 -1
  4. data/VERSION +1 -1
  5. data/lib/faster_require.rb +294 -287
  6. metadata +127 -74
@@ -0,0 +1,3 @@
1
+ 0.7.1: Accomodate for non HOME environment variable [what the..]
2
+
3
+ 0.7.0: now it works with autoload finally [and thus hopefully rails]
data/README CHANGED
@@ -2,15 +2,15 @@ A little utility to make
2
2
 
3
3
  require 'xxx'
4
4
 
5
- take much less time. As in much less. Well, on windows at least.
5
+ take much less time. As in much less. Well, on windows at least. And to speedup how long it takes things to load in windows, like rails apps.
6
6
 
7
7
  Well, mostly on windows--on linux it's a speedup of only 0.41 to 0.45s, or so. [1]
8
8
 
9
- If you've ever wondered why ruby feels slow on doze...sometimes it's just the startup time. This helps.
9
+ If you've ever wondered why ruby feels slow on doze...sometimes it's just the startup time. This really helps.
10
10
 
11
11
  Benchmarks:
12
12
 
13
- loading a spec file:
13
+ loading a (blank) rspec file:
14
14
 
15
15
  1.9.1
16
16
  without 3.20s
@@ -47,8 +47,8 @@ running "rake -T"
47
47
 
48
48
  Note: in reality what we should do is fix core so that it doesn't have such awful I/O time in windows. There may be some gross inefficiency in there. For now, this is a work-around.
49
49
 
50
- [1] A sister project to this one, faster_gem_script, can make ruby scripts in linux run faster by 0.1s :) http://github.com/rdp/faster_gem_script
51
- (in windows it's a much higher gain). Eventually they'll be combined into one "gem optimizer" gem.
50
+ [1] If anybody asks me for it, I'll come up with a way to *always* preload this when using rubygems, to speed up "everything" [hopefully]. Note also that
51
+ if things get corrupted or messed up, you can run the (included) faster_require command/script ($ faster_require --clear-cache) and it will clear it.
52
52
 
53
53
  == How to use in Rails ==
54
54
 
@@ -57,7 +57,6 @@ You can either install the gem, then add a
57
57
  require 'rubygems'
58
58
  require 'faster_require'
59
59
 
60
-
61
60
  in your config/environment.rb, or (the best way is as follows):
62
61
 
63
62
  Unpack it somewhere, like lib
@@ -66,9 +65,9 @@ $ gem unpack faster_require
66
65
 
67
66
  Now add this line to your config/environment.rb:
68
67
 
69
- require File.dirname(__FILE__) + "/../lib/faster_require-0.7.0/lib/faster_require" # faster speeds all around...
68
+ require File.dirname(__FILE__) + "/../lib/faster_require-0.7.0/lib/faster_require" # faster speeds all around...make sure to update it to whatever version number you downloaded.
70
69
 
71
- *before* this other (existing) line:
70
+ add it *before* this other (existing) line:
72
71
 
73
72
  require File.join(File.dirname(__FILE__), 'boot')
74
73
 
data/Rakefile CHANGED
@@ -14,7 +14,8 @@ end
14
14
  s.homepage = "http://github.com/rdp/faster_require"
15
15
  s.authors = ["Roger Pack"]
16
16
  s.add_development_dependency 'redparse'
17
- s.add_development_dependency 'active_support', '= 2.3.10'
17
+ s.add_development_dependency 'activesupport', '= 2.3.10'
18
+ s.add_development_dependency 'actionpack', '= 2.3.10'
18
19
  # s.add_development_dependency 'ruby-debug' too... or ruby-debug19 pick your poison
19
20
  s.add_development_dependency 'jeweler'
20
21
  s.add_development_dependency 'rspec', '>= 2'
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.7.0
1
+ 0.7.2
@@ -1,288 +1,295 @@
1
- require 'rbconfig'
2
- #require 'rubygems'
3
- #require 'ruby-debug'
4
-
5
- module FastRequire
6
- $FAST_REQUIRE_DEBUG ||= $DEBUG # can set via $DEBUG, or on its own.
7
-
8
- def self.setup
9
- @@dir = File.expand_path('~/.ruby_faster_require_cache')
10
- Dir.mkdir @@dir unless File.directory?(@@dir)
11
-
12
- parts = [File.basename($0), RUBY_VERSION, RUBY_PLATFORM, File.basename(Dir.pwd), Dir.pwd, File.dirname($0), File.expand_path(File.dirname($0))].map{|part| sanitize(part)}
13
- loc_name = (parts.map{|part| part[0..5]} + parts).join('-')[0..75] # try to be unique, but short...
14
- @@loc = @@dir + '/' + loc_name
15
- end
16
-
17
- def self.sanitize filename
18
- filename.gsub(/[\/:]/, '_')
19
- end
20
-
21
- FastRequire.setup
22
-
23
- def self.load filename
24
- @@require_locs = Marshal.restore( File.open(filename, 'rb') {|f| f.read}) rescue {}
25
- end
26
-
27
- if File.exist?(@@loc)
28
- FastRequire.load @@loc
29
- else
30
- @@require_locs = {}
31
- end
32
-
33
- @@already_loaded = {}
34
-
35
- # try to see where this file was loaded from, from $:
36
- # partial_name might be abc.rb, or might be abc
37
- # partial_name might be a full path, too
38
- def self.guess_discover partial_name, add_dot_rb = false
39
-
40
- # test for full path first
41
- # unfortunately it has to be a full separate test
42
- # for windoze sake, as drive letter could be different than slapping a '/' on the dir to test list...
43
- tests = [partial_name]
44
-
45
- if add_dot_rb
46
- tests << partial_name + '.rb'
47
- tests << partial_name + '.' + RbConfig::CONFIG['DLEXT']
48
- end
49
-
50
- tests.each{|b|
51
- # assume that .rb.rb is...valid...?
52
- if File.file?(b) && ((b[-3..-1] == '.rb') || (b[-3..-1] == '.' + RbConfig::CONFIG['DLEXT']))
53
- return File.expand_path(b)
54
- end
55
- }
56
-
57
- for dir in $:
58
- if File.file?(b = (dir + '/' + partial_name))
59
- # make sure we require a file that has the right suffix...
60
- if (b[-3..-1] == '.rb') || (b[-3..-1] == '.' + RbConfig::CONFIG['DLEXT'])
61
- return File.expand_path(b)
62
- end
63
-
64
- end
65
- end
66
-
67
- if add_dot_rb && (partial_name[-3..-1] != '.rb') && (partial_name[-3..-1] != '.' + RbConfig::CONFIG['DLEXT'])
68
- guess_discover(partial_name + '.rb') || guess_discover(partial_name + '.')
69
- else
70
- nil
71
- end
72
- end
73
-
74
- $LOADED_FEATURES.each{|already_loaded|
75
- # in 1.8 they might be partial paths
76
- # in 1.9, they might be non collapsed paths
77
- # so we have to sanitize them here...
78
- # XXXX File.exist? is a bit too loose, here...
79
- if File.exist?(already_loaded)
80
- key = File.expand_path(already_loaded)
81
- else
82
- key = FastRequire.guess_discover(already_loaded) || already_loaded
83
- end
84
- @@already_loaded[key] = true
85
- }
86
-
87
- @@already_loaded[File.expand_path(__FILE__)] = true # this file itself isn't in loaded features, yet, but very soon will be..
88
- # a special case--I hope...
89
-
90
- # also disallow re- $0
91
- @@require_locs[$0] = File.expand_path($0) # so when we run into it on a require, we will skip it...
92
- @@already_loaded[File.expand_path($0)] = true
93
-
94
- # XXXX within a very long depth to require fast_require,
95
- # require 'a' => 'b' => 'c' => 'd' & fast_require
96
- # then
97
- # => 'b.rb'
98
- # it works always
99
-
100
- def self.already_loaded
101
- @@already_loaded
102
- end
103
-
104
- def self.require_locs
105
- @@require_locs
106
- end
107
-
108
- def self.dir
109
- @@dir
110
- end
111
-
112
- at_exit {
113
- FastRequire.default_save
114
- }
115
-
116
- def self.default_save
117
- self.save @@loc
118
- end
119
-
120
- def self.save to_file
121
- File.open(to_file, 'wb'){|f| f.write Marshal.dump(@@require_locs)}
122
- end
123
-
124
- def self.clear_all!
125
- require 'fileutils'
126
- FileUtils.rm_rf @@dir if File.exist? @@dir
127
- @@require_locs.clear
128
- setup
129
- end
130
-
131
- private
132
- def last_caller
133
- caller[-2]
134
- end
135
-
136
- IN_PROCESS = []
137
- ALL_IN_PROCESS = []
138
- @@count = 0
139
- public
140
-
141
- def require_cached lib
142
- lib = lib.to_s # might not be zactly 1.9 compat... to_path ??
143
- ALL_IN_PROCESS << [lib, @@count += 1]
144
- begin
145
- p 'doing require ' + lib + ' from ' + caller[-1] if $FAST_REQUIRE_DEBUG
146
- if known_loc = @@require_locs[lib]
147
- if @@already_loaded[known_loc]
148
- p 'already loaded ' + known_loc + ' ' + lib if $FAST_REQUIRE_DEBUG
149
- return false
150
- end
151
- @@already_loaded[known_loc] = true
152
- if known_loc =~ /\.#{RbConfig::CONFIG['DLEXT']}$/
153
- puts 'doing original_non_cached_require on .so full path ' + known_loc if $FAST_REQUIRE_DEBUG
154
- original_non_cached_require known_loc # not much we can do there...too bad...well at least we pass it a full path though :P
155
- else
156
- unless $LOADED_FEATURES.include? known_loc
157
- if known_loc =~ /rubygems.rb$/
158
- puts 'requiring rubygems ' + lib if $FAST_REQUIRE_DEBUG
159
- original_non_cached_require(lib) # revert to normal require so rubygems doesn't freak out when it finds itself already in $LOADED_FEATURES with rubygems > 1.6 :P
160
- else
161
- IN_PROCESS << known_loc
162
- begin
163
- if $FAST_REQUIRE_DEBUG
164
- puts 'doing cached loc eval on ' + lib + '=>' + known_loc + " with stack:" + IN_PROCESS.join(' ')
165
- end
166
- $LOADED_FEATURES << known_loc
167
- # fakely add the load path, too, so that autoload for the same file/path in gems will work <sigh> [rspec2]
168
- no_suffix_full_path = known_loc.gsub(/\.[^.]+$/, '')
169
- no_suffix_lib = lib.gsub(/\.[^.]+$/, '')
170
- libs_path = no_suffix_full_path.gsub(no_suffix_lib, '')
171
- libs_path = File.expand_path(libs_path) # strip off trailing '/'
172
- $: << libs_path unless $:.index(libs_path)
173
- # try some more autoload conivings...so that it won't attempt to autoload if it runs into it later...
174
- relative_full_path = known_loc.sub(libs_path, '')[1..-1]
175
- # $LOADED_FEATURES << relative_full_path.gsub('.rb', '') # don't think you need this one
176
- $LOADED_FEATURES << relative_full_path # add in with .rb, too.
177
-
178
- # load(known_loc, false) # too slow
179
- eval(File.open(known_loc, 'rb') {|f| f.read}, TOPLEVEL_BINDING, known_loc) # note the 'rb' here--this means it's reading .rb files as binary, which *typically* works...maybe unnecessary though?
180
- ensure
181
- raise 'unexpected' unless IN_PROCESS.pop == known_loc
182
- end
183
- # --if it breaks re-save the offending file in binary mode, or file an issue on the tracker...
184
- return true
185
- end
186
- else
187
- puts 'ignoring already loaded [circular require?] ' + known_loc + ' ' + lib if $FAST_REQUIRE_DEBUG
188
- end
189
- end
190
- else
191
- # we don't know the location--let Ruby's original require do the heavy lifting for us here
192
- old = $LOADED_FEATURES.dup
193
- if(original_non_cached_require(lib))
194
- # debugger might land here the first time you run a script and it doesn't have a require
195
- # cached yet...
196
- new = $LOADED_FEATURES - old
197
- found = new.last
198
-
199
- # incredibly, in 1.8.x, this doesn't always get set to a full path.
200
- if RUBY_VERSION < '1.9'
201
- if !File.file?(found)
202
- # discover the full path.
203
- dir = $:.find{|path| File.file?(path + '/' + found)}
204
- return true unless dir # give up, case jruby socket.jar "mysterious"
205
- found = dir + '/' + found
206
- end
207
- found = File.expand_path(found);
208
- end
209
- puts 'found new loc:' + lib + '=>' + found if $FAST_REQUIRE_DEBUG
210
- @@require_locs[lib] = found
211
- @@already_loaded[found] = true
212
- return true
213
- else
214
-
215
- # this is expected if it's for libraries required before faster_require was [like rbconfig]
216
- # raise 'actually expected' + lib if RUBY_VERSION >= '1.9.0'
217
- puts 'already loaded, apparently [require returned false], trying to discover how it was redundant... ' + lib if $FAST_REQUIRE_DEBUG
218
- # this probably was something like
219
- # the first pass was require 'regdeferred'
220
- # now it's a different require 'regdeferred.rb'
221
- # which fails (or vice versa)
222
- # so figure out why
223
- # calc location, expand, map back
224
- where_found = FastRequire.guess_discover(lib, true)
225
- if where_found
226
- puts 'inferred lib loc:' + lib + '=>' + where_found if $FAST_REQUIRE_DEBUG
227
- @@require_locs[lib] = where_found
228
- # unfortunately if it's our first pass
229
- # and we are in the middle of a "real" require
230
- # that is circular
231
- # then $LOADED_FEATURES or (AFAIK) nothing will have been set
232
- # for us to be able to assert that
233
- # so...I think we'll end up
234
- # just fudging for a bit
235
- # raise 'not found' unless @@already_loaded[where_found] # should have already been set...I think...
236
- else
237
- if $FAST_REQUIRE_DEBUG
238
- # happens for enumerator XXXX
239
- puts 'unable to infer ' + lib + ' location' if $FAST_REQUIRE_DEBUG
240
- @@already_loaded[found] = true # so hacky...
241
- end
242
- end
243
- return false # XXXX test all these return values
244
- end
245
- end
246
- ensure
247
- raise 'huh' unless ALL_IN_PROCESS.pop[0] == lib
248
- end
249
- end
250
-
251
- end
252
-
253
- module Kernel
254
-
255
- if(defined?(@already_using_faster_require))
256
- raise 'loading twice not allowed...we should never get here!'
257
- end
258
- @already_using_faster_require = true
259
- # overwrite old require...
260
- include FastRequire
261
- if defined?(gem_original_require)
262
- class << self
263
- alias :original_remove_method :remove_method
264
-
265
- def remove_method method # I think this actually might be needed <sigh>
266
- if method.to_s == 'require'
267
- #p 'not removing old require, since that\'s ours now'
268
- else
269
- original_remove_method method
270
- end
271
- end
272
-
273
- end
274
-
275
- # unused?
276
- # def remove_method method
277
- # p 'in mine2'
278
- # end
279
-
280
- # similarly overwrite this one...I guess...1.9.x...rubygems uses this as its default...I think...
281
- alias :original_non_cached_require :gem_original_require
282
- alias :gem_original_require :require_cached
283
- else
284
- alias :original_non_cached_require :require
285
- alias :require :require_cached
1
+ require 'rbconfig'
2
+
3
+ module FastRequire
4
+ $FAST_REQUIRE_DEBUG ||= $DEBUG # can set via $DEBUG, or on its own.
5
+
6
+ def self.setup
7
+ begin
8
+ @@dir = File.expand_path('~/.ruby_faster_require_cache')
9
+ rescue ArgumentError => e # like couldn't find HOME environment or the like
10
+ whoami = `whoami`.strip
11
+ if File.directory?(home = "/home/#{whoami}") # assume writable :P
12
+ @@dir = home + '/.ruby_faster_require_cache'
13
+ else
14
+ raise e
15
+ end
16
+ end
17
+
18
+ Dir.mkdir @@dir unless File.directory?(@@dir)
19
+
20
+ parts = [File.basename($0), RUBY_VERSION, RUBY_PLATFORM, File.basename(Dir.pwd), Dir.pwd, File.dirname($0), File.expand_path(File.dirname($0))].map{|part| sanitize(part)}
21
+ loc_name = (parts.map{|part| part[0..5]} + parts).join('-')[0..75] # try to be unique, but short...
22
+ @@loc = @@dir + '/' + loc_name
286
23
  end
287
-
288
- end
24
+
25
+ def self.sanitize filename
26
+ filename.gsub(/[\/:]/, '_')
27
+ end
28
+
29
+ FastRequire.setup
30
+
31
+ def self.load filename
32
+ @@require_locs = Marshal.restore( File.open(filename, 'rb') {|f| f.read}) rescue {}
33
+ end
34
+
35
+ if File.exist?(@@loc)
36
+ FastRequire.load @@loc
37
+ else
38
+ @@require_locs = {}
39
+ end
40
+
41
+ @@already_loaded = {}
42
+
43
+ # try to see where this file was loaded from, from $:
44
+ # partial_name might be abc.rb, or might be abc
45
+ # partial_name might be a full path, too
46
+ def self.guess_discover partial_name, add_dot_rb = false
47
+
48
+ # test for full path first
49
+ # unfortunately it has to be a full separate test
50
+ # for windoze sake, as drive letter could be different than slapping a '/' on the dir to test list...
51
+ tests = [partial_name]
52
+
53
+ if add_dot_rb
54
+ tests << partial_name + '.rb'
55
+ tests << partial_name + '.' + RbConfig::CONFIG['DLEXT']
56
+ end
57
+
58
+ tests.each{|b|
59
+ # assume that .rb.rb is...valid...?
60
+ if File.file?(b) && ((b[-3..-1] == '.rb') || (b[-3..-1] == '.' + RbConfig::CONFIG['DLEXT']))
61
+ return File.expand_path(b)
62
+ end
63
+ }
64
+
65
+ for dir in $:
66
+ if File.file?(b = (dir + '/' + partial_name))
67
+ # make sure we require a file that has the right suffix...
68
+ if (b[-3..-1] == '.rb') || (b[-3..-1] == '.' + RbConfig::CONFIG['DLEXT'])
69
+ return File.expand_path(b)
70
+ end
71
+
72
+ end
73
+ end
74
+
75
+ if add_dot_rb && (partial_name[-3..-1] != '.rb') && (partial_name[-3..-1] != '.' + RbConfig::CONFIG['DLEXT'])
76
+ guess_discover(partial_name + '.rb') || guess_discover(partial_name + '.')
77
+ else
78
+ nil
79
+ end
80
+ end
81
+
82
+ $LOADED_FEATURES.each{|already_loaded|
83
+ # in 1.8 they might be partial paths
84
+ # in 1.9, they might be non collapsed paths
85
+ # so we have to sanitize them here...
86
+ # XXXX File.exist? is a bit too loose, here...
87
+ if File.exist?(already_loaded)
88
+ key = File.expand_path(already_loaded)
89
+ else
90
+ key = FastRequire.guess_discover(already_loaded) || already_loaded
91
+ end
92
+ @@already_loaded[key] = true
93
+ }
94
+
95
+ @@already_loaded[File.expand_path(__FILE__)] = true # this file itself isn't in loaded features, yet, but very soon will be..
96
+ # a special case--I hope...
97
+
98
+ # also disallow re- $0
99
+ @@require_locs[$0] = File.expand_path($0) # so when we run into it on a require, we will skip it...
100
+ @@already_loaded[File.expand_path($0)] = true
101
+
102
+ # XXXX within a very long depth to require fast_require,
103
+ # require 'a' => 'b' => 'c' => 'd' & fast_require
104
+ # then
105
+ # => 'b.rb'
106
+ # it works always
107
+
108
+ def self.already_loaded
109
+ @@already_loaded
110
+ end
111
+
112
+ def self.require_locs
113
+ @@require_locs
114
+ end
115
+
116
+ def self.dir
117
+ @@dir
118
+ end
119
+
120
+ at_exit {
121
+ FastRequire.default_save
122
+ }
123
+
124
+ def self.default_save
125
+ self.save @@loc
126
+ end
127
+
128
+ def self.save to_file
129
+ File.open(to_file, 'wb'){|f| f.write Marshal.dump(@@require_locs)}
130
+ end
131
+
132
+ def self.clear_all!
133
+ require 'fileutils'
134
+ FileUtils.rm_rf @@dir if File.exist? @@dir
135
+ @@require_locs.clear
136
+ setup
137
+ end
138
+
139
+ private
140
+ def last_caller
141
+ caller[-2]
142
+ end
143
+
144
+ IN_PROCESS = []
145
+ ALL_IN_PROCESS = []
146
+ @@count = 0
147
+ public
148
+
149
+ def require_cached lib
150
+ lib = lib.to_s # might not be zactly 1.9 compat... to_path ??
151
+ ALL_IN_PROCESS << [lib, @@count += 1]
152
+ begin
153
+ p 'doing require ' + lib + ' from ' + caller[-1] if $FAST_REQUIRE_DEBUG
154
+ if known_loc = @@require_locs[lib]
155
+ if @@already_loaded[known_loc]
156
+ p 'already loaded ' + known_loc + ' ' + lib if $FAST_REQUIRE_DEBUG
157
+ return false
158
+ end
159
+ @@already_loaded[known_loc] = true
160
+ if known_loc =~ /\.#{RbConfig::CONFIG['DLEXT']}$/
161
+ puts 'doing original_non_cached_require on .so full path ' + known_loc if $FAST_REQUIRE_DEBUG
162
+ original_non_cached_require known_loc # not much we can do there...too bad...well at least we pass it a full path though :P
163
+ else
164
+ unless $LOADED_FEATURES.include? known_loc
165
+ if known_loc =~ /rubygems.rb$/
166
+ puts 'requiring rubygems ' + lib if $FAST_REQUIRE_DEBUG
167
+ original_non_cached_require(lib) # revert to normal require so rubygems doesn't freak out when it finds itself already in $LOADED_FEATURES with rubygems > 1.6 :P
168
+ else
169
+ IN_PROCESS << known_loc
170
+ begin
171
+ if $FAST_REQUIRE_DEBUG
172
+ puts 'doing cached loc eval on ' + lib + '=>' + known_loc + " with stack:" + IN_PROCESS.join(' ')
173
+ end
174
+ $LOADED_FEATURES << known_loc
175
+ # fakely add the load path, too, so that autoload for the same file/path in gems will work <sigh> [rspec2]
176
+ no_suffix_full_path = known_loc.gsub(/\.[^.]+$/, '')
177
+ no_suffix_lib = lib.gsub(/\.[^.]+$/, '')
178
+ libs_path = no_suffix_full_path.gsub(no_suffix_lib, '')
179
+ libs_path = File.expand_path(libs_path) # strip off trailing '/'
180
+ $: << libs_path unless $:.index(libs_path)
181
+ # try some more autoload conivings...so that it won't attempt to autoload if it runs into it later...
182
+ relative_full_path = known_loc.sub(libs_path, '')[1..-1]
183
+ # $LOADED_FEATURES << relative_full_path.gsub('.rb', '') # don't think you need this one
184
+ $LOADED_FEATURES << relative_full_path # add in with .rb, too.
185
+
186
+ # load(known_loc, false) # too slow
187
+ eval(File.open(known_loc, 'rb') {|f| f.read}, TOPLEVEL_BINDING, known_loc) # note the 'rb' here--this means it's reading .rb files as binary, which *typically* works...maybe unnecessary though?
188
+ ensure
189
+ raise 'unexpected' unless IN_PROCESS.pop == known_loc
190
+ end
191
+ # --if it breaks re-save the offending file in binary mode, or file an issue on the tracker...
192
+ return true
193
+ end
194
+ else
195
+ puts 'ignoring already loaded [circular require?] ' + known_loc + ' ' + lib if $FAST_REQUIRE_DEBUG
196
+ end
197
+ end
198
+ else
199
+ # we don't know the location--let Ruby's original require do the heavy lifting for us here
200
+ old = $LOADED_FEATURES.dup
201
+ if(original_non_cached_require(lib))
202
+ # debugger might land here the first time you run a script and it doesn't have a require
203
+ # cached yet...
204
+ new = $LOADED_FEATURES - old
205
+ found = new.last
206
+
207
+ # incredibly, in 1.8.x, this doesn't always get set to a full path.
208
+ if RUBY_VERSION < '1.9'
209
+ if !File.file?(found)
210
+ # discover the full path.
211
+ dir = $:.find{|path| File.file?(path + '/' + found)}
212
+ return true unless dir # give up, case jruby socket.jar "mysterious"
213
+ found = dir + '/' + found
214
+ end
215
+ found = File.expand_path(found);
216
+ end
217
+ puts 'found new loc:' + lib + '=>' + found if $FAST_REQUIRE_DEBUG
218
+ @@require_locs[lib] = found
219
+ @@already_loaded[found] = true
220
+ return true
221
+ else
222
+
223
+ # this is expected if it's for libraries required before faster_require was [like rbconfig]
224
+ # raise 'actually expected' + lib if RUBY_VERSION >= '1.9.0'
225
+ puts 'already loaded, apparently [require returned false], trying to discover how it was redundant... ' + lib if $FAST_REQUIRE_DEBUG
226
+ # this probably was something like
227
+ # the first pass was require 'regdeferred'
228
+ # now it's a different require 'regdeferred.rb'
229
+ # which fails (or vice versa)
230
+ # so figure out why
231
+ # calc location, expand, map back
232
+ where_found = FastRequire.guess_discover(lib, true)
233
+ if where_found
234
+ puts 'inferred lib loc:' + lib + '=>' + where_found if $FAST_REQUIRE_DEBUG
235
+ @@require_locs[lib] = where_found
236
+ # unfortunately if it's our first pass
237
+ # and we are in the middle of a "real" require
238
+ # that is circular
239
+ # then $LOADED_FEATURES or (AFAIK) nothing will have been set
240
+ # for us to be able to assert that
241
+ # so...I think we'll end up
242
+ # just fudging for a bit
243
+ # raise 'not found' unless @@already_loaded[where_found] # should have already been set...I think...
244
+ else
245
+ if $FAST_REQUIRE_DEBUG
246
+ # happens for enumerator XXXX
247
+ puts 'unable to infer ' + lib + ' location' if $FAST_REQUIRE_DEBUG
248
+ @@already_loaded[found] = true # so hacky...
249
+ end
250
+ end
251
+ return false # XXXX test all these return values
252
+ end
253
+ end
254
+ ensure
255
+ raise 'huh' unless ALL_IN_PROCESS.pop[0] == lib
256
+ end
257
+ end
258
+
259
+ end
260
+
261
+ module Kernel
262
+
263
+ if(defined?(@already_using_faster_require))
264
+ raise 'loading twice not allowed...we should never get here!'
265
+ end
266
+ @already_using_faster_require = true
267
+ # overwrite old require...
268
+ include FastRequire
269
+ if defined?(gem_original_require)
270
+ class << self
271
+ alias :original_remove_method :remove_method
272
+
273
+ def remove_method method # I think this actually might be needed <sigh>
274
+ if method.to_s == 'require'
275
+ #p 'not removing old require, since that\'s ours now'
276
+ else
277
+ original_remove_method method
278
+ end
279
+ end
280
+
281
+ end
282
+
283
+ # unused?
284
+ # def remove_method method
285
+ # p 'in mine2'
286
+ # end
287
+
288
+ # similarly overwrite this one...I guess...1.9.x...rubygems uses this as its default...I think...
289
+ alias :original_non_cached_require :gem_original_require
290
+ alias :gem_original_require :require_cached
291
+ else
292
+ alias :original_non_cached_require :require
293
+ alias :require :require_cached
294
+ end
295
+ end
metadata CHANGED
@@ -1,92 +1,136 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: faster_require
3
- version: !ruby/object:Gem::Version
4
- version: 0.7.0
5
- prerelease:
3
+ version: !ruby/object:Gem::Version
4
+ hash: 7
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 7
9
+ - 2
10
+ version: 0.7.2
6
11
  platform: ruby
7
- authors:
12
+ authors:
8
13
  - Roger Pack
9
14
  autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
- date: 2011-03-09 00:00:00.000000000 -07:00
17
+
18
+ date: 2011-03-09 00:00:00 -07:00
13
19
  default_executable: faster_require
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
16
22
  name: redparse
17
- requirement: &18274344 !ruby/object:Gem::Requirement
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
18
25
  none: false
19
- requirements:
20
- - - ! '>='
21
- - !ruby/object:Gem::Version
22
- version: '0'
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
23
33
  type: :development
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: activesupport
24
37
  prerelease: false
25
- version_requirements: *18274344
26
- - !ruby/object:Gem::Dependency
27
- name: active_support
28
- requirement: &18273984 !ruby/object:Gem::Requirement
38
+ requirement: &id002 !ruby/object:Gem::Requirement
29
39
  none: false
30
- requirements:
31
- - - =
32
- - !ruby/object:Gem::Version
40
+ requirements:
41
+ - - "="
42
+ - !ruby/object:Gem::Version
43
+ hash: 23
44
+ segments:
45
+ - 2
46
+ - 3
47
+ - 10
33
48
  version: 2.3.10
34
49
  type: :development
50
+ version_requirements: *id002
51
+ - !ruby/object:Gem::Dependency
52
+ name: actionpack
35
53
  prerelease: false
36
- version_requirements: *18273984
37
- - !ruby/object:Gem::Dependency
38
- name: jeweler
39
- requirement: &18273696 !ruby/object:Gem::Requirement
54
+ requirement: &id003 !ruby/object:Gem::Requirement
40
55
  none: false
41
- requirements:
42
- - - ! '>='
43
- - !ruby/object:Gem::Version
44
- version: '0'
56
+ requirements:
57
+ - - "="
58
+ - !ruby/object:Gem::Version
59
+ hash: 23
60
+ segments:
61
+ - 2
62
+ - 3
63
+ - 10
64
+ version: 2.3.10
45
65
  type: :development
66
+ version_requirements: *id003
67
+ - !ruby/object:Gem::Dependency
68
+ name: jeweler
46
69
  prerelease: false
47
- version_requirements: *18273696
48
- - !ruby/object:Gem::Dependency
49
- name: rspec
50
- requirement: &18273336 !ruby/object:Gem::Requirement
70
+ requirement: &id004 !ruby/object:Gem::Requirement
51
71
  none: false
52
- requirements:
53
- - - ! '>='
54
- - !ruby/object:Gem::Version
55
- version: '2'
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ hash: 3
76
+ segments:
77
+ - 0
78
+ version: "0"
56
79
  type: :development
80
+ version_requirements: *id004
81
+ - !ruby/object:Gem::Dependency
82
+ name: rspec
57
83
  prerelease: false
58
- version_requirements: *18273336
59
- - !ruby/object:Gem::Dependency
60
- name: sane
61
- requirement: &18272976 !ruby/object:Gem::Requirement
84
+ requirement: &id005 !ruby/object:Gem::Requirement
62
85
  none: false
63
- requirements:
64
- - - ! '>='
65
- - !ruby/object:Gem::Version
66
- version: '0'
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ hash: 7
90
+ segments:
91
+ - 2
92
+ version: "2"
67
93
  type: :development
94
+ version_requirements: *id005
95
+ - !ruby/object:Gem::Dependency
96
+ name: sane
68
97
  prerelease: false
69
- version_requirements: *18272976
70
- - !ruby/object:Gem::Dependency
71
- name: ruby-prof
72
- requirement: &18272652 !ruby/object:Gem::Requirement
98
+ requirement: &id006 !ruby/object:Gem::Requirement
73
99
  none: false
74
- requirements:
75
- - - ! '>='
76
- - !ruby/object:Gem::Version
77
- version: '0'
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ hash: 3
104
+ segments:
105
+ - 0
106
+ version: "0"
78
107
  type: :development
108
+ version_requirements: *id006
109
+ - !ruby/object:Gem::Dependency
110
+ name: ruby-prof
79
111
  prerelease: false
80
- version_requirements: *18272652
81
- description: A tool designed to speedup library loading in Ruby by caching library
82
- locations
112
+ requirement: &id007 !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ hash: 3
118
+ segments:
119
+ - 0
120
+ version: "0"
121
+ type: :development
122
+ version_requirements: *id007
123
+ description: A tool designed to speedup library loading in Ruby by caching library locations
83
124
  email: rogerdpack@gmail.com
84
- executables:
125
+ executables:
85
126
  - faster_require
86
127
  extensions: []
87
- extra_rdoc_files:
128
+
129
+ extra_rdoc_files:
130
+ - ChangeLog
88
131
  - README
89
- files:
132
+ files:
133
+ - ChangeLog
90
134
  - README
91
135
  - Rakefile
92
136
  - VERSION
@@ -127,35 +171,44 @@ files:
127
171
  has_rdoc: true
128
172
  homepage: http://github.com/rdp/faster_require
129
173
  licenses: []
174
+
130
175
  post_install_message:
131
- rdoc_options: []
132
- require_paths:
176
+ rdoc_options:
177
+ - --charset=UTF-8
178
+ require_paths:
133
179
  - lib
134
- required_ruby_version: !ruby/object:Gem::Requirement
180
+ required_ruby_version: !ruby/object:Gem::Requirement
135
181
  none: false
136
- requirements:
137
- - - ! '>='
138
- - !ruby/object:Gem::Version
139
- version: '0'
140
- required_rubygems_version: !ruby/object:Gem::Requirement
182
+ requirements:
183
+ - - ">="
184
+ - !ruby/object:Gem::Version
185
+ hash: 3
186
+ segments:
187
+ - 0
188
+ version: "0"
189
+ required_rubygems_version: !ruby/object:Gem::Requirement
141
190
  none: false
142
- requirements:
143
- - - ! '>='
144
- - !ruby/object:Gem::Version
145
- version: '0'
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ hash: 3
195
+ segments:
196
+ - 0
197
+ version: "0"
146
198
  requirements: []
199
+
147
200
  rubyforge_project:
148
- rubygems_version: 1.6.0
201
+ rubygems_version: 1.3.7
149
202
  signing_key:
150
203
  specification_version: 3
151
204
  summary: Speed library loading in Ruby
152
- test_files:
205
+ test_files:
153
206
  - spec/eval_me1.rb
154
207
  - spec/eval_me2.rb
155
208
  - spec/files/a.rb
156
- - spec/files/a_requires_b.rb
157
209
  - spec/files/active_support_no_double_load.rb
158
210
  - spec/files/attempt_double_load.rb
211
+ - spec/files/a_requires_b.rb
159
212
  - spec/files/b.rb
160
213
  - spec/files/c.rb
161
214
  - spec/files/d.rb
@@ -168,10 +221,10 @@ test_files:
168
221
  - spec/files/load_various_gems.rb
169
222
  - spec/files/load_various_gems2.rb
170
223
  - spec/files/non_dot_rb.rb
224
+ - spec/files/requires_itself.rb
171
225
  - spec/files/require_full_path.rb
172
226
  - spec/files/require_non_dot_rb_fails.rb
173
227
  - spec/files/require_twice_in_dir_pwd.rb
174
- - spec/files/requires_itself.rb
175
228
  - spec/files/should_put_modules_in_right_place.rb
176
229
  - spec/files/slow.rb
177
230
  - spec/files/socket_load.rb