faster_path 0.1.3 → 0.1.4

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: b2f9feadf34476752439130f2871285f20bd67d5
4
- data.tar.gz: 184c00898cdca31bc822bf9c0023ca24f729c839
3
+ metadata.gz: 175d2f5deb162ae5b91fd8c6a78f3a4ec9f2c614
4
+ data.tar.gz: 85f78d5451c0e8b34bc00d282e08e6c7d84715ea
5
5
  SHA512:
6
- metadata.gz: 963c1a8874494f241daeb36c791c0136107be377df03739276b1e1c3b354a352616972c72ac137192cade9d8168ec5f863d1aaeb2c7974a949887f018652ce53
7
- data.tar.gz: f66e104da591aa1b690eedbc5dca48eb636c0cdb27d5d150b3425d67e6e6c568932cf0474fd80915fae6d477715af85337d54a93065561db9fb03d404d0910ee
6
+ metadata.gz: 62cdddd68edc6109686eda078a585038d8d3c1737330d025b0cf9b863f39696e4074a916c82ac331a7801e62a01a9138ff84d2c0c4e5e1ac4ad93a157dce548e
7
+ data.tar.gz: a66eb90ede0d919ba85c04714f2fa3412d7b8f6e099e933a50210c6f81f8a1cc94ede8805c498c5ba80ec1b2c56c9be1acdbe7cb8d4df34119ca0aa00d6b6eb5
data/README.md CHANGED
@@ -3,9 +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
- _Build is currently failing is for the monkey-patch tests only._
7
-
8
- #### As of gem version 0.0.9 this shaves off 66% of my Rails applications page load time.
6
+ #### This gem shaves off more than 30% of my Rails application page load time.
9
7
 
10
8
  The primary **GOAL** of this project is to improve performance in the most heavily used areas of Ruby as
11
9
  path relation and file lookup is currently a huge bottleneck in performance. As this is the case the
@@ -88,7 +86,7 @@ Current methods implemented:
88
86
  |---|---|:---:|
89
87
  | `FasterPath.absolute?` | `Pathname#absolute?` | 1234.6% |
90
88
  | `FasterPath.basename` | `File.basename` | 31.3% |
91
- | `FasterPath.chop_basename` | `Pathname#chop_basename` | 46.7% |
89
+ | `FasterPath.chop_basename` | `Pathname#chop_basename` | 66.0% |
92
90
  | `FasterPath.relative?` | `Pathname#relative?` | 1262.3% |
93
91
  | `FasterPath.blank?` | | |
94
92
 
@@ -1,3 +1,3 @@
1
1
  module FasterPath
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
data/src/basename.rs CHANGED
@@ -1,18 +1,10 @@
1
1
  #[allow(dead_code)]
2
2
  fn rubyish_basename(string: &str, globish_string: &str) -> String {
3
- let result = if globish_string.chars().next().unwrap_or("muffins".chars().next().unwrap()).eq(&".".chars().next().unwrap()) {
4
- if globish_string == ".*" {
5
- let base = string.rsplit_terminator(MAIN_SEPARATOR).nth(0).unwrap_or("");
6
- let index = base.rfind(".");
7
- let (first, _) = base.split_at(index.unwrap());
8
- first
9
- } else {
10
- if &string[string.len()-globish_string.len()..] == globish_string {
11
- &string[0..string.len()-globish_string.len()]
12
- } else {
13
- string
14
- }.rsplit_terminator(MAIN_SEPARATOR).nth(0).unwrap_or("")
15
- }
3
+ let result = if globish_string == ".*" {
4
+ let base = string.rsplit_terminator(MAIN_SEPARATOR).nth(0).unwrap_or("");
5
+ let index = base.rfind(".");
6
+ let (first, _) = base.split_at(index.unwrap());
7
+ first
16
8
  } else {
17
9
  if &string[string.len()-globish_string.len()..] == globish_string {
18
10
  &string[0..string.len()-globish_string.len()]
@@ -69,19 +61,11 @@ pub extern fn basename(str_pth: *const c_char, comp_ext: *const c_char) -> *cons
69
61
  let string = str::from_utf8(c_str1.to_bytes()).unwrap();
70
62
  let globish_string = str::from_utf8(c_str2.to_bytes()).unwrap();
71
63
 
72
- let result = if globish_string.chars().next().unwrap_or("muffins".chars().next().unwrap()).eq(&".".chars().next().unwrap()) {
73
- if globish_string == ".*" {
74
- let base = string.rsplit_terminator(MAIN_SEPARATOR).nth(0).unwrap_or("");
75
- let index = base.rfind(".");
76
- let (first, _) = base.split_at(index.unwrap());
77
- first
78
- } else {
79
- if &string[string.len()-globish_string.len()..] == globish_string {
80
- &string[0..string.len()-globish_string.len()]
81
- } else {
82
- string
83
- }.rsplit_terminator(MAIN_SEPARATOR).nth(0).unwrap_or("")
84
- }
64
+ let result = if globish_string == ".*" {
65
+ let base = string.rsplit_terminator(MAIN_SEPARATOR).nth(0).unwrap_or("");
66
+ let index = base.rfind(".");
67
+ let (first, _) = base.split_at(index.unwrap());
68
+ first
85
69
  } else {
86
70
  if &string[string.len()-globish_string.len()..] == globish_string {
87
71
  &string[0..string.len()-globish_string.len()]
@@ -8,8 +8,18 @@ pub extern fn basename_for_chop(string: *const c_char) -> *const c_char {
8
8
 
9
9
  let r_str = str::from_utf8(c_str.to_bytes()).unwrap();
10
10
 
11
- let part = Path::new(r_str).file_name().unwrap_or(OsStr::new("")).to_str();
11
+ let mut offset = 0;
12
+ let mut trailing_slashes = r_str.chars().rev();
13
+ loop {
14
+ match trailing_slashes.next() {
15
+ Some(MAIN_SEPARATOR) => { offset = offset + 1 },
16
+ _ => { break },
17
+ }
18
+ }
12
19
 
13
- let output = CString::new(format!("{}", part.unwrap())).unwrap();
20
+ let r_str = &r_str[0..r_str.len()-offset];
21
+ let part = r_str.rsplit_terminator(MAIN_SEPARATOR).nth(0).unwrap_or("");
22
+
23
+ let output = CString::new(part).unwrap();
14
24
  output.into_raw()
15
25
  }
@@ -12,14 +12,19 @@ pub extern fn dirname_for_chop(string: *const c_char) -> *const c_char {
12
12
  return string
13
13
  }
14
14
 
15
- let path = Path::new(r_str).parent().unwrap_or(Path::new(""));
15
+ let mut offset = 0;
16
+ let mut trailing_slashes = r_str.chars().rev();
17
+ loop {
18
+ match trailing_slashes.next() {
19
+ Some(MAIN_SEPARATOR) => { offset = offset + 1 },
20
+ _ => { break },
21
+ }
22
+ }
23
+
24
+ let r_str = &r_str[0..r_str.len()-offset];
16
25
 
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
- };
26
+ let base = r_str.rsplit_terminator(MAIN_SEPARATOR).nth(0).unwrap_or("");
22
27
 
23
- let output = CString::new(out_str).unwrap();
28
+ let output = CString::new(&r_str[0..r_str.len()-base.len()]).unwrap();
24
29
  output.into_raw()
25
30
  }
data/src/lib.rs CHANGED
@@ -8,7 +8,7 @@ extern crate libc;
8
8
 
9
9
  use std::path::{Path,MAIN_SEPARATOR};
10
10
  use libc::c_char;
11
- use std::ffi::{CStr,CString,OsStr};
11
+ use std::ffi::{CStr,CString};
12
12
  use std::str;
13
13
  use std::mem;
14
14
 
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.3
4
+ version: 0.1.4
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-15 00:00:00.000000000 Z
11
+ date: 2016-06-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi