faster_path 0.1.10 → 0.1.11
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.
- checksums.yaml +4 -4
- data/Gemfile +4 -1
- data/README.md +9 -3
- data/Rakefile +12 -4
- data/ext/faster_path/extconf.rb +3 -3
- data/faster_path.gemspec +5 -4
- data/lib/faster_path.rb +8 -7
- data/lib/faster_path/asset_resolution.rb +59 -0
- data/lib/faster_path/optional/monkeypatches.rb +52 -42
- data/lib/faster_path/optional/refinements.rb +1 -1
- data/lib/faster_path/version.rb +1 -1
- metadata +19 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ff5facbf74ee4f0f136736a30ac47a525f6eb39b
|
4
|
+
data.tar.gz: 0a9ef741f3fce8b6786f2917fda4f43d2e81e185
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1b2b36657e420010b1cf931bb6e0ba75299277689cd2f84ca0e04b1b8b2e8d02ca00ffc0f3a39b27f1ea1b8451082caf26fb3a158f54eea8119081c63c0bb30f
|
7
|
+
data.tar.gz: 111d7bf455b8db96f55f5f5b664d876ede2bb78b163e21672162a58c751c32d6328b2cb2340ffeaa1de561e3f114fd9417f93f9ffb147bd97ce1f24bfcb3dd91
|
data/Gemfile
CHANGED
@@ -1,11 +1,14 @@
|
|
1
1
|
source 'https://rubygems.org' do
|
2
2
|
# Specify your gem's dependencies in faster_path.gemspec
|
3
3
|
gemspec
|
4
|
+
group :test do
|
5
|
+
gem 'coveralls', require: false
|
6
|
+
end
|
4
7
|
end
|
5
8
|
|
6
9
|
begin
|
7
10
|
# https://github.com/ruby/spec dependencies
|
8
|
-
eval_gemfile File.expand_path('spec/ruby_spec/Gemfile', File.dirname(__FILE__))
|
11
|
+
eval_gemfile File.expand_path('spec/ruby_spec/Gemfile', File.dirname(__FILE__))
|
9
12
|
rescue
|
10
13
|
`git submodule update --init`
|
11
14
|
eval_gemfile File.expand_path('spec/ruby_spec/Gemfile', File.dirname(__FILE__))
|
data/README.md
CHANGED
@@ -1,8 +1,14 @@
|
|
1
1
|
# FasterPath
|
2
2
|
[](https://badge.fury.io/rb/faster_path)
|
3
|
-
[](https://travis-ci.org/danielpclark/faster_path)
|
3
|
+
[](https://travis-ci.org/danielpclark/faster_path)
|
4
|
+
[](https://ci.appveyor.com/project/danielpclark/faster-path/branch/master)
|
5
|
+
[](https://github.com/danielpclark/faster_path/tags)
|
6
|
+
[](https://github.com/danielpclark/faster_path/pulse)
|
7
|
+
[](https://github.com/danielpclark/faster_path/releases)
|
8
|
+
[](https://coveralls.io/github/danielpclark/faster_path)
|
9
|
+
[](http://inch-ci.org/github/danielpclark/faster_path)
|
10
|
+
[](https://www.codetriage.com/danielpclark/faster_path)
|
4
11
|
[](https://twitter.com/share?url=https%3A%2F%2Fgithub.com%2Fdanielpclark%2Ffaster_path&via=6ftdan&hashtags=Ruby&text=You%20could%20save%2015%25%20or%20more%20on%20website%20page%20load%20time%20by%20switching%20to%20the%20FasterPath%20gem.)
|
5
|
-
[New Wiki Up!](https://github.com/danielpclark/faster_path/wiki)
|
6
12
|
|
7
13
|
#### This gem shaves off more than 30% of my Rails application page load time.
|
8
14
|
|
@@ -176,7 +182,7 @@ FasterPath.sledgehammer_everything!
|
|
176
182
|
It's been my observation (and some others) that the Rust implementation of the C code for `File` has similar results but
|
177
183
|
performance seems to vary based on CPU cache on possibly 64bit/32bit system environmnets.
|
178
184
|
|
179
|
-
**Developers for FasterPath:** Most of these need to be rewritten, please use `WITH_REGRESSION` in your testing. You can see the resulting failures currently on TravisCI under "Allow Failures".
|
185
|
+
**Developers for FasterPath:** Most of these need to be rewritten, please use `WITH_REGRESSION=true TEST_MONKEYPATCHES=true` in your testing. You can see the resulting failures currently on TravisCI under "Allow Failures".
|
180
186
|
|
181
187
|
## Getting Started with Development
|
182
188
|
|
data/Rakefile
CHANGED
@@ -5,7 +5,7 @@ require 'fileutils'
|
|
5
5
|
desc "Build Rust extension"
|
6
6
|
task :build_src do
|
7
7
|
puts "Building extension..."
|
8
|
-
|
8
|
+
sh "cargo build --release"
|
9
9
|
end
|
10
10
|
|
11
11
|
desc "Clean up Rust build"
|
@@ -16,9 +16,9 @@ task :clean_src do
|
|
16
16
|
rm_rf(
|
17
17
|
Dir.
|
18
18
|
glob('target/release/*').
|
19
|
-
keep_if
|
19
|
+
keep_if do |f|
|
20
20
|
!f[/\.(?:so|dll|dylib|deps)\z/]
|
21
|
-
|
21
|
+
end
|
22
22
|
)
|
23
23
|
end
|
24
24
|
|
@@ -27,13 +27,21 @@ task build_lib: [:build_src, :clean_src] do
|
|
27
27
|
puts "Completed build!"
|
28
28
|
end
|
29
29
|
|
30
|
+
desc "Code Quality Check"
|
31
|
+
task :lint do
|
32
|
+
puts
|
33
|
+
puts "Quality check starting..."
|
34
|
+
sh "rubocop"
|
35
|
+
puts
|
36
|
+
end
|
37
|
+
|
30
38
|
Rake::TestTask.new(minitest: :build_lib) do |t|
|
31
39
|
t.libs << "test"
|
32
40
|
t.libs << "lib"
|
33
41
|
t.test_files = FileList['test/**/*_test.rb']
|
34
42
|
end
|
35
43
|
|
36
|
-
task :
|
44
|
+
task test: [:minitest, :lint] do |_t|
|
37
45
|
exec 'mspec --format spec core/file/basename core/file/extname core/file/dirname library/pathname'
|
38
46
|
end
|
39
47
|
|
data/ext/faster_path/extconf.rb
CHANGED
@@ -8,12 +8,12 @@ unless find_executable('cargo')
|
|
8
8
|
puts
|
9
9
|
puts "curl -sSf https://static.rust-lang.org/rustup.sh | sudo sh -s -- --channel=nightly"
|
10
10
|
puts
|
11
|
-
|
11
|
+
at_exit { puts "Exiting..."}
|
12
12
|
end
|
13
13
|
|
14
14
|
Dir.chdir(File.expand_path("../../", File.dirname(__FILE__))) do
|
15
|
-
|
16
|
-
|
15
|
+
`rake build_src`
|
16
|
+
`rake clean_src`
|
17
17
|
end
|
18
18
|
|
19
19
|
create_makefile('faster_path/dummy')
|
data/faster_path.gemspec
CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = FasterPath::VERSION
|
9
9
|
spec.authors = ["Daniel P. Clark"]
|
10
10
|
spec.email = ["6ftdan@gmail.com"]
|
11
|
-
spec.summary =
|
12
|
-
spec.description =
|
11
|
+
spec.summary = 'Reimplementation of Pathname for better performance'
|
12
|
+
spec.description = 'FasterPath is a reimplementation of Pathname for better performance.'
|
13
13
|
spec.homepage = "https://github.com/danielpclark/faster_path"
|
14
14
|
spec.license = "MIT OR Apache-2.0"
|
15
15
|
|
@@ -30,8 +30,9 @@ Gem::Specification.new do |spec|
|
|
30
30
|
spec.add_development_dependency "method_source", "~> 0.8.2"
|
31
31
|
spec.add_development_dependency "minitest", "~> 5.10"
|
32
32
|
spec.add_development_dependency "minitest-reporters", "~> 1.1"
|
33
|
-
spec.add_development_dependency "color_pound_spec_reporter", "~> 0.0.
|
34
|
-
|
33
|
+
spec.add_development_dependency "color_pound_spec_reporter", "~> 0.0.9"
|
34
|
+
spec.add_development_dependency "rubocop", "~> 0.47"
|
35
|
+
unless ENV['CI']
|
35
36
|
spec.add_development_dependency "stop_watch", "~> 0.1.0"
|
36
37
|
spec.add_development_dependency "gruff", "~> 0.7.0"
|
37
38
|
end
|
data/lib/faster_path.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require "faster_path/version"
|
2
2
|
require 'pathname'
|
3
3
|
require "ffi"
|
4
|
+
require 'faster_path/asset_resolution'
|
4
5
|
|
5
6
|
module FasterPath
|
6
7
|
def self.rust_arch_bits
|
@@ -35,8 +36,9 @@ module FasterPath
|
|
35
36
|
# This implementation correctly handles blank strings just as Pathname had intended
|
36
37
|
# to handle non-path strings.
|
37
38
|
def self.chop_basename(pth)
|
38
|
-
d
|
39
|
-
|
39
|
+
d = Rust.dirname_for_chop(pth)
|
40
|
+
b = Rust.basename_for_chop(pth)
|
41
|
+
[d, b] unless Rust.both_are_blank(d, b)
|
40
42
|
end
|
41
43
|
|
42
44
|
def self.blank?(str)
|
@@ -64,16 +66,15 @@ module FasterPath
|
|
64
66
|
end
|
65
67
|
|
66
68
|
# EXAMPLE
|
67
|
-
#def self.one_and_two
|
69
|
+
# def self.one_and_two
|
68
70
|
# Rust.one_and_two.to_a
|
69
|
-
#end
|
71
|
+
# end
|
70
72
|
|
71
|
-
private
|
72
73
|
module Rust
|
73
74
|
extend FFI::Library
|
74
75
|
ffi_lib begin
|
75
76
|
prefix = Gem.win_platform? ? "" : "lib"
|
76
|
-
"#{File.expand_path("../target/release/",
|
77
|
+
"#{File.expand_path("../target/release/", __dir__)}/#{prefix}faster_path.#{FFI::Platform::LIBSUFFIX}"
|
77
78
|
end
|
78
79
|
|
79
80
|
class FromRustArray < FFI::Struct
|
@@ -101,7 +102,7 @@ module FasterPath
|
|
101
102
|
attach_function :entries, [ :string ], FromRustArray.by_value
|
102
103
|
|
103
104
|
# EXAMPLE
|
104
|
-
#attach_function :one_and_two, [], FromRustArray.by_value
|
105
|
+
# attach_function :one_and_two, [], FromRustArray.by_value
|
105
106
|
end
|
106
107
|
private_constant :Rust
|
107
108
|
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# This is a redundancy check for the rust compiled library needed for this gem.
|
2
|
+
# If the asset is not available and we can't compile it from this code then FAIL
|
3
|
+
# on require of 'faster_path' with a very clear message as to why."
|
4
|
+
|
5
|
+
module FasterPath
|
6
|
+
module AssetResolution # BREAK IN CASE OF EMERGENCY ;-)
|
7
|
+
class << self
|
8
|
+
def verify!
|
9
|
+
return lib_file if file?
|
10
|
+
|
11
|
+
if rust?
|
12
|
+
compile!
|
13
|
+
raise "Rust failed to compile asset! The dynamic library for this package was not found." unless file?
|
14
|
+
return lib_file
|
15
|
+
end
|
16
|
+
|
17
|
+
raise "The dynamic library for this package was not found nor was Rust's cargo executable found. This package will not work without it!"
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def compile!
|
23
|
+
require 'open3'
|
24
|
+
Dir.chdir(File.expand_path('../../', __dir__)) do
|
25
|
+
Open3.popen3("rake build_lib") do |stdin, stdout, stderr, wait_thr|
|
26
|
+
stdin.close
|
27
|
+
|
28
|
+
wait_thr && wait_thr.value.exitstatus
|
29
|
+
out = Thread.new { stdout.read }.value.strip
|
30
|
+
Thread.new { stderr.read }.value
|
31
|
+
out
|
32
|
+
end
|
33
|
+
end
|
34
|
+
File.exist? lib_file
|
35
|
+
end
|
36
|
+
|
37
|
+
def rust?
|
38
|
+
require 'mkmf'
|
39
|
+
MakeMakefile::Logging.instance_variable_set(:@log, File.open(File::NULL, 'w'))
|
40
|
+
MakeMakefile.instance_eval "undef :message; def message(*); end"
|
41
|
+
MakeMakefile.find_executable('cargo')
|
42
|
+
end
|
43
|
+
|
44
|
+
def file?
|
45
|
+
File.exist? lib_file
|
46
|
+
end
|
47
|
+
|
48
|
+
def lib_dir
|
49
|
+
File.expand_path("../../target/release/", __dir__)
|
50
|
+
end
|
51
|
+
|
52
|
+
def lib_file
|
53
|
+
prefix = Gem.win_platform? ? "" : "lib"
|
54
|
+
"#{lib_dir}/#{prefix}faster_path.#{FFI::Platform::LIBSUFFIX}"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
FasterPath::AssetResolution.verify! unless ENV['TEST']
|
@@ -1,53 +1,63 @@
|
|
1
1
|
require 'pathname'
|
2
2
|
|
3
3
|
module FasterPath
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
4
|
+
module MonkeyPatches
|
5
|
+
def self._ruby_core_file!
|
6
|
+
::File.class_eval do
|
7
|
+
def self.basename(pth, ext = '')
|
8
|
+
FasterPath.basename(pth, ext)
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.extname(pth)
|
12
|
+
FasterPath.extname(pth)
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.dirname(pth)
|
16
|
+
FasterPath.dirname(pth)
|
17
|
+
end
|
16
18
|
end if ENV['WITH_REGRESSION']
|
17
19
|
end
|
18
20
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
21
|
+
def self._ruby_library_pathname!
|
22
|
+
::Pathname.class_eval do
|
23
|
+
def absolute?
|
24
|
+
FasterPath.absolute?(@path)
|
25
|
+
end
|
26
|
+
|
27
|
+
def directory?
|
28
|
+
FasterPath.directory?(@path)
|
29
|
+
end
|
30
|
+
|
31
|
+
def chop_basename(pth)
|
32
|
+
FasterPath.chop_basename(pth)
|
33
|
+
end
|
34
|
+
private :chop_basename
|
35
|
+
|
36
|
+
def relative?
|
37
|
+
FasterPath.relative?(@path)
|
38
|
+
end
|
39
|
+
|
40
|
+
def add_trailing_separator(pth)
|
41
|
+
FasterPath.add_trailing_separator(pth)
|
42
|
+
end
|
43
|
+
private :add_trailing_separator
|
44
|
+
|
45
|
+
def has_trailing_separator?(pth)
|
46
|
+
FasterPath.has_trailing_separator?(pth)
|
47
|
+
end
|
48
|
+
private :has_trailing_separator?
|
49
|
+
|
50
|
+
def entries
|
51
|
+
FasterPath.entries(@path)
|
52
|
+
end
|
44
53
|
end
|
45
|
-
private :has_trailing_separator?
|
46
|
-
|
47
|
-
def entries
|
48
|
-
FasterPath.entries(@path)
|
49
|
-
end if ENV['WITH_REGRESSION']
|
50
54
|
end
|
55
|
+
end
|
56
|
+
private_constant :MonkeyPatches
|
57
|
+
|
58
|
+
def self.sledgehammer_everything!
|
59
|
+
MonkeyPatches._ruby_core_file!
|
60
|
+
MonkeyPatches._ruby_library_pathname!
|
51
61
|
"CAUTION: Monkey patching effects everything! Be very sure you want this!"
|
52
62
|
end
|
53
63
|
end
|
data/lib/faster_path/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: faster_path
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel P. Clark
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-03-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -100,14 +100,28 @@ dependencies:
|
|
100
100
|
requirements:
|
101
101
|
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: 0.0.
|
103
|
+
version: 0.0.9
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: 0.0.
|
110
|
+
version: 0.0.9
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rubocop
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0.47'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0.47'
|
111
125
|
- !ruby/object:Gem::Dependency
|
112
126
|
name: stop_watch
|
113
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -155,6 +169,7 @@ files:
|
|
155
169
|
- ext/faster_path/extconf.rb
|
156
170
|
- faster_path.gemspec
|
157
171
|
- lib/faster_path.rb
|
172
|
+
- lib/faster_path/asset_resolution.rb
|
158
173
|
- lib/faster_path/optional/monkeypatches.rb
|
159
174
|
- lib/faster_path/optional/refinements.rb
|
160
175
|
- lib/faster_path/version.rb
|