faster_path 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -5
- data/Rakefile +1 -1
- data/lib/faster_path.rb +4 -1
- data/lib/faster_path/version.rb +1 -1
- data/src/basename_for_chop.rs +15 -0
- data/src/dirname_for_chop.rs +25 -0
- data/src/lib.rs +2 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: db825eef6d7393b150a108c97a668088a0d403e7
|
4
|
+
data.tar.gz: 54ed210ae569bd548c3f6233e4f11b9d6d678688
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0425ba04eb0e8579dc55b3d1c8b9a9ab30cbba96d548d7d8f52fe97ea2bcb2c66fa8a092ff1883c260ddefa071beb9453b6a2f99d54b1cf6a529a08837055c22
|
7
|
+
data.tar.gz: 3c4bcf0268e0ac6e74f487880081e60f367f56b8919e0b12348b9a194374bea01cb9c86c55ca8e5ec4c92a5c57ade1365b1021f23a34d7fb93f60568dace080a
|
data/README.md
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
[![Build Status](https://travis-ci.org/danielpclark/faster_path.svg?branch=master)](https://travis-ci.org/danielpclark/faster_path)
|
4
4
|
[![Tweet This](https://raw.githubusercontent.com/danielpclark/faster_path/master/assets/tweet.png)](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%20load%20time%20by%20switching%20to%20the%20FasterPath%20gem.)
|
5
5
|
|
6
|
-
#### As of gem version 0.0.9 this shaves off 66% of my Rails applications load time.
|
6
|
+
#### As of gem version 0.0.9 this shaves off 66% of my Rails applications page load time.
|
7
7
|
|
8
8
|
The primary **GOAL** of this project is to improve performance in the most heavily used areas of Ruby as
|
9
9
|
path relation and file lookup is currently a huge bottleneck in performance. As this is the case the
|
@@ -14,9 +14,6 @@ Users will have the option to write their apps directly for this library, or the
|
|
14
14
|
refine or monkeypatch the existing standard library. Refinements are narrowed to scope and monkeypatching will
|
15
15
|
be a sledge hammer ;-)
|
16
16
|
|
17
|
-
**NOTE**: Refinements and monkeypatch methods are highly likely to be changed and renamed pre version
|
18
|
-
0.1.0 so keep that in mind!
|
19
|
-
|
20
17
|
## Why
|
21
18
|
|
22
19
|
I did a check on Rails on what methods were being called the most and where the application spend
|
@@ -70,7 +67,7 @@ curl -sSf https://static.rust-lang.org/rustup.sh | sudo sh -s -- --channel=night
|
|
70
67
|
Add this line to your application's Gemfile:
|
71
68
|
|
72
69
|
```ruby
|
73
|
-
gem 'faster_path'
|
70
|
+
gem 'faster_path', '~> 0.1.0'
|
74
71
|
```
|
75
72
|
|
76
73
|
And then execute:
|
data/Rakefile
CHANGED
data/lib/faster_path.rb
CHANGED
@@ -8,6 +8,7 @@ module FasterPath
|
|
8
8
|
Rust.is_absolute(pth)
|
9
9
|
end
|
10
10
|
|
11
|
+
# Spec to Pathname#relative?
|
11
12
|
def self.relative?(pth)
|
12
13
|
Rust.is_relative(pth)
|
13
14
|
end
|
@@ -17,7 +18,7 @@ module FasterPath
|
|
17
18
|
# This implementation correctly handles blank strings just as Pathname had intended
|
18
19
|
# to handle non-path strings.
|
19
20
|
def self.chop_basename(pth)
|
20
|
-
d,b = [Rust.
|
21
|
+
d,b = [Rust.dirname_for_chop(pth), Rust.basename_for_chop(pth)]
|
21
22
|
[d,b] unless Rust.both_are_blank(d,b)
|
22
23
|
end
|
23
24
|
|
@@ -53,6 +54,8 @@ module FasterPath
|
|
53
54
|
attach_function :both_are_blank, [ :string, :string ], :bool
|
54
55
|
attach_function :basename, [ :string ], :string
|
55
56
|
attach_function :dirname, [ :string ], :string
|
57
|
+
attach_function :basename_for_chop, [ :string ], :string # decoupling behavior
|
58
|
+
attach_function :dirname_for_chop, [ :string ], :string # decoupling behavior
|
56
59
|
|
57
60
|
# EXAMPLE
|
58
61
|
#attach_function :one_and_two, [], FromRustArray.by_value
|
data/lib/faster_path/version.rb
CHANGED
@@ -0,0 +1,15 @@
|
|
1
|
+
#[no_mangle]
|
2
|
+
pub extern fn basename_for_chop(string: *const c_char) -> *const c_char {
|
3
|
+
let c_str = unsafe {
|
4
|
+
assert!(!string.is_null());
|
5
|
+
|
6
|
+
CStr::from_ptr(string)
|
7
|
+
};
|
8
|
+
|
9
|
+
let r_str = str::from_utf8(c_str.to_bytes()).unwrap();
|
10
|
+
|
11
|
+
let part = Path::new(r_str).file_name().unwrap_or(OsStr::new("")).to_str();
|
12
|
+
|
13
|
+
let output = CString::new(format!("{}", part.unwrap())).unwrap();
|
14
|
+
output.into_raw()
|
15
|
+
}
|
@@ -0,0 +1,25 @@
|
|
1
|
+
#[no_mangle]
|
2
|
+
pub extern fn dirname_for_chop(string: *const c_char) -> *const c_char {
|
3
|
+
let c_str = unsafe {
|
4
|
+
assert!(!string.is_null());
|
5
|
+
|
6
|
+
CStr::from_ptr(string)
|
7
|
+
};
|
8
|
+
|
9
|
+
let r_str = str::from_utf8(c_str.to_bytes()).unwrap();
|
10
|
+
|
11
|
+
if r_str.is_empty() {
|
12
|
+
return string
|
13
|
+
}
|
14
|
+
|
15
|
+
let path = Path::new(r_str).parent().unwrap_or(Path::new(""));
|
16
|
+
|
17
|
+
let out_str = if !path.to_str().unwrap().is_empty() {
|
18
|
+
format!("{}{}", path.to_str().unwrap(), MAIN_SEPARATOR)
|
19
|
+
} else {
|
20
|
+
format!("{}", path.to_str().unwrap())
|
21
|
+
};
|
22
|
+
|
23
|
+
let output = CString::new(out_str).unwrap();
|
24
|
+
output.into_raw()
|
25
|
+
}
|
data/src/lib.rs
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.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel P. Clark
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-06-
|
11
|
+
date: 2016-06-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ffi
|
@@ -105,8 +105,10 @@ files:
|
|
105
105
|
- lib/faster_path/optional/refinements.rb
|
106
106
|
- lib/faster_path/version.rb
|
107
107
|
- src/basename.rs
|
108
|
+
- src/basename_for_chop.rs
|
108
109
|
- src/both_are_blank.rs
|
109
110
|
- src/dirname.rs
|
111
|
+
- src/dirname_for_chop.rs
|
110
112
|
- src/is_absolute.rs
|
111
113
|
- src/is_blank.rs
|
112
114
|
- src/is_relative.rs
|