fast_blank 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +5 -0
  3. data/benchmark +17 -0
  4. data/ext/fast_blank/fast_blank.c +36 -25
  5. metadata +7 -20
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 23b988d318c1c1da6a788a6d0c3b1f7f0f65e6ca
4
- data.tar.gz: ba4ef389e4cebb24ba9ac8e1fc8c5d263b817d94
3
+ metadata.gz: 171bfb8d6bbf40369a5b4e1135ca2bca72950173
4
+ data.tar.gz: beadd5011d64a71bba5c435c91a1c4d0983794a4
5
5
  SHA512:
6
- metadata.gz: 88222e2184cf6394fd34fb5840e8ca30013e68cac6ea2f0a5408252eafe97a121db72baa42ec10bee14d7ae1ccced2f66974fcfa76c3d999f989050fe183b118
7
- data.tar.gz: 74e3a6270528702e72428564215614a81564e2a475dfe797db27ebb5780d9cb8e452f7fc458767cbfea9a127de0ab6607879733bbee6e8916c8ac72231c55693
6
+ metadata.gz: 3c9aef69d8f30162ec6b9aeb195fc9e4c6fb37e57def7a3db12ac791554cfd1321e6445521cb419d0c498ca67409fcdd58fa380c1da91e85d793caeab06db2cf
7
+ data.tar.gz: 5ddd68f7bbfdbc6f18304ff31968a434e17438c68fde5bddd0deb758427b3e31bceb06a9cb672e9ebe275122bec23dbbebc77c08d210b143f4040514d9d90f66
data/README.md CHANGED
@@ -53,5 +53,10 @@ Author: Sam Saffron sam.saffron@gmail.com
53
53
  http://github.com/SamSaffron/fast_blank
54
54
  License: MIT
55
55
 
56
+ ### Change log:
57
+
58
+ 0.0.2:
59
+ - Removed rake dependency (tmm1)
60
+ - Unrolled internal loop to improve perf (tmm1)
56
61
 
57
62
  (gem template based on https://github.com/CodeMonkeySteve/fast_xor )
data/benchmark CHANGED
@@ -38,3 +38,20 @@ Benchmark.bmbm do |x|
38
38
  #x.report("Empty #{s.length} :") do n.times { s.empty? } end
39
39
  end
40
40
  end
41
+
42
+ user system total real
43
+ # Fast Blank 0 : 0.050000 0.000000 0.050000 ( 0.048928)
44
+ # Fast Blank (Active Support) 0 : 0.050000 0.000000 0.050000 ( 0.049967)
45
+ # Slow Blank 0 : 0.290000 0.000000 0.290000 ( 0.295086)
46
+ # Fast Blank 6 : 0.090000 0.000000 0.090000 ( 0.089295)
47
+ # Fast Blank (Active Support) 6 : 0.090000 0.000000 0.090000 ( 0.089648)
48
+ # Slow Blank 6 : 0.420000 0.000000 0.420000 ( 0.418375)
49
+ # Fast Blank 14 : 0.060000 0.000000 0.060000 ( 0.056642)
50
+ # Fast Blank (Active Support) 14 : 0.060000 0.000000 0.060000 ( 0.061443)
51
+ # Slow Blank 14 : 0.670000 0.000000 0.670000 ( 0.668229)
52
+ # Fast Blank 24 : 0.070000 0.000000 0.070000 ( 0.075878)
53
+ # Fast Blank (Active Support) 24 : 0.090000 0.000000 0.090000 ( 0.088610)
54
+ # Slow Blank 24 : 0.650000 0.000000 0.650000 ( 0.650736)
55
+ # Fast Blank 136 : 0.070000 0.000000 0.070000 ( 0.075540)
56
+ # Fast Blank (Active Support) 136 : 0.090000 0.000000 0.090000 ( 0.087240)
57
+ # Slow Blank 136 : 0.660000 0.000000 0.660000 ( 0.655168)
@@ -13,19 +13,11 @@
13
13
  #define RSTRING_LEN(s) (RSTRING(s)->len)
14
14
  #endif
15
15
 
16
- const unsigned int as_blank[26] = {9, 0xa, 0xb, 0xc, 0xd,
17
- 0x20, 0x85, 0xa0, 0x1680, 0x180e, 0x2000, 0x2001,
18
- 0x2002, 0x2003, 0x2004, 0x2005, 0x2006, 0x2007, 0x2008,
19
- 0x2009, 0x200a, 0x2028, 0x2029, 0x202f, 0x205f, 0x3000
20
- };
21
-
22
16
  static VALUE
23
17
  rb_str_blank_as(VALUE str)
24
18
  {
25
19
  rb_encoding *enc;
26
20
  char *s, *e;
27
- int i;
28
- int found;
29
21
 
30
22
  enc = STR_ENC_GET(str);
31
23
  s = RSTRING_PTR(str);
@@ -33,22 +25,41 @@ rb_str_blank_as(VALUE str)
33
25
 
34
26
  e = RSTRING_END(str);
35
27
  while (s < e) {
36
- int n;
37
- unsigned int cc = rb_enc_codepoint_len(s, e, &n, enc);
28
+ int n;
29
+ unsigned int cc = rb_enc_codepoint_len(s, e, &n, enc);
38
30
 
39
- found = 0;
40
- for(i=0;i<26;i++){
41
- unsigned int current = as_blank[i];
42
- if(current == cc) {
43
- found = 1;
44
- break;
45
- }
46
- if(cc < current){
47
- break;
48
- }
31
+ switch (cc) {
32
+ case 9:
33
+ case 0xa:
34
+ case 0xb:
35
+ case 0xc:
36
+ case 0xd:
37
+ case 0x20:
38
+ case 0x85:
39
+ case 0xa0:
40
+ case 0x1680:
41
+ case 0x180e:
42
+ case 0x2000:
43
+ case 0x2001:
44
+ case 0x2002:
45
+ case 0x2003:
46
+ case 0x2004:
47
+ case 0x2005:
48
+ case 0x2006:
49
+ case 0x2007:
50
+ case 0x2008:
51
+ case 0x2009:
52
+ case 0x200a:
53
+ case 0x2028:
54
+ case 0x2029:
55
+ case 0x202f:
56
+ case 0x205f:
57
+ case 0x3000:
58
+ /* found */
59
+ break;
60
+ default:
61
+ return Qfalse;
49
62
  }
50
-
51
- if (!found) return Qfalse;
52
63
  s += n;
53
64
  }
54
65
  return Qtrue;
@@ -66,10 +77,10 @@ rb_str_blank(VALUE str)
66
77
 
67
78
  e = RSTRING_END(str);
68
79
  while (s < e) {
69
- int n;
70
- unsigned int cc = rb_enc_codepoint_len(s, e, &n, enc);
80
+ int n;
81
+ unsigned int cc = rb_enc_codepoint_len(s, e, &n, enc);
71
82
 
72
- if (!rb_isspace(cc) && cc != 0) return Qfalse;
83
+ if (!rb_isspace(cc) && cc != 0) return Qfalse;
73
84
  s += n;
74
85
  }
75
86
  return Qtrue;
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fast_blank
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
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-03-29 00:00:00.000000000 Z
11
+ date: 2013-11-22 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: rake
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - '>='
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - '>='
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: rake-compiler
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -31,7 +17,7 @@ dependencies:
31
17
  - - '>='
32
18
  - !ruby/object:Gem::Version
33
19
  version: '0'
34
- type: :runtime
20
+ type: :development
35
21
  prerelease: false
36
22
  version_requirements: !ruby/object:Gem::Requirement
37
23
  requirements:
@@ -66,8 +52,9 @@ files:
66
52
  - ext/fast_blank/fast_blank.c
67
53
  - ext/fast_blank/extconf.rb
68
54
  - spec/fast_blank_spec.rb
69
- homepage: ''
70
- licenses: []
55
+ homepage: https://github.com/SamSaffron/fast_blank
56
+ licenses:
57
+ - MIT
71
58
  metadata: {}
72
59
  post_install_message:
73
60
  rdoc_options: []
@@ -85,7 +72,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
85
72
  version: '0'
86
73
  requirements: []
87
74
  rubyforge_project:
88
- rubygems_version: 2.0.2
75
+ rubygems_version: 2.0.3
89
76
  signing_key:
90
77
  specification_version: 4
91
78
  summary: Fast String blank? implementation