sin_fast_blank 2.1.0 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b9f863829ebf00c899275632445cd36a72c4a25de0220dbe7857ea44463cf59b
4
- data.tar.gz: 1379eadaf06364ac0218264888754e862877da98634d3b399d24a72c560fd60e
3
+ metadata.gz: a997d09cae43ba54e6bdf67653f42624e1e24d9bc95bc3f6746ee395e7c1c8b6
4
+ data.tar.gz: 79e130061acd6f534d452632fd9db962970e4d3b6ef11ff6cba2857b31b1a013
5
5
  SHA512:
6
- metadata.gz: 71801cffb1501b713552ba4b26396c2ab330a13551a8a91ff7d36344ff5e3e9a254dd67702379e20d4174d4bcf0136f16b59f5c102a72f6cc8323d239a342a9c
7
- data.tar.gz: 2e34a38f2a356d326a0fc2d84c1e7090e16de74db7dbc997d19fe68e56580154a92b78314f8f45080aa9ed87f436271d57b7d4e6634985fb25be49c45edc1c76
6
+ metadata.gz: e377bcbfb32e24bf1d07b763228f5a324a1da74470262ece7a120c41127018401f36a57a8d255b0ba9237e82b9f5546c3be01b723136e0e3314e495da9bfbdea
7
+ data.tar.gz: 536ff2d8d37822686338925c4b5504a490d5725d3542a64a14c3ac866e79993863dabc7464a56efe6fd2b2725596b274b5fb099866c87dc60a2179dfdc32fa6e
@@ -3,67 +3,122 @@
3
3
 
4
4
  #define STR_ENC_GET(str) rb_enc_from_index(ENCODING_GET(str))
5
5
 
6
+ static inline int is_unicode_blank(unsigned int codepoint) {
7
+ switch (codepoint) {
8
+ case 0x9:
9
+ case 0xa:
10
+ case 0xb:
11
+ case 0xc:
12
+ case 0xd:
13
+ case 0x20:
14
+ case 0x85:
15
+ case 0xa0:
16
+ case 0x1680:
17
+ case 0x2000:
18
+ case 0x2001:
19
+ case 0x2002:
20
+ case 0x2003:
21
+ case 0x2004:
22
+ case 0x2005:
23
+ case 0x2006:
24
+ case 0x2007:
25
+ case 0x2008:
26
+ case 0x2009:
27
+ case 0x200a:
28
+ case 0x2028:
29
+ case 0x2029:
30
+ case 0x202f:
31
+ case 0x205f:
32
+ case 0x3000:
33
+ return 1;
34
+ default:
35
+ return 0;
36
+ }
37
+ }
38
+
6
39
  static VALUE rb_str_blank_as(VALUE str) {
7
- char *ptr = RSTRING_PTR(str);
8
- if (!ptr || RSTRING_LEN(str) == 0) return Qtrue;
40
+ long len = RSTRING_LEN(str);
41
+ if (len == 0) {
42
+ return Qtrue;
43
+ }
9
44
 
10
- char *end = RSTRING_END(str);
45
+ const char *ptr = RSTRING_PTR(str);
46
+ const char *end = ptr + len;
11
47
  rb_encoding *enc = STR_ENC_GET(str);
12
48
 
49
+ if (rb_enc_asciicompat(enc)) {
50
+ for (const unsigned char *p = (const unsigned char *)ptr; p < (const unsigned char *)end; p++) {
51
+ if (*p >= 0x80) {
52
+ goto FULL_CHECK;
53
+ }
54
+
55
+ switch (*p) {
56
+ case 0x9:
57
+ case 0xa:
58
+ case 0xb:
59
+ case 0xc:
60
+ case 0xd:
61
+ case 0x20:
62
+ break;
63
+ default:
64
+ return Qfalse;
65
+ }
66
+ }
67
+
68
+ return Qtrue;
69
+ }
70
+
71
+ FULL_CHECK:;
13
72
  while (ptr < end) {
14
- int len;
15
- unsigned int codepoint = rb_enc_codepoint_len(ptr, end, &len, enc);
16
-
17
- switch (codepoint) {
18
- case 9:
19
- case 0xa:
20
- case 0xb:
21
- case 0xc:
22
- case 0xd:
23
- case 0x20:
24
- case 0x85:
25
- case 0xa0:
26
- case 0x1680:
27
- case 0x2000:
28
- case 0x2001:
29
- case 0x2002:
30
- case 0x2003:
31
- case 0x2004:
32
- case 0x2005:
33
- case 0x2006:
34
- case 0x2007:
35
- case 0x2008:
36
- case 0x2009:
37
- case 0x200a:
38
- case 0x2028:
39
- case 0x2029:
40
- case 0x202f:
41
- case 0x205f:
42
- case 0x3000:
43
- break;
44
- default:
45
- return Qfalse;
73
+ int clen;
74
+ unsigned int codepoint = rb_enc_codepoint_len(ptr, end, &clen, enc);
75
+
76
+ if (!is_unicode_blank(codepoint)) {
77
+ return Qfalse;
46
78
  }
47
79
 
48
- ptr += len;
80
+ ptr += clen;
49
81
  }
50
82
 
51
83
  return Qtrue;
52
84
  }
53
85
 
54
86
  static VALUE rb_str_blank(VALUE str) {
55
- char *ptr = RSTRING_PTR(str);
56
- if (!ptr || RSTRING_LEN(str) == 0) return Qtrue;
87
+ long len = RSTRING_LEN(str);
88
+ if (len == 0) {
89
+ return Qtrue;
90
+ }
57
91
 
58
- char *end = RSTRING_END(str);
92
+ const char *ptr = RSTRING_PTR(str);
93
+ const char *end = ptr + len;
59
94
  rb_encoding *enc = STR_ENC_GET(str);
95
+
96
+ if (rb_enc_asciicompat(enc)) {
97
+ for (; ptr < end; ptr++) {
98
+ unsigned char c = (unsigned char)*ptr;
99
+
100
+ if (c >= 0x80) {
101
+ goto FULL_CHECK;
102
+ }
103
+
104
+ if (!rb_isspace(c) && c != 0) {
105
+ return Qfalse;
106
+ }
107
+ }
108
+
109
+ return Qtrue;
110
+ }
111
+
112
+ FULL_CHECK:;
60
113
  while (ptr < end) {
61
- int len;
62
- unsigned int codepoint = rb_enc_codepoint_len(ptr, end, &len, enc);
114
+ int clen;
115
+ unsigned int codepoint = rb_enc_codepoint_len(ptr, end, &clen, enc);
63
116
 
64
- if (!rb_isspace(codepoint) && codepoint != 0) return Qfalse;
117
+ if (codepoint != 0 && !rb_isspace(codepoint)) {
118
+ return Qfalse;
119
+ }
65
120
 
66
- ptr += len;
121
+ ptr += clen;
67
122
  }
68
123
 
69
124
  return Qtrue;
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sin_fast_blank
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masahiro
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2025-01-17 00:00:00.000000000 Z
10
+ date: 2025-03-02 00:00:00.000000000 Z
11
11
  dependencies: []
12
12
  description: |
13
- Ruby extension library for fast blank string checking.
13
+ Ruby extension library for up to 3x faster blank string checking than fast_blank gem.
14
14
  Forked from FastBlank.
15
15
  email:
16
16
  - watanabe@cadenza-tech.com
@@ -21,15 +21,15 @@ extra_rdoc_files: []
21
21
  files:
22
22
  - ext/sin_fast_blank/extconf.rb
23
23
  - ext/sin_fast_blank/sin_fast_blank.c
24
- homepage: https://github.com/cadenza-tech/sin_fast_blank/tree/v2.1.0
24
+ homepage: https://github.com/cadenza-tech/sin_fast_blank/tree/v2.2.0
25
25
  licenses:
26
26
  - MIT
27
27
  metadata:
28
- homepage_uri: https://github.com/cadenza-tech/sin_fast_blank/tree/v2.1.0
29
- source_code_uri: https://github.com/cadenza-tech/sin_fast_blank/tree/v2.1.0
30
- changelog_uri: https://github.com/cadenza-tech/sin_fast_blank/blob/v2.1.0/CHANGELOG.md
28
+ homepage_uri: https://github.com/cadenza-tech/sin_fast_blank/tree/v2.2.0
29
+ source_code_uri: https://github.com/cadenza-tech/sin_fast_blank/tree/v2.2.0
30
+ changelog_uri: https://github.com/cadenza-tech/sin_fast_blank/blob/v2.2.0/CHANGELOG.md
31
31
  bug_tracker_uri: https://github.com/cadenza-tech/sin_fast_blank/issues
32
- documentation_uri: https://rubydoc.info/gems/sin_fast_blank/2.1.0
32
+ documentation_uri: https://rubydoc.info/gems/sin_fast_blank/2.2.0
33
33
  funding_uri: https://patreon.com/CadenzaTech
34
34
  rubygems_mfa_required: 'true'
35
35
  required_jruby_version: ">= 9.3.0.0"
@@ -51,5 +51,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
51
51
  requirements: []
52
52
  rubygems_version: 3.6.2
53
53
  specification_version: 4
54
- summary: Ruby extension library for fast blank string checking.
54
+ summary: Ruby extension library for up to 3x faster blank string checking than fast_blank
55
+ gem.
55
56
  test_files: []