faster_require 0.9.2 → 0.9.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (7) hide show
  1. data/ChangeLog +2 -0
  2. data/LICENSE +3 -0
  3. data/README +7 -3
  4. data/Rakefile +2 -0
  5. data/VERSION +1 -1
  6. data/lib/faster_require.rb +365 -365
  7. metadata +169 -185
data/ChangeLog CHANGED
@@ -1,3 +1,5 @@
1
+ 0.9.3: work with execjs or some odd...
2
+
1
3
  0.9.1: work with rails 3.0.7 through a kludgey way...
2
4
 
3
5
  0.9.0: refactors, bug fix for poor file, can autoload disregarding dir now
data/LICENSE ADDED
@@ -0,0 +1,3 @@
1
+ Released under the BSD license copyright 2010 Roger Pack
2
+
3
+ http://www.opensource.org/licenses/bsd-license.php
data/README CHANGED
@@ -146,7 +146,7 @@ be slow the first time you run it in each directory.
146
146
  To make it be fast and basically disregard PWD, you can add global setting $faster_require_ignore_pwd_for_cache = true
147
147
  and set it before requiring faster_require itself.
148
148
 
149
- So not rubygems.rb at the top would look like
149
+ So now rubygems.rb at the top would look like
150
150
  $faster_require_ignore_pwd_for_cache = true
151
151
  require 'd:/Ruby192/lib/ruby/gems/1.9.1/gems/faster_require-0.6.0/lib/faster_require.rb'
152
152
 
@@ -154,7 +154,11 @@ And now your gem scripts will run fast regardless of where you run them from.
154
154
 
155
155
  == See also ==
156
156
 
157
- Spork can help speedup rails tests. I "should" work well when used in conjunction with faster_require, as well.
157
+ Spork can help speedup rails tests. It "should" work well when used in conjunction with faster_require, as well.
158
158
 
159
+ Also "The Code Shop" releases versions of ruby that have an optimized require method, which might make this library obsolete.
160
+ http://thecodeshop.github.com
161
+ https://groups.google.com/group/thecodeshop
162
+ http://itreallymatters.net/post/12897174267/speedup-ruby-1-9-3-on-windows#.T89_XtVYut0
159
163
 
160
- Enjoy.
164
+ Enjoy.
data/Rakefile CHANGED
@@ -1,5 +1,7 @@
1
1
  require 'rubygems'
2
2
 
3
+ #NB that releasing with 1.9.x is ill advised...
4
+
3
5
  require 'jeweler'
4
6
  Jeweler::Tasks.new do |s|
5
7
  s.name = "faster_require"
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.9.2
1
+ 0.9.3
@@ -1,366 +1,366 @@
1
- # check for and avoid a double load...because we're afraid to load twice, since we override require et al
2
-
3
- if(defined?($already_using_faster_require))
4
- p 'warning: faster_require double load--expected?' if $FAST_REQUIRE_DEBUG
5
- local_version = File.read(File.dirname(__FILE__) + "/../VERSION")
6
- raise "mismatched faster_require versions! #{local_version} != #{FastRequire::VERSION}" unless local_version == FastRequire::VERSION
7
- else
8
-
9
- $already_using_faster_require = true
10
-
11
-
12
- require 'rbconfig' # maybe could cache this one's loc, too? probably not...
13
-
14
- module FastRequire
15
-
16
- $FAST_REQUIRE_DEBUG ||= $DEBUG # can set this via $DEBUG, or on its own previously
17
-
18
- VERSION = File.read(File.dirname(__FILE__) + "/../VERSION")
19
-
20
- def self.sanitize filename
21
- filename.gsub(/[\/:]/, '_')
22
- end
23
-
24
- if RUBY_VERSION >= '1.9.0'
25
- # appears 1.9.x has inconsistent string hashes...so roll our own...
26
- def self.string_array_cruddy_hash strings
27
- # we only call this method once, so overflowing to a bignum is ok
28
- hash = 1;
29
- for string in strings
30
- hash = hash * 31
31
- string.each_byte{|b|
32
- hash += b
33
- }
34
- end
35
- hash # probably a Bignum (sigh)
36
- end
37
-
38
- else
39
-
40
- def self.string_array_cruddy_hash strings
41
- strings.hash
42
- end
43
-
44
- end
45
-
46
- def self.setup
47
- begin
48
- @@dir = File.expand_path('~/.ruby_faster_require_cache')
49
- rescue ArgumentError => e # couldn't find HOME environment or the like
50
- whoami = `whoami`.strip
51
- if File.directory?(home = "/home/#{whoami}")
52
- @@dir = home + '/.ruby_faster_require_cache'
53
- else
54
- raise e.to_s + " and couldnt infer it from whoami"
55
- end
56
- end
57
-
58
- unless File.directory?(@@dir)
59
- Dir.mkdir @@dir
60
- raise 'unable to create user dir for faster_require ' + @@dir unless File.directory?(@@dir)
61
- end
62
-
63
- config = RbConfig::CONFIG
64
-
65
- # try to be a unique, but not too long, filename, for restrictions on filename length in doze
66
- ruby_bin_name = config['bindir'] + config['ruby_install_name'] # needed if you have two rubies, same box, same ruby description [version, patch number]
67
- parts = [File.basename($0), RUBY_PATCHLEVEL.to_s, RUBY_PLATFORM, RUBY_VERSION, RUBY_VERSION, File.expand_path(File.dirname($0)), ruby_bin_name]
68
- unless defined?($faster_require_ignore_pwd_for_cache)
69
- # add in Dir.pwd
70
- parts << File.basename(Dir.pwd)
71
- parts << Dir.pwd
72
- else
73
- p 'ignoring dirpwd for cached file location' if $FAST_REQUIRE_DEBUG
74
- end
75
-
76
- sanitized_parts = parts.map{|part| sanitize(part)}
77
-
78
- full_parts_hash = string_array_cruddy_hash(parts).to_s
79
-
80
- loc_name = (sanitized_parts.map{|part| part[0..5] + (part[-5..-1] || '')}).join('-') + '-' + full_parts_hash + '.marsh'
81
-
82
- @@loc = @@dir + '/' + loc_name
83
-
84
- if File.exist?(@@loc)
85
- FastRequire.load @@loc
86
- else
87
- @@require_locs = {}
88
- end
89
-
90
- @@already_loaded = {}
91
-
92
- $LOADED_FEATURES.each{|already_loaded|
93
- # in 1.8 they might be partial paths
94
- # in 1.9, they might be non collapsed paths
95
- # so we have to sanitize them here...
96
- # XXXX File.exist? is a bit too loose, here...
97
- if File.exist?(already_loaded)
98
- key = File.expand_path(already_loaded)
99
- else
100
- key = FastRequire.guess_discover(already_loaded) || already_loaded
101
- end
102
- @@already_loaded[key] = true
103
- }
104
-
105
- @@already_loaded[File.expand_path(__FILE__)] = true # this file itself isn't in loaded features, yet, but very soon will be..
106
- # a special case--I hope...
107
-
108
- # also disallow re-loading $0
109
- @@require_locs[$0] = File.expand_path($0) # so when we run into $0 on a freak require, we will skip it...
110
- @@already_loaded[File.expand_path($0)] = true
111
-
112
- end
113
-
114
- def self.load filename
115
- cached_marshal_data = File.open(filename, 'rb') {|f| f.read}
116
- begin
117
- @@require_locs = Marshal.restore( cached_marshal_data )
118
- rescue ArgumentError
119
- @@require_locs= {}
120
- end
121
- end
122
-
123
-
124
- # try to see where this file was loaded from, from $:
125
- # partial_name might be abc.rb, or might be abc
126
- # partial_name might be a full path, too
127
- def self.guess_discover partial_name, add_dot_rb = false
128
-
129
- # test for full path first
130
- # unfortunately it has to be a full separate test
131
- # for windoze sake, as drive letter could be different than slapping a '/' on the dir to test list...
132
- tests = [partial_name]
133
-
134
- if add_dot_rb
135
- tests << partial_name + '.rb'
136
- tests << partial_name + '.' + RbConfig::CONFIG['DLEXT']
137
- end
138
-
139
- tests.each{|b|
140
- # assume that .rb.rb is...valid...?
141
- if File.file?(b) && ((b[-3..-1] == '.rb') || (b[-3..-1] == '.' + RbConfig::CONFIG['DLEXT']))
142
- return File.expand_path(b)
143
- end
144
- }
145
-
146
- for dir in $:
147
- if File.file?(b = (dir + '/' + partial_name))
148
- # make sure we require a file that has the right suffix...
149
- if (b[-3..-1] == '.rb') || (b[-3..-1] == '.' + RbConfig::CONFIG['DLEXT'])
150
- return File.expand_path(b)
151
- end
152
-
153
- end
154
- end
155
-
156
- if add_dot_rb && (partial_name[-3..-1] != '.rb') && (partial_name[-3..-1] != '.' + RbConfig::CONFIG['DLEXT'])
157
- guess_discover(partial_name + '.rb') || guess_discover(partial_name + '.')
158
- else
159
- nil
160
- end
161
- end
162
-
163
- FastRequire.setup
164
-
165
- def self.already_loaded
166
- @@already_loaded
167
- end
168
-
169
- def self.require_locs
170
- @@require_locs
171
- end
172
-
173
- def self.dir
174
- @@dir
175
- end
176
-
177
- def self.loc
178
- @@loc
179
- end
180
-
181
- at_exit {
182
- FastRequire.default_save
183
- }
184
-
185
- def self.default_save
186
- self.save @@loc
187
- end
188
-
189
- def self.save to_file
190
- File.open(to_file, 'wb'){|f| f.write Marshal.dump(@@require_locs)}
191
- end
192
-
193
- # for testing use only, basically
194
- def self.clear_all!
195
- require 'fileutils'
196
- success = false
197
- if File.exist? @@dir
198
- FileUtils.rm_rf @@dir
199
- success = true
200
- end
201
- @@require_locs.clear
202
- setup
203
- success
204
- end
205
-
206
- private
207
- def last_caller
208
- caller[-2]
209
- end
210
-
211
- IN_PROCESS = []
212
- ALL_IN_PROCESS = []
213
- @@count = 0
214
-
215
- public
216
-
217
- def require_cached lib
218
- lib = lib.to_s # might not be zactly 1.9 compat... to_path ??
219
- ALL_IN_PROCESS << [lib, @@count += 1]
220
- begin
221
- p 'doing require ' + lib + ' from ' + caller[-1] if $FAST_REQUIRE_DEBUG
222
- if known_loc = @@require_locs[lib]
223
- if @@already_loaded[known_loc]
224
- p 'already loaded ' + known_loc + ' ' + lib if $FAST_REQUIRE_DEBUG
225
- return false
226
- end
227
- @@already_loaded[known_loc] = true
228
- if known_loc =~ /\.#{RbConfig::CONFIG['DLEXT']}$/
229
- puts 'doing original_non_cached_require on .so full path ' + known_loc if $FAST_REQUIRE_DEBUG
230
- 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
231
- else
232
- unless $LOADED_FEATURES.include? known_loc
233
- if known_loc =~ /rubygems.rb$/
234
- puts 'requiring rubygems ' + lib if $FAST_REQUIRE_DEBUG
235
- 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
236
- else
237
- IN_PROCESS << known_loc
238
- begin
239
- if $FAST_REQUIRE_DEBUG
240
- puts 'doing cached loc eval on ' + lib + '=>' + known_loc + " with stack:" + IN_PROCESS.join(' ')
241
- end
242
- $LOADED_FEATURES << known_loc
243
- # fakely add the load path, too, so that autoload for the same file/path in gems will work <sigh> [rspec2]
244
- no_suffix_full_path = known_loc.gsub(/\.[^.]+$/, '')
245
- no_suffix_lib = lib.gsub(/\.[^.]+$/, '')
246
- libs_path = no_suffix_full_path.gsub(no_suffix_lib, '')
247
- libs_path = File.expand_path(libs_path) # strip off trailing '/'
248
-
249
- $: << libs_path unless $:.index(libs_path) # add in this ones real require path, so that neighboring autoloads will work
250
- known_locs_dir = File.dirname(known_loc)
251
- $: << known_locs_dir unless $:.index(known_locs_dir) # attempt to avoid the regin loading bug...yipes.
252
-
253
- # try some more autoload conivings...so that it won't attempt to autoload if it runs into it later...
254
- relative_full_path = known_loc.sub(libs_path, '')[1..-1]
255
- $LOADED_FEATURES << relative_full_path unless $LOADED_FEATURES.index(relative_full_path) # add in with .rb, too, for autoload
256
-
257
- # load(known_loc, false) # too slow
258
-
259
- # use eval: if this fails to load breaks re-save the offending file in binary mode, or file an issue on the faster_require tracker...
260
- contents = File.open(known_loc, 'rb') {|f| f.read} # read only costs 0.34/10.0 s...
261
- if contents =~ /require_relative/ # =~ is faster apparently faster than .include?
262
- load(known_loc, false) # load is slow, but overcomes a ruby core bug: http://redmine.ruby-lang.org/issues/4487
263
- else
264
- eval(contents, TOPLEVEL_BINDING, known_loc) # note the 'rb' here--this means it's reading .rb files as binary, which *typically* works...maybe unnecessary though?
265
- end
266
- ensure
267
- raise 'unexpected' unless IN_PROCESS.pop == known_loc
268
- end
269
- return true
270
- end
271
- else
272
- puts 'ignoring already loaded [circular require?] ' + known_loc + ' ' + lib if $FAST_REQUIRE_DEBUG
273
- end
274
- end
275
- else
276
- # we don't know the location--let Ruby's original require do the heavy lifting for us here
277
- old = $LOADED_FEATURES.dup
278
- p 'doing old non-known location require ' + lib if $FAST_REQUIRE_DEBUG
279
- if(original_non_cached_require(lib))
280
- # debugger might land here the first time you run a script and it doesn't have a require
281
- # cached yet...
282
- new = $LOADED_FEATURES - old
283
- found = new.last
284
-
285
- # incredibly, in 1.8.x, this doesn't always get set to a full path.
286
- if RUBY_VERSION < '1.9'
287
- if !File.file?(found)
288
- # discover the full path.
289
- dir = $:.find{|path| File.file?(path + '/' + found)}
290
- return true unless dir # give up, case jruby socket.jar "mysterious"
291
- found = dir + '/' + found
292
- end
293
- found = File.expand_path(found);
294
- end
295
- puts 'found new loc:' + lib + '=>' + found if $FAST_REQUIRE_DEBUG
296
- @@require_locs[lib] = found
297
- @@already_loaded[found] = true
298
- return true
299
- else
300
-
301
- # this is expected if it's for libraries required before faster_require was [like rbconfig]
302
- # raise 'actually expected' + lib if RUBY_VERSION >= '1.9.0'
303
- puts 'already loaded, apparently [require returned false], trying to discover how it was redundant... ' + lib if $FAST_REQUIRE_DEBUG
304
- # this probably was something like
305
- # the first pass was require 'regdeferred'
306
- # now it's a different require 'regdeferred.rb'
307
- # which fails (or vice versa)
308
- # so figure out why
309
- # calc location, expand, map back
310
- where_found = FastRequire.guess_discover(lib, true)
311
- if where_found
312
- puts 'inferred lib loc:' + lib + '=>' + where_found if $FAST_REQUIRE_DEBUG
313
- @@require_locs[lib] = where_found
314
- # unfortunately if it's our first pass
315
- # and we are in the middle of a "real" require
316
- # that is circular
317
- # then $LOADED_FEATURES or (AFAIK) nothing will have been set
318
- # for us to be able to assert that
319
- # so...I think we'll end up
320
- # just fudging for a bit
321
- # raise 'not found' unless @@already_loaded[where_found] # should have already been set...I think...
322
- else
323
- if $FAST_REQUIRE_DEBUG
324
- # happens for enumerator XXXX
325
- puts 'unable to infer ' + lib + ' location' if $FAST_REQUIRE_DEBUG
326
- @@already_loaded[found] = true # so hacky...
327
- end
328
- end
329
- return false # XXXX test all these return values
330
- end
331
- end
332
- ensure
333
- raise 'huh' unless ALL_IN_PROCESS.pop[0] == lib
334
- end
335
- end
336
-
337
- end
338
-
339
- module Kernel
340
-
341
- # overwrite old require...
342
- include FastRequire
343
- if defined?(gem_original_require)
344
- class << self
345
- alias :original_remove_method :remove_method
346
-
347
- def remove_method method # I think this actually might be needed <sigh>
348
- if method.to_s == 'require'
349
- #p 'not removing old require, since that\'s ours now'
350
- else
351
- original_remove_method method
352
- end
353
- end
354
-
355
- end
356
-
357
- # similarly overwrite this one...I guess...1.9.x...rubygems uses this as its default...I think...
358
- alias :original_non_cached_require :gem_original_require
359
- alias :gem_original_require :require_cached
360
- else
361
- alias :original_non_cached_require :require
362
- alias :require :require_cached
363
- end
364
- end
365
-
1
+ # check for and avoid a double load...because we're afraid to load twice, since we override require et al
2
+
3
+ if(defined?($already_using_faster_require))
4
+ p 'warning: faster_require double load--expected?' if $FAST_REQUIRE_DEBUG
5
+ local_version = File.read(File.dirname(__FILE__) + "/../VERSION")
6
+ raise "mismatched faster_require versions! #{local_version} != #{FastRequire::VERSION}" unless local_version == FastRequire::VERSION
7
+ else
8
+
9
+ $already_using_faster_require = true
10
+
11
+
12
+ require 'rbconfig' # maybe could cache this one's loc, too? probably not...
13
+
14
+ module FastRequire
15
+
16
+ $FAST_REQUIRE_DEBUG ||= $DEBUG # can set this via $DEBUG, or on its own previously
17
+
18
+ VERSION = File.read(File.dirname(__FILE__) + "/../VERSION")
19
+
20
+ def self.sanitize filename
21
+ filename.gsub(/[\/:]/, '_')
22
+ end
23
+
24
+ if RUBY_VERSION >= '1.9.0'
25
+ # appears 1.9.x has inconsistent string hashes...so roll our own...
26
+ def self.string_array_cruddy_hash strings
27
+ # we only call this method once, so overflowing to a bignum is ok
28
+ hash = 1;
29
+ for string in strings
30
+ hash = hash * 31
31
+ string.each_byte{|b|
32
+ hash += b
33
+ }
34
+ end
35
+ hash # probably a Bignum (sigh)
36
+ end
37
+
38
+ else
39
+
40
+ def self.string_array_cruddy_hash strings
41
+ strings.hash
42
+ end
43
+
44
+ end
45
+
46
+ def self.setup
47
+ begin
48
+ @@dir = File.expand_path('~/.ruby_faster_require_cache')
49
+ rescue ArgumentError => e # couldn't find HOME environment or the like
50
+ whoami = `whoami`.strip
51
+ if File.directory?(home = "/home/#{whoami}")
52
+ @@dir = home + '/.ruby_faster_require_cache'
53
+ else
54
+ raise e.to_s + " and couldnt infer it from whoami"
55
+ end
56
+ end
57
+
58
+ unless File.directory?(@@dir)
59
+ Dir.mkdir @@dir
60
+ raise 'unable to create user dir for faster_require ' + @@dir unless File.directory?(@@dir)
61
+ end
62
+
63
+ config = RbConfig::CONFIG
64
+
65
+ # try to be a unique, but not too long, filename, for restrictions on filename length in doze
66
+ ruby_bin_name = config['bindir'] + config['ruby_install_name'] # needed if you have two rubies, same box, same ruby description [version, patch number]
67
+ parts = [File.basename($0), RUBY_PATCHLEVEL.to_s, RUBY_PLATFORM, RUBY_VERSION, RUBY_VERSION, File.expand_path(File.dirname($0)), ruby_bin_name]
68
+ unless defined?($faster_require_ignore_pwd_for_cache)
69
+ # add in Dir.pwd
70
+ parts << File.basename(Dir.pwd)
71
+ parts << Dir.pwd
72
+ else
73
+ p 'ignoring dirpwd for cached file location' if $FAST_REQUIRE_DEBUG
74
+ end
75
+
76
+ sanitized_parts = parts.map{|part| sanitize(part)}
77
+
78
+ full_parts_hash = string_array_cruddy_hash(parts).to_s
79
+
80
+ loc_name = (sanitized_parts.map{|part| part[0..5] + (part[-5..-1] || '')}).join('-') + '-' + full_parts_hash + '.marsh'
81
+
82
+ @@loc = @@dir + '/' + loc_name
83
+
84
+ if File.exist?(@@loc)
85
+ FastRequire.load @@loc
86
+ else
87
+ @@require_locs = {}
88
+ end
89
+
90
+ @@already_loaded = {}
91
+
92
+ $LOADED_FEATURES.each{|already_loaded|
93
+ # in 1.8 they might be partial paths
94
+ # in 1.9, they might be non collapsed paths
95
+ # so we have to sanitize them here...
96
+ # XXXX File.exist? is a bit too loose, here...
97
+ if File.exist?(already_loaded)
98
+ key = File.expand_path(already_loaded)
99
+ else
100
+ key = FastRequire.guess_discover(already_loaded) || already_loaded
101
+ end
102
+ @@already_loaded[key] = true
103
+ }
104
+
105
+ @@already_loaded[File.expand_path(__FILE__)] = true # this file itself isn't in loaded features, yet, but very soon will be..
106
+ # a special case--I hope...
107
+
108
+ # also disallow re-loading $0
109
+ @@require_locs[$0] = File.expand_path($0) # so when we run into $0 on a freak require, we will skip it...
110
+ @@already_loaded[File.expand_path($0)] = true
111
+
112
+ end
113
+
114
+ def self.load filename
115
+ cached_marshal_data = File.open(filename, 'rb') {|f| f.read}
116
+ begin
117
+ @@require_locs = Marshal.restore( cached_marshal_data )
118
+ rescue ArgumentError
119
+ @@require_locs= {}
120
+ end
121
+ end
122
+
123
+
124
+ # try to see where this file was loaded from, from $:
125
+ # partial_name might be abc.rb, or might be abc
126
+ # partial_name might be a full path, too
127
+ def self.guess_discover partial_name, add_dot_rb = false
128
+
129
+ # test for full path first
130
+ # unfortunately it has to be a full separate test
131
+ # for windoze sake, as drive letter could be different than slapping a '/' on the dir to test list...
132
+ tests = [partial_name]
133
+
134
+ if add_dot_rb
135
+ tests << partial_name + '.rb'
136
+ tests << partial_name + '.' + RbConfig::CONFIG['DLEXT']
137
+ end
138
+
139
+ tests.each{|b|
140
+ # assume that .rb.rb is...valid...?
141
+ if File.file?(b) && ((b[-3..-1] == '.rb') || (b[-3..-1] == '.' + RbConfig::CONFIG['DLEXT']))
142
+ return File.expand_path(b)
143
+ end
144
+ }
145
+
146
+ for dir in $:
147
+ if File.file?(b = (dir + '/' + partial_name))
148
+ # make sure we require a file that has the right suffix...
149
+ if (b[-3..-1] == '.rb') || (b[-3..-1] == '.' + RbConfig::CONFIG['DLEXT'])
150
+ return File.expand_path(b)
151
+ end
152
+
153
+ end
154
+ end
155
+
156
+ if add_dot_rb && (partial_name[-3..-1] != '.rb') && (partial_name[-3..-1] != '.' + RbConfig::CONFIG['DLEXT'])
157
+ guess_discover(partial_name + '.rb') || guess_discover(partial_name + '.')
158
+ else
159
+ nil
160
+ end
161
+ end
162
+
163
+ FastRequire.setup
164
+
165
+ def self.already_loaded
166
+ @@already_loaded
167
+ end
168
+
169
+ def self.require_locs
170
+ @@require_locs
171
+ end
172
+
173
+ def self.dir
174
+ @@dir
175
+ end
176
+
177
+ def self.loc
178
+ @@loc
179
+ end
180
+
181
+ at_exit {
182
+ FastRequire.default_save
183
+ }
184
+
185
+ def self.default_save
186
+ self.save @@loc
187
+ end
188
+
189
+ def self.save to_file
190
+ File.open(to_file, 'wb'){|f| f.write Marshal.dump(@@require_locs)}
191
+ end
192
+
193
+ # for testing use only, basically
194
+ def self.clear_all!
195
+ require 'fileutils'
196
+ success = false
197
+ if File.exist? @@dir
198
+ FileUtils.rm_rf @@dir
199
+ success = true
200
+ end
201
+ @@require_locs.clear
202
+ setup
203
+ success
204
+ end
205
+
206
+ private
207
+ def last_caller
208
+ caller[-2]
209
+ end
210
+
211
+ IN_PROCESS = []
212
+ ALL_IN_PROCESS = []
213
+ @@count = 0
214
+
215
+ public
216
+
217
+ def require_cached lib
218
+ lib = lib.to_s # might not be zactly 1.9 compat... to_path ??
219
+ ALL_IN_PROCESS << [lib, @@count += 1]
220
+ begin
221
+ p 'doing require ' + lib + ' from ' + caller[-1] if $FAST_REQUIRE_DEBUG
222
+ if known_loc = @@require_locs[lib]
223
+ if @@already_loaded[known_loc]
224
+ p 'already loaded ' + known_loc + ' ' + lib if $FAST_REQUIRE_DEBUG
225
+ return false
226
+ end
227
+ @@already_loaded[known_loc] = true
228
+ if known_loc =~ /\.#{RbConfig::CONFIG['DLEXT']}$/
229
+ puts 'doing original_non_cached_require on .so full path ' + known_loc if $FAST_REQUIRE_DEBUG
230
+ 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
231
+ else
232
+ unless $LOADED_FEATURES.include? known_loc
233
+ if known_loc =~ /rubygems.rb$/
234
+ puts 'requiring rubygems ' + lib if $FAST_REQUIRE_DEBUG
235
+ 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
236
+ else
237
+ IN_PROCESS << known_loc
238
+ begin
239
+ if $FAST_REQUIRE_DEBUG
240
+ puts 'doing cached loc eval on ' + lib + '=>' + known_loc + " with stack:" + IN_PROCESS.join(' ')
241
+ end
242
+ $LOADED_FEATURES << known_loc
243
+ # fakely add the load path, too, so that autoload for the same file/path in gems will work <sigh> [rspec2]
244
+ no_suffix_full_path = known_loc.gsub(/\.[^.]+$/, '')
245
+ no_suffix_lib = lib.gsub(/\.[^.]+$/, '')
246
+ libs_path = no_suffix_full_path.gsub(no_suffix_lib, '')
247
+ libs_path = File.expand_path(libs_path) # strip off trailing '/'
248
+
249
+ $: << libs_path unless $:.index(libs_path) # add in this ones real require path, so that neighboring autoloads will work
250
+ known_locs_dir = File.dirname(known_loc)
251
+ $: << known_locs_dir unless $:.index(known_locs_dir) # attempt to avoid the regin loading bug...yipes.
252
+
253
+ # try some more autoload conivings...so that it won't attempt to autoload if it runs into it later...
254
+ relative_full_path = known_loc.sub(libs_path, '')[1..-1]
255
+ $LOADED_FEATURES << relative_full_path unless $LOADED_FEATURES.index(relative_full_path) # add in with .rb, too, for autoload
256
+
257
+ # load(known_loc, false) # too slow
258
+
259
+ # use eval: if this fails to load breaks re-save the offending file in binary mode, or file an issue on the faster_require tracker...
260
+ contents = File.open(known_loc, 'rb') {|f| f.read} # read only costs 0.34/10.0 s...
261
+ if contents =~ /require_relative/ # =~ is faster apparently faster than .include?
262
+ load(known_loc, false) # load is slow, but overcomes a ruby core bug: http://redmine.ruby-lang.org/issues/4487
263
+ else
264
+ Kernel.eval(contents, TOPLEVEL_BINDING, known_loc) # note the 'rb' here--this means it's reading .rb files as binary, which *typically* works...maybe unnecessary though?
265
+ end
266
+ ensure
267
+ raise 'unexpected' unless IN_PROCESS.pop == known_loc
268
+ end
269
+ return true
270
+ end
271
+ else
272
+ puts 'ignoring already loaded [circular require?] ' + known_loc + ' ' + lib if $FAST_REQUIRE_DEBUG
273
+ end
274
+ end
275
+ else
276
+ # we don't know the location--let Ruby's original require do the heavy lifting for us here
277
+ old = $LOADED_FEATURES.dup
278
+ p 'doing old non-known location require ' + lib if $FAST_REQUIRE_DEBUG
279
+ if(original_non_cached_require(lib))
280
+ # debugger might land here the first time you run a script and it doesn't have a require
281
+ # cached yet...
282
+ new = $LOADED_FEATURES - old
283
+ found = new.last
284
+
285
+ # incredibly, in 1.8.x, this doesn't always get set to a full path.
286
+ if RUBY_VERSION < '1.9'
287
+ if !File.file?(found)
288
+ # discover the full path.
289
+ dir = $:.find{|path| File.file?(path + '/' + found)}
290
+ return true unless dir # give up, case jruby socket.jar "mysterious"
291
+ found = dir + '/' + found
292
+ end
293
+ found = File.expand_path(found);
294
+ end
295
+ puts 'found new loc:' + lib + '=>' + found if $FAST_REQUIRE_DEBUG
296
+ @@require_locs[lib] = found
297
+ @@already_loaded[found] = true
298
+ return true
299
+ else
300
+
301
+ # this is expected if it's for libraries required before faster_require was [like rbconfig]
302
+ # raise 'actually expected' + lib if RUBY_VERSION >= '1.9.0'
303
+ puts 'already loaded, apparently [require returned false], trying to discover how it was redundant... ' + lib if $FAST_REQUIRE_DEBUG
304
+ # this probably was something like
305
+ # the first pass was require 'regdeferred'
306
+ # now it's a different require 'regdeferred.rb'
307
+ # which fails (or vice versa)
308
+ # so figure out why
309
+ # calc location, expand, map back
310
+ where_found = FastRequire.guess_discover(lib, true)
311
+ if where_found
312
+ puts 'inferred lib loc:' + lib + '=>' + where_found if $FAST_REQUIRE_DEBUG
313
+ @@require_locs[lib] = where_found
314
+ # unfortunately if it's our first pass
315
+ # and we are in the middle of a "real" require
316
+ # that is circular
317
+ # then $LOADED_FEATURES or (AFAIK) nothing will have been set
318
+ # for us to be able to assert that
319
+ # so...I think we'll end up
320
+ # just fudging for a bit
321
+ # raise 'not found' unless @@already_loaded[where_found] # should have already been set...I think...
322
+ else
323
+ if $FAST_REQUIRE_DEBUG
324
+ # happens for enumerator XXXX
325
+ puts 'unable to infer ' + lib + ' location' if $FAST_REQUIRE_DEBUG
326
+ @@already_loaded[found] = true # so hacky...
327
+ end
328
+ end
329
+ return false # XXXX test all these return values
330
+ end
331
+ end
332
+ ensure
333
+ raise 'huh' unless ALL_IN_PROCESS.pop[0] == lib
334
+ end
335
+ end
336
+
337
+ end
338
+
339
+ module Kernel
340
+
341
+ # overwrite old require...
342
+ include FastRequire
343
+ if defined?(gem_original_require)
344
+ class << self
345
+ alias :original_remove_method :remove_method
346
+
347
+ def remove_method method # I think this actually might be needed <sigh>
348
+ if method.to_s == 'require'
349
+ #p 'not removing old require, since that\'s ours now'
350
+ else
351
+ original_remove_method method
352
+ end
353
+ end
354
+
355
+ end
356
+
357
+ # similarly overwrite this one...I guess...1.9.x...rubygems uses this as its default...I think...
358
+ alias :original_non_cached_require :gem_original_require
359
+ alias :gem_original_require :require_cached
360
+ else
361
+ alias :original_non_cached_require :require
362
+ alias :require :require_cached
363
+ end
364
+ end
365
+
366
366
  end
metadata CHANGED
@@ -1,183 +1,202 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: faster_require
3
- version: !ruby/object:Gem::Version
4
- hash: 63
5
- prerelease:
6
- segments:
7
- - 0
8
- - 9
9
- - 2
10
- version: 0.9.2
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.9.3
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Roger Pack
14
9
  - faisal
15
- autorequire:
10
+ autorequire:
16
11
  bindir: bin
17
12
  cert_chain: []
18
-
19
- date: 2011-04-25 00:00:00 Z
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
13
+ date: 2012-12-03 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
22
16
  name: redparse
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
17
+ version_requirements: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: !binary |-
22
+ MA==
23
+ none: false
24
+ requirement: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ! '>='
27
+ - !ruby/object:Gem::Version
28
+ version: !binary |-
29
+ MA==
25
30
  none: false
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- hash: 3
30
- segments:
31
- - 0
32
- version: "0"
31
+ prerelease: false
33
32
  type: :development
34
- version_requirements: *id001
35
- - !ruby/object:Gem::Dependency
33
+ - !ruby/object:Gem::Dependency
36
34
  name: activesupport
37
- prerelease: false
38
- requirement: &id002 !ruby/object:Gem::Requirement
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - '='
38
+ - !ruby/object:Gem::Version
39
+ version: 2.3.10
39
40
  none: false
40
- requirements:
41
- - - "="
42
- - !ruby/object:Gem::Version
43
- hash: 23
44
- segments:
45
- - 2
46
- - 3
47
- - 10
41
+ requirement: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - '='
44
+ - !ruby/object:Gem::Version
48
45
  version: 2.3.10
46
+ none: false
47
+ prerelease: false
49
48
  type: :development
50
- version_requirements: *id002
51
- - !ruby/object:Gem::Dependency
49
+ - !ruby/object:Gem::Dependency
52
50
  name: actionpack
53
- prerelease: false
54
- requirement: &id003 !ruby/object:Gem::Requirement
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - '='
54
+ - !ruby/object:Gem::Version
55
+ version: 2.3.10
55
56
  none: false
56
- requirements:
57
- - - "="
58
- - !ruby/object:Gem::Version
59
- hash: 23
60
- segments:
61
- - 2
62
- - 3
63
- - 10
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
64
61
  version: 2.3.10
62
+ none: false
63
+ prerelease: false
65
64
  type: :development
66
- version_requirements: *id003
67
- - !ruby/object:Gem::Dependency
65
+ - !ruby/object:Gem::Dependency
68
66
  name: jeweler
69
- prerelease: false
70
- requirement: &id004 !ruby/object:Gem::Requirement
67
+ version_requirements: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ! '>='
70
+ - !ruby/object:Gem::Version
71
+ version: !binary |-
72
+ MA==
71
73
  none: false
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- hash: 3
76
- segments:
77
- - 0
78
- version: "0"
74
+ requirement: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: !binary |-
79
+ MA==
80
+ none: false
81
+ prerelease: false
79
82
  type: :development
80
- version_requirements: *id004
81
- - !ruby/object:Gem::Dependency
83
+ - !ruby/object:Gem::Dependency
82
84
  name: rspec
83
- prerelease: false
84
- requirement: &id005 !ruby/object:Gem::Requirement
85
+ version_requirements: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: !binary |-
90
+ Mg==
91
+ none: false
92
+ requirement: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ! '>='
95
+ - !ruby/object:Gem::Version
96
+ version: !binary |-
97
+ Mg==
85
98
  none: false
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- hash: 7
90
- segments:
91
- - 2
92
- version: "2"
99
+ prerelease: false
93
100
  type: :development
94
- version_requirements: *id005
95
- - !ruby/object:Gem::Dependency
101
+ - !ruby/object:Gem::Dependency
96
102
  name: sane
97
- prerelease: false
98
- requirement: &id006 !ruby/object:Gem::Requirement
103
+ version_requirements: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ! '>='
106
+ - !ruby/object:Gem::Version
107
+ version: !binary |-
108
+ MA==
99
109
  none: false
100
- requirements:
101
- - - ">="
102
- - !ruby/object:Gem::Version
103
- hash: 3
104
- segments:
105
- - 0
106
- version: "0"
110
+ requirement: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ! '>='
113
+ - !ruby/object:Gem::Version
114
+ version: !binary |-
115
+ MA==
116
+ none: false
117
+ prerelease: false
107
118
  type: :development
108
- version_requirements: *id006
109
- - !ruby/object:Gem::Dependency
119
+ - !ruby/object:Gem::Dependency
110
120
  name: facets
111
- prerelease: false
112
- requirement: &id007 !ruby/object:Gem::Requirement
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: !binary |-
126
+ MA==
127
+ none: false
128
+ requirement: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ! '>='
131
+ - !ruby/object:Gem::Version
132
+ version: !binary |-
133
+ MA==
113
134
  none: false
114
- requirements:
115
- - - ">="
116
- - !ruby/object:Gem::Version
117
- hash: 3
118
- segments:
119
- - 0
120
- version: "0"
135
+ prerelease: false
121
136
  type: :development
122
- version_requirements: *id007
123
- - !ruby/object:Gem::Dependency
137
+ - !ruby/object:Gem::Dependency
124
138
  name: ruby-prof
125
- prerelease: false
126
- requirement: &id008 !ruby/object:Gem::Requirement
139
+ version_requirements: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - ! '>='
142
+ - !ruby/object:Gem::Version
143
+ version: !binary |-
144
+ MA==
127
145
  none: false
128
- requirements:
129
- - - ">="
130
- - !ruby/object:Gem::Version
131
- hash: 3
132
- segments:
133
- - 0
134
- version: "0"
146
+ requirement: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - ! '>='
149
+ - !ruby/object:Gem::Version
150
+ version: !binary |-
151
+ MA==
152
+ none: false
153
+ prerelease: false
135
154
  type: :development
136
- version_requirements: *id008
137
- - !ruby/object:Gem::Dependency
155
+ - !ruby/object:Gem::Dependency
138
156
  name: rack-mount
139
- prerelease: false
140
- requirement: &id009 !ruby/object:Gem::Requirement
157
+ version_requirements: !ruby/object:Gem::Requirement
158
+ requirements:
159
+ - - '='
160
+ - !ruby/object:Gem::Version
161
+ version: 0.6.14
141
162
  none: false
142
- requirements:
143
- - - "="
144
- - !ruby/object:Gem::Version
145
- hash: 27
146
- segments:
147
- - 0
148
- - 6
149
- - 14
163
+ requirement: !ruby/object:Gem::Requirement
164
+ requirements:
165
+ - - '='
166
+ - !ruby/object:Gem::Version
150
167
  version: 0.6.14
168
+ none: false
169
+ prerelease: false
151
170
  type: :development
152
- version_requirements: *id009
153
- - !ruby/object:Gem::Dependency
171
+ - !ruby/object:Gem::Dependency
154
172
  name: rack
155
- prerelease: false
156
- requirement: &id010 !ruby/object:Gem::Requirement
173
+ version_requirements: !ruby/object:Gem::Requirement
174
+ requirements:
175
+ - - '='
176
+ - !ruby/object:Gem::Version
177
+ version: 1.2.2
157
178
  none: false
158
- requirements:
159
- - - "="
160
- - !ruby/object:Gem::Version
161
- hash: 27
162
- segments:
163
- - 1
164
- - 2
165
- - 2
179
+ requirement: !ruby/object:Gem::Requirement
180
+ requirements:
181
+ - - '='
182
+ - !ruby/object:Gem::Version
166
183
  version: 1.2.2
184
+ none: false
185
+ prerelease: false
167
186
  type: :development
168
- version_requirements: *id010
169
187
  description: A tool designed to speedup library loading (startup time) in Ruby by caching library locations
170
188
  email: rogerdpack@gmail.com
171
- executables:
189
+ executables:
172
190
  - faster_require
173
191
  extensions: []
174
-
175
- extra_rdoc_files:
192
+ extra_rdoc_files:
176
193
  - ChangeLog
194
+ - LICENSE
177
195
  - README
178
196
  - TODO
179
- files:
197
+ files:
180
198
  - ChangeLog
199
+ - LICENSE
181
200
  - README
182
201
  - Rakefile
183
202
  - VERSION
@@ -219,63 +238,28 @@ files:
219
238
  - TODO
220
239
  homepage: http://github.com/rdp/faster_require
221
240
  licenses: []
222
-
223
- post_install_message:
241
+ post_install_message:
224
242
  rdoc_options: []
225
-
226
- require_paths:
243
+ require_paths:
227
244
  - lib
228
- required_ruby_version: !ruby/object:Gem::Requirement
245
+ required_ruby_version: !ruby/object:Gem::Requirement
246
+ requirements:
247
+ - - ! '>='
248
+ - !ruby/object:Gem::Version
249
+ version: !binary |-
250
+ MA==
229
251
  none: false
230
- requirements:
231
- - - ">="
232
- - !ruby/object:Gem::Version
233
- hash: 3
234
- segments:
235
- - 0
236
- version: "0"
237
- required_rubygems_version: !ruby/object:Gem::Requirement
252
+ required_rubygems_version: !ruby/object:Gem::Requirement
253
+ requirements:
254
+ - - ! '>='
255
+ - !ruby/object:Gem::Version
256
+ version: !binary |-
257
+ MA==
238
258
  none: false
239
- requirements:
240
- - - ">="
241
- - !ruby/object:Gem::Version
242
- hash: 3
243
- segments:
244
- - 0
245
- version: "0"
246
259
  requirements: []
247
-
248
- rubyforge_project:
249
- rubygems_version: 1.7.2
250
- signing_key:
260
+ rubyforge_project:
261
+ rubygems_version: 1.8.24
262
+ signing_key:
251
263
  specification_version: 3
252
264
  summary: Speed library loading in Ruby
253
- test_files:
254
- - spec/files/a_requires_b.rb
255
- - spec/files/active_support_no_double_load.rb
256
- - spec/files/attempt_double_load.rb
257
- - spec/files/attempt_double_load_wrong_version.rb
258
- - spec/files/b.rb
259
- - spec/files/c.rb
260
- - spec/files/d.rb
261
- - spec/files/e.rb
262
- - spec/files/fast.rb
263
- - spec/files/fast2.rb
264
- - spec/files/file_that_sets_ignore_pwd_flag.rb
265
- - spec/files/gem_after.rb
266
- - spec/files/gem_before.rb
267
- - spec/files/large.rb
268
- - spec/files/load_various_gems.rb
269
- - spec/files/load_various_gems2.rb
270
- - spec/files/non_dot_rb.rb
271
- - spec/files/regin_gem.rb
272
- - spec/files/require_facets.rb
273
- - spec/files/require_full_path.rb
274
- - spec/files/require_non_dot_rb_fails.rb
275
- - spec/files/require_twice_in_dir_pwd.rb
276
- - spec/files/requires_itself.rb
277
- - spec/files/should_put_modules_in_right_place.rb
278
- - spec/files/slow.rb
279
- - spec/files/socket_load.rb
280
- - spec/files/time_just_loading_rubygems.rb
281
- - spec/spec.fast_require.rb
265
+ test_files: []