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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1a58736ba26f8da66798e1d880b69f41024b781d
4
- data.tar.gz: 178bc067336654653eb2447423710968a4734331
3
+ metadata.gz: db825eef6d7393b150a108c97a668088a0d403e7
4
+ data.tar.gz: 54ed210ae569bd548c3f6233e4f11b9d6d678688
5
5
  SHA512:
6
- metadata.gz: 23661f4030527974dcaf48551e2c2865a00deb0fce02559bf904fa7e41286e76e66fa85cc4bd085bf8d375187b4b1a89b0c2580b9652b2bfabdfdbff8d562670
7
- data.tar.gz: fac99ce8064997efdd227ec2154557c6ccae0c78a38c6e5b31a4031302b3f42a695da9419a608cdc89a7075f2127f0d24bce1a83a574889900545f19bcb7d855
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
@@ -17,7 +17,7 @@ task :clean_src do
17
17
  Dir.
18
18
  glob('target/release/*').
19
19
  keep_if {|f|
20
- !f[/\.(?:so|dll|dylib)\z/]
20
+ !f[/\.(?:so|dll|dylib|deps)\z/]
21
21
  }
22
22
  )
23
23
  end
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.dirname(pth), Rust.basename(pth)]
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
@@ -1,3 +1,3 @@
1
1
  module FasterPath
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -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
@@ -20,6 +20,8 @@ include!("is_blank.rs");
20
20
  include!("both_are_blank.rs");
21
21
  include!("basename.rs");
22
22
  include!("dirname.rs");
23
+ include!("basename_for_chop.rs");
24
+ include!("dirname_for_chop.rs");
23
25
 
24
26
  // EXAMPLE
25
27
  //
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.0
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-13 00:00:00.000000000 Z
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