From 7fca3dcd77a2697e766b074f5cbe68537463a145 Mon Sep 17 00:00:00 2001 From: Aman Gupta Date: Thu, 21 Nov 2013 14:05:08 -0800 Subject: [PATCH 1/4] fix indentation --- ext/fast_blank/fast_blank.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ext/fast_blank/fast_blank.c b/ext/fast_blank/fast_blank.c index d96f598..c7e7e90 100644 --- a/ext/fast_blank/fast_blank.c +++ b/ext/fast_blank/fast_blank.c @@ -33,8 +33,8 @@ rb_str_blank_as(VALUE str) e = RSTRING_END(str); while (s < e) { - int n; - unsigned int cc = rb_enc_codepoint_len(s, e, &n, enc); + int n; + unsigned int cc = rb_enc_codepoint_len(s, e, &n, enc); found = 0; for(i=0;i<26;i++){ @@ -48,7 +48,7 @@ rb_str_blank_as(VALUE str) } } - if (!found) return Qfalse; + if (!found) return Qfalse; s += n; } return Qtrue; @@ -66,10 +66,10 @@ rb_str_blank(VALUE str) e = RSTRING_END(str); while (s < e) { - int n; - unsigned int cc = rb_enc_codepoint_len(s, e, &n, enc); + int n; + unsigned int cc = rb_enc_codepoint_len(s, e, &n, enc); - if (!rb_isspace(cc) && cc != 0) return Qfalse; + if (!rb_isspace(cc) && cc != 0) return Qfalse; s += n; } return Qtrue; From ff3d629c0790772b5be3e99c871d47fcd0fdb594 Mon Sep 17 00:00:00 2001 From: Aman Gupta Date: Thu, 21 Nov 2013 14:14:26 -0800 Subject: [PATCH 2/4] remove unneccessary runtime dependencies --- Gemfile | 1 + Gemfile.lock | 4 ++-- fast_blank.gemspec | 4 +--- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/Gemfile b/Gemfile index 4806480..8d328cc 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,7 @@ source 'https://rubygems.org' gemspec +gem 'rake' gem 'debugger', :platform => :mri_19 gem 'ruby-debug', :platform => :mri_18 diff --git a/Gemfile.lock b/Gemfile.lock index ee50856..4cd966c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -2,8 +2,6 @@ PATH remote: . specs: fast_blank (0.0.1) - rake - rake-compiler GEM remote: https://rubygems.org/ @@ -63,5 +61,7 @@ DEPENDENCIES debugger fast_blank! guard-rspec + rake + rake-compiler rspec ruby-debug diff --git a/fast_blank.gemspec b/fast_blank.gemspec index fcbe371..a14da7e 100644 --- a/fast_blank.gemspec +++ b/fast_blank.gemspec @@ -24,9 +24,7 @@ Gem::Specification.new do |s| s.platform = Gem::Platform::RUBY s.rubygems_version = '1.3.7' - s.add_dependency 'rake' - s.add_dependency 'rake-compiler' - + s.add_development_dependency 'rake-compiler' s.add_development_dependency 'rspec' end From 4e192378f78fa508ab8e8cdf57a30c31d5137055 Mon Sep 17 00:00:00 2001 From: Aman Gupta Date: Thu, 21 Nov 2013 14:20:22 -0800 Subject: [PATCH 3/4] remove loop in blank_as? --- ext/fast_blank/fast_blank.c | 49 +++++++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 18 deletions(-) diff --git a/ext/fast_blank/fast_blank.c b/ext/fast_blank/fast_blank.c index c7e7e90..093052f 100644 --- a/ext/fast_blank/fast_blank.c +++ b/ext/fast_blank/fast_blank.c @@ -13,12 +13,6 @@ #define RSTRING_LEN(s) (RSTRING(s)->len) #endif -const unsigned int as_blank[26] = {9, 0xa, 0xb, 0xc, 0xd, - 0x20, 0x85, 0xa0, 0x1680, 0x180e, 0x2000, 0x2001, - 0x2002, 0x2003, 0x2004, 0x2005, 0x2006, 0x2007, 0x2008, - 0x2009, 0x200a, 0x2028, 0x2029, 0x202f, 0x205f, 0x3000 -}; - static VALUE rb_str_blank_as(VALUE str) { @@ -36,19 +30,38 @@ rb_str_blank_as(VALUE str) int n; unsigned int cc = rb_enc_codepoint_len(s, e, &n, enc); - found = 0; - for(i=0;i<26;i++){ - unsigned int current = as_blank[i]; - if(current == cc) { - found = 1; - break; - } - if(cc < current){ - break; - } + switch (cc) { + case 9: + case 0xa: + case 0xb: + case 0xc: + case 0xd: + case 0x20: + case 0x85: + case 0xa0: + case 0x1680: + case 0x180e: + case 0x2000: + case 0x2001: + case 0x2002: + case 0x2003: + case 0x2004: + case 0x2005: + case 0x2006: + case 0x2007: + case 0x2008: + case 0x2009: + case 0x200a: + case 0x2028: + case 0x2029: + case 0x202f: + case 0x205f: + case 0x3000: + /* found */ + break; + default: + return Qfalse; } - - if (!found) return Qfalse; s += n; } return Qtrue; From 3895a4a538be61252f1f8fc88fc3012510a76527 Mon Sep 17 00:00:00 2001 From: Aman Gupta Date: Thu, 21 Nov 2013 14:25:09 -0800 Subject: [PATCH 4/4] add license and homepage --- fast_blank.gemspec | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fast_blank.gemspec b/fast_blank.gemspec index a14da7e..7f2239e 100644 --- a/fast_blank.gemspec +++ b/fast_blank.gemspec @@ -7,7 +7,8 @@ Gem::Specification.new do |s| s.authors = ['Sam Saffron'] s.email = 'sam.saffron@gmail.com' - s.homepage = '' + s.homepage = '/~https://github.com/SamSaffron/fast_blank' + s.license = 'MIT' s.extensions = ['ext/fast_blank/extconf.rb'] s.require_paths = ['lib']