fast_blank 0.0.2 → 1.0.0

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: 171bfb8d6bbf40369a5b4e1135ca2bca72950173
4
- data.tar.gz: beadd5011d64a71bba5c435c91a1c4d0983794a4
3
+ metadata.gz: 5ccb1d100034d7f4b64f8b586a1936fa782bae23
4
+ data.tar.gz: ca1266f681fd9a599f5ce7439f19d11e12b7bc25
5
5
  SHA512:
6
- metadata.gz: 3c9aef69d8f30162ec6b9aeb195fc9e4c6fb37e57def7a3db12ac791554cfd1321e6445521cb419d0c498ca67409fcdd58fa380c1da91e85d793caeab06db2cf
7
- data.tar.gz: 5ddd68f7bbfdbc6f18304ff31968a434e17438c68fde5bddd0deb758427b3e31bceb06a9cb672e9ebe275122bec23dbbebc77c08d210b143f4040514d9d90f66
6
+ metadata.gz: 99af052c09364d2c1d69a53e948e3de398c831e023face6f6b0d0cd12d8a9f6572b5500ba4f38c136df070093cf99cc3dd986bb8ce9ede599bd7d0c65718c2b5
7
+ data.tar.gz: a4ed6e70604a61c11eea45a5bc723e28e77e15afc51149986bf67a11c27a380bb803f9047de560ee6ac65f6d605005367b24ce08d9f34179a909061dce21763e
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  ### String blank? Ruby Extension
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/fast_blank.png)](http://badge.fury.io/rb/fast_blank) [![Build Status](https://travis-ci.org/SamSaffron/fast_blank.png?branch=master)](https://travis-ci.org/SamSaffron/fast_blank)
4
+
3
5
  `fast_blank` is a simple extension which provides a fast implementation of active support's string#blank? function
4
6
 
5
7
  ### How do you use it?
@@ -39,7 +41,9 @@ Slow Blank 136 : 0.900000 0.000000 0.900000 ( 0.8998
39
41
  Additionally, this gem allocates no strings during the test, making it less of a GC burden.
40
42
 
41
43
 
42
- ###Compatability note:
44
+ ###Compatibility note:
45
+
46
+ fast_blank is supported under MRI Ruby 1.9.3, 2.0 and 2.1, earlier versions of MRI are untested.
43
47
 
44
48
  fast_blank implements string.blank? as MRI would have it implemented, meaning it has 100% parity with `String#strip.length == 0`.
45
49
 
data/benchmark CHANGED
@@ -6,7 +6,7 @@ require 'fast_blank'
6
6
  class String
7
7
  # active support implementation
8
8
  def slow_blank?
9
- self !~ /[^[:space:]]/
9
+ /\A[[:space:]]*\z/ === self
10
10
  end
11
11
  end
12
12
 
@@ -39,7 +39,7 @@ Benchmark.bmbm do |x|
39
39
  end
40
40
  end
41
41
 
42
- user system total real
42
+ # user system total real
43
43
  # Fast Blank 0 : 0.050000 0.000000 0.050000 ( 0.048928)
44
44
  # Fast Blank (Active Support) 0 : 0.050000 0.000000 0.050000 ( 0.049967)
45
45
  # Slow Blank 0 : 0.290000 0.000000 0.290000 ( 0.295086)
@@ -2,6 +2,7 @@
2
2
  #include <ruby.h>
3
3
  #include <ruby/encoding.h>
4
4
  #include <ruby/re.h>
5
+ #include <ruby/version.h>
5
6
 
6
7
  #define STR_ENC_GET(str) rb_enc_from_index(ENCODING_GET(str))
7
8
 
@@ -13,6 +14,17 @@
13
14
  #define RSTRING_LEN(s) (RSTRING(s)->len)
14
15
  #endif
15
16
 
17
+ static int
18
+ ruby_version_before_2_2()
19
+ {
20
+ #ifdef RUBY_API_VERSION_MAJOR
21
+ if (RUBY_API_VERSION_MAJOR > 2 || (RUBY_API_VERSION_MAJOR == 2 && RUBY_API_VERSION_MINOR >= 2)) {
22
+ return 0;
23
+ }
24
+ #endif
25
+ return 1;
26
+ }
27
+
16
28
  static VALUE
17
29
  rb_str_blank_as(VALUE str)
18
30
  {
@@ -38,7 +50,6 @@ rb_str_blank_as(VALUE str)
38
50
  case 0x85:
39
51
  case 0xa0:
40
52
  case 0x1680:
41
- case 0x180e:
42
53
  case 0x2000:
43
54
  case 0x2001:
44
55
  case 0x2002:
@@ -57,6 +68,8 @@ rb_str_blank_as(VALUE str)
57
68
  case 0x3000:
58
69
  /* found */
59
70
  break;
71
+ case 0x180e:
72
+ if (ruby_version_before_2_2()) break;
60
73
  default:
61
74
  return Qfalse;
62
75
  }
@@ -2,24 +2,23 @@ require 'fast_blank'
2
2
 
3
3
  class ::String
4
4
  def blank2?
5
- self !~ /[^[:space:]]/
5
+ /\A[[:space:]]*\z/ === self
6
6
  end
7
7
  end
8
8
 
9
9
  describe String do
10
10
  it "works" do
11
- "".blank?.should == true
12
- " ".blank?.should == true
13
- "\r\n".blank?.should == true
11
+ expect("".blank?).to eq(true)
12
+ expect(" ".blank?).to eq(true)
13
+ expect("\r\n".blank?).to eq(true)
14
14
  "\r\n\v\f\r\s\u0085".blank? == true
15
-
16
15
  end
17
16
 
18
17
  it "provides a parity with active support function" do
19
18
  (16*16*16*16).times do |i|
20
19
  c = i.chr('UTF-8') rescue nil
21
20
  unless c.nil?
22
- "#{i.to_s(16)} #{c.blank_as?}".should == "#{i.to_s(16)} #{c.blank2?}"
21
+ expect("#{i.to_s(16)} #{c.blank_as?}").to eq("#{i.to_s(16)} #{c.blank2?}")
23
22
  end
24
23
  end
25
24
 
@@ -27,7 +26,7 @@ describe String do
27
26
  (256).times do |i|
28
27
  c = i.chr('ASCII') rescue nil
29
28
  unless c.nil?
30
- "#{i.to_s(16)} #{c.blank_as?}".should == "#{i.to_s(16)} #{c.blank2?}"
29
+ expect("#{i.to_s(16)} #{c.blank_as?}").to eq("#{i.to_s(16)} #{c.blank2?}")
31
30
  end
32
31
  end
33
32
  end
@@ -36,16 +35,16 @@ describe String do
36
35
  (256).times do |i|
37
36
  c = i.chr('ASCII') rescue nil
38
37
  unless c.nil?
39
- "#{i.to_s(16)} #{c.strip.length == 0}".should == "#{i.to_s(16)} #{c.blank?}"
38
+ expect("#{i.to_s(16)} #{c.strip.length == 0}").to eq("#{i.to_s(16)} #{c.blank?}")
40
39
  end
41
40
  end
42
41
  end
43
42
 
44
43
  it "treats \u0000 correctly" do
45
44
  # odd I know
46
- "\u0000".strip.length.should == 0
47
- "\u0000".blank_as?.should be_false
48
- "\u0000".blank?.should be_true
45
+ expect("\u0000".strip.length).to eq(0)
46
+ expect("\u0000".blank_as?).to be_falsey
47
+ expect("\u0000".blank?).to be_truthy
49
48
  end
50
49
 
51
50
  end
metadata CHANGED
@@ -1,41 +1,41 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fast_blank
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Saffron
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-22 00:00:00.000000000 Z
11
+ date: 2015-08-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake-compiler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rspec
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  description: Provides a C-optimized method for determining if a string is blank
@@ -48,9 +48,9 @@ files:
48
48
  - MIT-LICENSE
49
49
  - README.md
50
50
  - benchmark
51
- - lib/.gemkeep
52
- - ext/fast_blank/fast_blank.c
53
51
  - ext/fast_blank/extconf.rb
52
+ - ext/fast_blank/fast_blank.c
53
+ - lib/.gemkeep
54
54
  - spec/fast_blank_spec.rb
55
55
  homepage: https://github.com/SamSaffron/fast_blank
56
56
  licenses:
@@ -62,17 +62,17 @@ require_paths:
62
62
  - lib
63
63
  required_ruby_version: !ruby/object:Gem::Requirement
64
64
  requirements:
65
- - - '>='
65
+ - - ">="
66
66
  - !ruby/object:Gem::Version
67
67
  version: '0'
68
68
  required_rubygems_version: !ruby/object:Gem::Requirement
69
69
  requirements:
70
- - - '>='
70
+ - - ">="
71
71
  - !ruby/object:Gem::Version
72
72
  version: '0'
73
73
  requirements: []
74
74
  rubyforge_project:
75
- rubygems_version: 2.0.3
75
+ rubygems_version: 2.4.5
76
76
  signing_key:
77
77
  specification_version: 4
78
78
  summary: Fast String blank? implementation