faster_support 0.1.2 → 0.1.3

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
  SHA1:
3
- metadata.gz: c92c6c5cad9bd0608e6a283d72f658bc86090b6f
4
- data.tar.gz: 651ae4799d92e798eb132e7b56eeb2bf44183f5d
3
+ metadata.gz: 76e9f5ca8de3d42e98a0e73df78445c2b3a4cb8c
4
+ data.tar.gz: ee4fc83ad572d7d6e6f174de52c1588cb6017678
5
5
  SHA512:
6
- metadata.gz: 444e81d82e5cd7f57b3692b474e99bdc9a8650ff824a8a0fdc9b43c9d9a691a9390f7e75a98d6e8d4a03b23e1eab5819c538f9f3ef7f3051f27fc6a7a73baf10
7
- data.tar.gz: 84eb093056ab474ce819e8ed06ae5ce9d70f98a052d4d1e94c88910a60f91ccfee7d80e93844c122a512871eae474b55eccf697efc7a363a1d7c91a26cab49ec
6
+ metadata.gz: 4db8352ef893e4a19dba66570cc21d933a42422613f341178dab02d09883c954708aa6d245d841776e3a01921439364e9e0b281ac91f8d24e7eadaf4aaed1af1
7
+ data.tar.gz: 3cc6517f426912997f1490b593d2b85726d3ba5a9bbaf2da0cb7a6c15af4a08928710ac91e2ee5c862180781e9039494e3d4596da5ae804442abd536d68f8a57
data/.color_coded CHANGED
@@ -1,11 +1,54 @@
1
1
  -x
2
2
  c
3
3
  -std=c99
4
- -I.
4
+ -I/Users/morgan/projects/coach/faster_support/ext/.
5
5
  -I/Users/morgan/.rvm/rubies/ruby-2.4.0/include/ruby-2.4.0/x86_64-darwin16
6
6
  -I/Users/morgan/.rvm/rubies/ruby-2.4.0/include/ruby-2.4.0/ruby/backward
7
7
  -I/Users/morgan/.rvm/rubies/ruby-2.4.0/include/ruby-2.4.0
8
- -I../../../../ext/faster_support
8
+ -I/Users/morgan/projects/coach/faster_support/ext/faster_support
9
+ -I/usr/local/opt/libyaml/include
10
+ -I/usr/local/opt/readline/include
11
+ -I/usr/local/opt/libksba/include
12
+ -I/usr/local/opt/openssl/include
13
+ -I/usr/local/opt/libyaml/include
14
+ -I/usr/local/opt/readline/include
15
+ -I/usr/local/opt/libksba/include
16
+ -I/usr/local/opt/openssl/include
17
+ -D_XOPEN_SOURCE
18
+ -D_DARWIN_C_SOURCE
19
+ -D_DARWIN_UNLIMITED_SELECT
20
+ -D_REENTRANT
21
+ -fno-common
22
+ -O3
23
+ -fno-fast-math
24
+ -ggdb3
25
+ -Wall
26
+ -Wextra
27
+ -Wno-unused-parameter
28
+ -Wno-parentheses
29
+ -Wno-long-long
30
+ -Wno-missing-field-initializers
31
+ -Wno-tautological-compare
32
+ -Wno-parentheses-equality
33
+ -Wno-constant-logical-operand
34
+ -Wno-self-assign
35
+ -Wunused-variable
36
+ -Wimplicit-int
37
+ -Wpointer-arith
38
+ -Wwrite-strings
39
+ -Wdeclaration-after-statement
40
+ -Wshorten-64-to-32
41
+ -Wimplicit-function-declaration
42
+ -Wdivision-by-zero
43
+ -Wdeprecated-declarations
44
+ -Wextra-tokens
45
+ -fno-common
46
+ -pipe
47
+ -I/Users/morgan/projects/coach/faster_support/ext/.
48
+ -I/Users/morgan/.rvm/rubies/ruby-2.4.0/include/ruby-2.4.0/x86_64-darwin16/.
49
+ -I/Users/morgan/.rvm/rubies/ruby-2.4.0/include/ruby-2.4.0/ruby/backward/.
50
+ -I/Users/morgan/.rvm/rubies/ruby-2.4.0/include/ruby-2.4.0/.
51
+ -I/Users/morgan/projects/coach/faster_support/ext/faster_support/object/blank/.
9
52
  -I/usr/local/opt/libyaml/include
10
53
  -I/usr/local/opt/readline/include
11
54
  -I/usr/local/opt/libksba/include
@@ -57,5 +100,5 @@ c
57
100
  -isystem
58
101
  /Library/Frameworks
59
102
  -isystem
60
- /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/7.3.0/include
103
+ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/8.0.0/include
61
104
  -fspell-checking
data/.ycm_extra_conf.py CHANGED
@@ -41,6 +41,9 @@ flags = [
41
41
  '-I/Users/morgan/projects/coach/faster_support/ext/faster_support/.',
42
42
  '-I/Users/morgan/projects/coach/faster_support/tmp/x86_64-darwin16/stage/lib/faster_support/.',
43
43
  '-I/Users/morgan/projects/coach/faster_support/tmp/x86_64-darwin16/faster_support/2.4.0/.',
44
+ '-I/Users/morgan/projects/coach/faster_support/ext/faster_support/object/blank/.',
45
+ '-I/Users/morgan/projects/coach/faster_support/tmp/x86_64-darwin16/stage/lib/faster_support/object/blank/.',
46
+ '-I/Users/morgan/projects/coach/faster_support/tmp/x86_64-darwin16/faster_support/2.4.0/object/blank/.',
44
47
  '-I/Users/morgan/.rvm/rubies/ruby-2.4.0/include/ruby-2.4.0/.',
45
48
  '-I/Users/morgan/.rvm/rubies/ruby-2.4.0/include/ruby-2.4.0/x86_64-darwin16/.',
46
49
  '-Wall',
data/Guardfile CHANGED
@@ -19,7 +19,7 @@
19
19
 
20
20
  group :build_and_test, halt_on_fail: true do
21
21
  guard 'rake', task: 'prespec' do
22
- watch(%r{^ext/(.+)\.(c|h|rb)$})
22
+ watch(%r{^ext/faster_support/(.+)\.(c|h|rb)$})
23
23
  end
24
24
 
25
25
  guard :rspec, cmd: 'bundle exec rspec' do
@@ -34,7 +34,7 @@ group :build_and_test, halt_on_fail: true do
34
34
  watch(rspec.spec_support) { rspec.spec_dir }
35
35
  watch(rspec.spec_files)
36
36
 
37
- watch(%r{^ext/(.+)\.(c|h|rb)$}) { rspec.spec_dir }
37
+ watch(%r{^ext/faster_support/(.+)\.(c|h|rb)$}) { rspec.spec_dir }
38
38
 
39
39
  # Ruby files
40
40
  ruby = dsl.ruby
data/Rakefile CHANGED
@@ -13,12 +13,21 @@ task build: [:compile, :tooling]
13
13
 
14
14
  task prespec: [:clobber, :compile, :tooling]
15
15
 
16
- Dir['./lib/tasks/**/*.rake'].each { |f| load f } # load task directory
16
+ require 'tasks/tooling'
17
17
 
18
18
  Rake::ExtensionTask.new('faster_support') do |ext|
19
19
  ext.lib_dir = 'lib/faster_support'
20
20
  ext.source_pattern = '*.{c,cpp,m,mm}'
21
- Tooling.exttask = ext
21
+ Tooling.add_task(ext: ext)
22
22
  end
23
23
 
24
+ Rake::ExtensionTask.new('object/blank') do |ext|
25
+ ext.ext_dir = 'ext/faster_support/object/blank'
26
+ ext.lib_dir = 'lib/faster_support/core_ext'
27
+ ext.source_pattern = '*.{c,cpp,m,mm}'
28
+ Tooling.add_task(ext: ext)
29
+ end
30
+
31
+ Tooling.define(:tooling)
32
+
24
33
  task default: [:clobber, :compile, :tooling, :spec]
@@ -1,22 +1,17 @@
1
1
  [
2
- {
3
- "command": "cc -c -I. -I/Users/morgan/.rvm/rubies/ruby-2.4.0/include/ruby-2.4.0/x86_64-darwin16 -I/Users/morgan/.rvm/rubies/ruby-2.4.0/include/ruby-2.4.0/ruby/backward -I/Users/morgan/.rvm/rubies/ruby-2.4.0/include/ruby-2.4.0 -I../../../../ext/faster_support -I/usr/local/opt/libyaml/include -I/usr/local/opt/readline/include -I/usr/local/opt/libksba/include -I/usr/local/opt/openssl/include -I/usr/local/opt/libyaml/include -I/usr/local/opt/readline/include -I/usr/local/opt/libksba/include -I/usr/local/opt/openssl/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -fno-common -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wno-tautological-compare -Wno-parentheses-equality -Wno-constant-logical-operand -Wno-self-assign -Wunused-variable -Wimplicit-int -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wshorten-64-to-32 -Wimplicit-function-declaration -Wdivision-by-zero -Wdeprecated-declarations -Wextra-tokens -fno-common -pipe -o array_blank.o ../../../../ext/faster_support/array_blank.c",
4
- "directory": "/Users/morgan/projects/coach/faster_support/tmp/x86_64-darwin16/faster_support/2.4.0",
5
- "file": "/Users/morgan/projects/coach/faster_support/ext/faster_support/array_blank.c"
6
- },
7
- {
8
- "command": "cc -c -I. -I/Users/morgan/.rvm/rubies/ruby-2.4.0/include/ruby-2.4.0/x86_64-darwin16 -I/Users/morgan/.rvm/rubies/ruby-2.4.0/include/ruby-2.4.0/ruby/backward -I/Users/morgan/.rvm/rubies/ruby-2.4.0/include/ruby-2.4.0 -I../../../../ext/faster_support -I/usr/local/opt/libyaml/include -I/usr/local/opt/readline/include -I/usr/local/opt/libksba/include -I/usr/local/opt/openssl/include -I/usr/local/opt/libyaml/include -I/usr/local/opt/readline/include -I/usr/local/opt/libksba/include -I/usr/local/opt/openssl/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -fno-common -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wno-tautological-compare -Wno-parentheses-equality -Wno-constant-logical-operand -Wno-self-assign -Wunused-variable -Wimplicit-int -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wshorten-64-to-32 -Wimplicit-function-declaration -Wdivision-by-zero -Wdeprecated-declarations -Wextra-tokens -fno-common -pipe -o faster_support.o ../../../../ext/faster_support/faster_support.c",
9
- "directory": "/Users/morgan/projects/coach/faster_support/tmp/x86_64-darwin16/faster_support/2.4.0",
10
- "file": "/Users/morgan/projects/coach/faster_support/ext/faster_support/faster_support.c"
11
- },
12
- {
13
- "command": "cc -c -I. -I/Users/morgan/.rvm/rubies/ruby-2.4.0/include/ruby-2.4.0/x86_64-darwin16 -I/Users/morgan/.rvm/rubies/ruby-2.4.0/include/ruby-2.4.0/ruby/backward -I/Users/morgan/.rvm/rubies/ruby-2.4.0/include/ruby-2.4.0 -I../../../../ext/faster_support -I/usr/local/opt/libyaml/include -I/usr/local/opt/readline/include -I/usr/local/opt/libksba/include -I/usr/local/opt/openssl/include -I/usr/local/opt/libyaml/include -I/usr/local/opt/readline/include -I/usr/local/opt/libksba/include -I/usr/local/opt/openssl/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -fno-common -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wno-tautological-compare -Wno-parentheses-equality -Wno-constant-logical-operand -Wno-self-assign -Wunused-variable -Wimplicit-int -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wshorten-64-to-32 -Wimplicit-function-declaration -Wdivision-by-zero -Wdeprecated-declarations -Wextra-tokens -fno-common -pipe -o object_blank.o ../../../../ext/faster_support/object_blank.c",
14
- "directory": "/Users/morgan/projects/coach/faster_support/tmp/x86_64-darwin16/faster_support/2.4.0",
15
- "file": "/Users/morgan/projects/coach/faster_support/ext/faster_support/object_blank.c"
16
- },
17
- {
18
- "command": "cc -c -I. -I/Users/morgan/.rvm/rubies/ruby-2.4.0/include/ruby-2.4.0/x86_64-darwin16 -I/Users/morgan/.rvm/rubies/ruby-2.4.0/include/ruby-2.4.0/ruby/backward -I/Users/morgan/.rvm/rubies/ruby-2.4.0/include/ruby-2.4.0 -I../../../../ext/faster_support -I/usr/local/opt/libyaml/include -I/usr/local/opt/readline/include -I/usr/local/opt/libksba/include -I/usr/local/opt/openssl/include -I/usr/local/opt/libyaml/include -I/usr/local/opt/readline/include -I/usr/local/opt/libksba/include -I/usr/local/opt/openssl/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -fno-common -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wno-tautological-compare -Wno-parentheses-equality -Wno-constant-logical-operand -Wno-self-assign -Wunused-variable -Wimplicit-int -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wshorten-64-to-32 -Wimplicit-function-declaration -Wdivision-by-zero -Wdeprecated-declarations -Wextra-tokens -fno-common -pipe -o string_blank.o ../../../../ext/faster_support/string_blank.c",
19
- "directory": "/Users/morgan/projects/coach/faster_support/tmp/x86_64-darwin16/faster_support/2.4.0",
20
- "file": "/Users/morgan/projects/coach/faster_support/ext/faster_support/string_blank.c"
21
- }
2
+ {
3
+ "command": "cc -c -I. -I/Users/morgan/.rvm/rubies/ruby-2.4.0/include/ruby-2.4.0/x86_64-darwin16 -I/Users/morgan/.rvm/rubies/ruby-2.4.0/include/ruby-2.4.0/ruby/backward -I/Users/morgan/.rvm/rubies/ruby-2.4.0/include/ruby-2.4.0 -I../../../../ext/faster_support -I/usr/local/opt/libyaml/include -I/usr/local/opt/readline/include -I/usr/local/opt/libksba/include -I/usr/local/opt/openssl/include -I/usr/local/opt/libyaml/include -I/usr/local/opt/readline/include -I/usr/local/opt/libksba/include -I/usr/local/opt/openssl/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -fno-common -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wno-tautological-compare -Wno-parentheses-equality -Wno-constant-logical-operand -Wno-self-assign -Wunused-variable -Wimplicit-int -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wshorten-64-to-32 -Wimplicit-function-declaration -Wdivision-by-zero -Wdeprecated-declarations -Wextra-tokens -fno-common -pipe -o faster_support.o ../../../../ext/faster_support/faster_support.c",
4
+ "directory": "/Users/morgan/projects/coach/faster_support/tmp/x86_64-darwin16/faster_support/2.4.0",
5
+ "file": "/Users/morgan/projects/coach/faster_support/ext/faster_support/faster_support.c"
6
+ },
7
+ {
8
+ "command": "cc -c -I. -I/Users/morgan/.rvm/rubies/ruby-2.4.0/include/ruby-2.4.0/x86_64-darwin16 -I/Users/morgan/.rvm/rubies/ruby-2.4.0/include/ruby-2.4.0/ruby/backward -I/Users/morgan/.rvm/rubies/ruby-2.4.0/include/ruby-2.4.0 -I../../../../../ext/faster_support/object/blank -I/usr/local/opt/libyaml/include -I/usr/local/opt/readline/include -I/usr/local/opt/libksba/include -I/usr/local/opt/openssl/include -I/usr/local/opt/libyaml/include -I/usr/local/opt/readline/include -I/usr/local/opt/libksba/include -I/usr/local/opt/openssl/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -I/Users/morgan/projects/coach/faster_support/ext/faster_support -fno-common -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wno-tautological-compare -Wno-parentheses-equality -Wno-constant-logical-operand -Wno-self-assign -Wunused-variable -Wimplicit-int -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wshorten-64-to-32 -Wimplicit-function-declaration -Wdivision-by-zero -Wdeprecated-declarations -Wextra-tokens -fno-common -pipe -o object_blank.o ../../../../../ext/faster_support/object/blank/object_blank.c",
9
+ "directory": "/Users/morgan/projects/coach/faster_support/tmp/x86_64-darwin16/object/blank/2.4.0",
10
+ "file": "/Users/morgan/projects/coach/faster_support/ext/faster_support/object/blank/object_blank.c"
11
+ },
12
+ {
13
+ "command": "cc -c -I. -I/Users/morgan/.rvm/rubies/ruby-2.4.0/include/ruby-2.4.0/x86_64-darwin16 -I/Users/morgan/.rvm/rubies/ruby-2.4.0/include/ruby-2.4.0/ruby/backward -I/Users/morgan/.rvm/rubies/ruby-2.4.0/include/ruby-2.4.0 -I../../../../../ext/faster_support/object/blank -I/usr/local/opt/libyaml/include -I/usr/local/opt/readline/include -I/usr/local/opt/libksba/include -I/usr/local/opt/openssl/include -I/usr/local/opt/libyaml/include -I/usr/local/opt/readline/include -I/usr/local/opt/libksba/include -I/usr/local/opt/openssl/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -I/Users/morgan/projects/coach/faster_support/ext/faster_support -fno-common -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wno-tautological-compare -Wno-parentheses-equality -Wno-constant-logical-operand -Wno-self-assign -Wunused-variable -Wimplicit-int -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wshorten-64-to-32 -Wimplicit-function-declaration -Wdivision-by-zero -Wdeprecated-declarations -Wextra-tokens -fno-common -pipe -o string_blank.o ../../../../../ext/faster_support/object/blank/string_blank.c",
14
+ "directory": "/Users/morgan/projects/coach/faster_support/tmp/x86_64-darwin16/object/blank/2.4.0",
15
+ "file": "/Users/morgan/projects/coach/faster_support/ext/faster_support/object/blank/string_blank.c"
16
+ }
22
17
  ]
@@ -1,3 +1,4 @@
1
- require 'mkmf'
1
+ # frozen_string_literal: true
2
2
 
3
+ require 'mkmf'
3
4
  create_makefile('faster_support/faster_support')
@@ -1,8 +1,60 @@
1
+ /* FasterSupport main implementation */
2
+
1
3
  #include "faster_support.h"
2
4
 
5
+ VALUE rb_mFasterSupport, rb_sFasterSupport;
6
+
7
+ static ID sym_mri, sym_as, id_blank_impl, id_to_sym;
8
+
9
+ static VALUE get_impl(void)
10
+ {
11
+ VALUE val, sym;
12
+
13
+ val = rb_funcall(rb_mFasterSupport, id_blank_impl, 0);
14
+
15
+ if (NIL_P(val)) {
16
+ printf("Got `nil`, returning sym_as\n");
17
+ sym = sym_as;
18
+ }
19
+ else {
20
+ sym = rb_funcall(val, id_to_sym, 0);
21
+ }
22
+
23
+ return sym;
24
+ }
25
+
26
+ FasterSupport_blank_impl FasterSupport_get_blank_impl()
27
+ {
28
+ VALUE impl = get_impl();
29
+
30
+ if (impl == sym_mri) {
31
+ return Impl_MRI;
32
+ }
33
+
34
+ if (impl == sym_as) {
35
+ return Impl_ActiveSupport;
36
+ }
37
+
38
+ return Impl_UNKNOWN;
39
+ }
40
+
41
+ inline int FasterSupport_uses_mri()
42
+ {
43
+ return (FasterSupport_get_blank_impl() == Impl_MRI);
44
+ }
45
+
46
+ inline int FasterSupport_uses_as()
47
+ {
48
+ return (FasterSupport_get_blank_impl() == Impl_ActiveSupport);
49
+ }
50
+
3
51
  void Init_faster_support(void)
4
52
  {
5
- Init_obj_blank();
6
- Init_str_blank();
7
- Init_ary_blank();
53
+ sym_mri = ID2SYM(rb_intern("mri"));
54
+ sym_as = ID2SYM(rb_intern("active_support"));
55
+ id_blank_impl = rb_intern("blank_implementation");
56
+ id_to_sym = rb_intern("to_sym");
57
+
58
+ rb_mFasterSupport = rb_define_module("FasterSupport");
59
+ rb_sFasterSupport = rb_singleton_class(rb_mFasterSupport);
8
60
  }
@@ -2,22 +2,18 @@
2
2
  #define FASTER_SUPPORT_H 1
3
3
 
4
4
  #include "ruby.h"
5
- #include "ruby/encoding.h"
6
- #include "ruby/re.h"
7
- #include "ruby/version.h"
8
5
 
9
- #define STR_ENC_GET(str) rb_enc_from_index(ENCODING_GET(str))
6
+ extern VALUE rb_mFasterSupport;
10
7
 
11
- #ifndef RUBY_API_VERSION_CODE
12
- #define RUBY_BEFORE_2_2 1
13
- #else
14
- #define RUBY_BEFORE_2_2 (RUBY_API_VERSION_CODE < 20200)
15
- #endif /* ifndef RUBY_API_VERSION_CODE */
8
+ typedef enum {
9
+ Impl_MRI,
10
+ Impl_ActiveSupport,
11
+ Impl_UNKNOWN,
12
+ } FasterSupport_blank_impl;
16
13
 
17
- #define RB_NEGATE(VAL) (VAL == Qtrue ? Qfalse : Qtrue)
14
+ FasterSupport_blank_impl FasterSupport_get_blank_impl();
18
15
 
19
- void Init_str_blank(void);
20
- void Init_ary_blank(void);
21
- void Init_obj_blank(void);
16
+ inline int FasterSupport_uses_mri();
17
+ inline int FasterSupport_uses_as();
22
18
 
23
19
  #endif /* FASTER_SUPPORT_H */
@@ -0,0 +1,23 @@
1
+ #ifndef FASTER_SUPPORT_OBJECT_BLANK_H
2
+ #define FASTER_SUPPORT_OBJECT_BLANK_H 1
3
+
4
+ #include "ruby.h"
5
+ #include "ruby/encoding.h"
6
+ #include "ruby/re.h"
7
+ #include "ruby/version.h"
8
+
9
+ #define STR_ENC_GET(str) rb_enc_from_index(ENCODING_GET(str))
10
+
11
+ #ifndef RUBY_API_VERSION_CODE
12
+ #define RUBY_BEFORE_2_2 1
13
+ #else
14
+ #define RUBY_BEFORE_2_2 (RUBY_API_VERSION_CODE < 20200)
15
+ #endif /* ifndef RUBY_API_VERSION_CODE */
16
+
17
+ #define RB_NEGATE(VAL) (VAL == Qtrue ? Qfalse : Qtrue)
18
+
19
+ void Init_str_blank(void);
20
+ void Init_ary_blank(void);
21
+ void Init_obj_blank(void);
22
+
23
+ #endif /* FASTER_SUPPORT_OBJECT_BLANK_H */
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'mkmf'
4
+ # rubocop:disable all
5
+ $CPPFLAGS += "-I#{File.expand_path('../../../', __FILE__)}"
6
+ create_makefile('faster_support/object/blank')
@@ -0,0 +1,93 @@
1
+ /* Object#blank? implementation */
2
+
3
+ #include "blank.h"
4
+
5
+ static ID id_empty;
6
+
7
+ static VALUE rb_obj_blank(VALUE obj)
8
+ {
9
+ VALUE empty;
10
+
11
+ if (rb_respond_to(obj, id_empty)) {
12
+ empty = rb_funcall(obj, id_empty, 0);
13
+ if (empty == Qnil || empty == Qfalse) {
14
+ return Qfalse;
15
+ }
16
+
17
+ return Qtrue;
18
+ }
19
+
20
+ empty = (obj == Qnil || obj == Qfalse) ? Qtrue : Qfalse;
21
+
22
+ return empty;
23
+ }
24
+
25
+ static VALUE rb_obj_present(VALUE obj)
26
+ {
27
+ return RB_NEGATE(rb_obj_blank(obj));
28
+ }
29
+
30
+ static VALUE return_false()
31
+ {
32
+ return Qfalse;
33
+ }
34
+
35
+ static VALUE return_true()
36
+ {
37
+ return Qtrue;
38
+ }
39
+
40
+ static VALUE rb_ary_blank(VALUE ary)
41
+ {
42
+ if (RARRAY_LEN(ary) == 0) {
43
+ return Qtrue;
44
+ }
45
+
46
+ return Qfalse;
47
+ }
48
+
49
+ static VALUE rb_ary_present(VALUE ary)
50
+ {
51
+ return RB_NEGATE(rb_ary_blank(ary));
52
+ }
53
+
54
+ static VALUE rb_hash_blank(VALUE self)
55
+ {
56
+ return RHASH_EMPTY_P(self) ? Qtrue : Qfalse;
57
+ }
58
+
59
+ static VALUE rb_hash_present(VALUE self)
60
+ {
61
+ return RB_NEGATE(rb_hash_blank(self));
62
+ }
63
+
64
+ void Init_blank(void)
65
+ {
66
+ id_empty = rb_intern("empty?");
67
+
68
+ rb_define_method(rb_cObject, "blank?", rb_obj_blank, 0);
69
+ rb_define_method(rb_cObject, "present?", rb_obj_present, 0);
70
+
71
+ rb_define_method(rb_cNilClass, "blank?", return_true, 0);
72
+ rb_define_method(rb_cNilClass, "present?", return_false, 0);
73
+
74
+ rb_define_method(rb_cFalseClass, "blank?", return_true, 0);
75
+ rb_define_method(rb_cFalseClass, "present?", return_false, 0);
76
+
77
+ rb_define_method(rb_cArray, "blank?", rb_ary_blank, 0);
78
+ rb_define_method(rb_cArray, "present?", rb_ary_present, 0);
79
+
80
+ rb_define_method(rb_cHash, "blank?", rb_hash_blank, 0);
81
+ rb_define_method(rb_cHash, "present?", rb_hash_present, 0);
82
+
83
+ rb_define_method(rb_cTrueClass, "blank?", return_false, 0);
84
+ rb_define_method(rb_cTrueClass, "present?", return_true, 0);
85
+
86
+ Init_str_blank();
87
+
88
+ rb_define_method(rb_cNumeric, "blank?", return_false, 0);
89
+ rb_define_method(rb_cNumeric, "present?", return_true, 0);
90
+
91
+ rb_define_method(rb_cTime, "blank?", return_false, 0);
92
+ rb_define_method(rb_cTime, "present?", return_true, 0);
93
+ }
@@ -1,9 +1,12 @@
1
1
  /* Faster implementation of String#blank? */
2
2
 
3
+ #include "blank.h"
3
4
  #include "faster_support.h"
4
5
  #include <stdio.h>
5
6
 
6
- static VALUE rb_str_blank(VALUE str)
7
+ extern VALUE rb_mFasterSupport;
8
+
9
+ static VALUE rb_str_as_blank(VALUE str)
7
10
  {
8
11
  rb_encoding *enc;
9
12
  char *s, *e;
@@ -62,7 +65,7 @@ static VALUE rb_str_blank(VALUE str)
62
65
  return Qtrue;
63
66
  }
64
67
 
65
- static VALUE rb_str_blank_mri(VALUE str)
68
+ static VALUE rb_str_mri_blank(VALUE str)
66
69
  {
67
70
  rb_encoding *enc;
68
71
  char *s, *e;
@@ -84,6 +87,22 @@ static VALUE rb_str_blank_mri(VALUE str)
84
87
  return Qtrue;
85
88
  }
86
89
 
90
+ static VALUE rb_str_blank(VALUE str)
91
+ {
92
+ FasterSupport_blank_impl impl = FasterSupport_get_blank_impl();
93
+
94
+ switch (impl) {
95
+ case Impl_MRI:
96
+ return rb_str_mri_blank(str);
97
+ case Impl_ActiveSupport:
98
+ return rb_str_as_blank(str);
99
+ default:
100
+ break;
101
+ }
102
+
103
+ return rb_str_as_blank(str);
104
+ }
105
+
87
106
  static VALUE rb_str_present(VALUE str)
88
107
  {
89
108
  return RB_NEGATE(rb_str_blank(str));
@@ -91,7 +110,8 @@ static VALUE rb_str_present(VALUE str)
91
110
 
92
111
  void Init_str_blank(void)
93
112
  {
113
+ rb_define_method(rb_cString, "as_blank?", rb_str_as_blank, 0);
94
114
  rb_define_method(rb_cString, "blank?", rb_str_blank, 0);
95
- rb_define_method(rb_cString, "mri_blank?", rb_str_blank_mri, 0);
115
+ rb_define_method(rb_cString, "mri_blank?", rb_str_mri_blank, 0);
96
116
  rb_define_method(rb_cString, "present?", rb_str_present, 0);
97
117
  }
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
21
21
  spec.bindir = 'exe'
22
22
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
23
  spec.require_paths = ['lib']
24
- spec.extensions = ['ext/faster_support/extconf.rb']
24
+ spec.extensions = Dir['ext/**/*/extconf.rb']
25
25
 
26
26
  spec.add_development_dependency 'bundler', '~> 1.13'
27
27
  spec.add_development_dependency 'rake', '~> 10.0'
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'faster_support/core_ext/object/blank'
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'faster_support/core_ext/object'
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FasterSupport
4
- VERSION = '0.1.2'
4
+ VERSION = '0.1.3'
5
5
  end
@@ -2,6 +2,28 @@
2
2
 
3
3
  require 'faster_support/version'
4
4
  require 'faster_support/faster_support'
5
+ require 'faster_support/core_ext'
5
6
 
6
7
  module FasterSupport
8
+ class << self
9
+ def blank_implementation
10
+ @blank_implementation ||= :active_support
11
+ end
12
+
13
+ def blank_implementation=(impl)
14
+ @blank_implementation =
15
+ case impl.to_sym
16
+ when :mri, :ruby then :mri
17
+ when :as, :active_support, :rails then :active_support
18
+ else
19
+ raise ArgumentError, "Unknown implementation: #{impl}. " \
20
+ 'Please use :active_support or :mri.'
21
+ end
22
+ end
23
+
24
+ alias blank_impl blank_implementation
25
+ alias blank_impl= blank_implementation=
26
+ end
27
+
28
+ @blank_implementation = :active_support
7
29
  end
@@ -19,7 +19,7 @@ namespace :tooling do
19
19
  commands = [Tooling::PRE_COMPILE_FLAGS,
20
20
  commands.uniq,
21
21
  Tooling::POST_COMPILE_FLAGS]
22
- print 'Generating .color_coded...'
22
+ puts 'Generating .color_coded...'
23
23
  File.open('.color_coded', 'w') { |io| io.puts commands }
24
24
  puts 'Done'
25
25
  end
data/lib/tasks/tooling.rb CHANGED
@@ -3,29 +3,191 @@ require 'forwardable'
3
3
  require 'pathname'
4
4
  require 'json'
5
5
 
6
+ require 'rake'
7
+ require 'rake/tasklib'
8
+
6
9
  module Tooling
7
10
  class << self
11
+ include ::Rake::DSL
12
+
13
+ def cc_jsons
14
+ @cc_jsons ||= []
15
+ end
16
+
17
+ def add_cc_json(text)
18
+ cc_jsons << JSON.parse(text)
19
+ end
20
+
21
+ def cc_json(as: :hash)
22
+ result = []
23
+ cc_jsons.each { |json| result += json }
24
+ return result if :hash == as
25
+
26
+ JSON.pretty_generate(result)
27
+ end
28
+
29
+ def color_coded_commands
30
+ @color_coded_commands ||= [Tooling::PRE_COMPILE_FLAGS,
31
+ inner_cc_commands,
32
+ Tooling::POST_COMPILE_FLAGS].uniq
33
+ end
34
+
35
+ def add_task(*args, ext:, **opts)
36
+ Tooling::Task.new(ext, *args, **opts)
37
+ end
38
+
39
+ def tasks
40
+ @tasks ||= []
41
+ end
42
+
43
+ def define(name = :tooling)
44
+ desc 'Prerequisites for compile_commands.json'
45
+ task "#{name}:pre_compile_commands" => pre_compile_commands
46
+
47
+ define_ccjson(name)
48
+ # define_color_coded
49
+
50
+ # CLEAN.include('.color_coded')
51
+ CLEAN.include('compile_commands.json')
52
+
53
+ desc 'Default vim tooling task'
54
+ task "#{name}:default" => ['compile_commands.json']
55
+
56
+ desc 'Generate vim tooling'
57
+ task name => [:compile, "#{name}:default"]
58
+ end
59
+
60
+ private
61
+
62
+ def define_ccjson(name)
63
+ file 'compile_commands.json' => "#{name}:pre_compile_commands" do
64
+ puts "Generating compile_commands.json at #{Rake.original_dir}"
65
+ Dir.chdir(Rake.original_dir) do
66
+ File.open('compile_commands.json', 'w') do |io|
67
+ io.write cc_json(as: :json)
68
+ end
69
+ end
70
+ puts 'Done'
71
+ end
72
+ end
73
+
74
+ def define_color_coded
75
+ file '.color_coded' => 'compile_commands.json' do
76
+ puts 'Generating .color_coded...'
77
+ File.open('.color_coded', 'w') { |io| io.puts color_coded_commands }
78
+ puts 'Done'
79
+ end
80
+ end
81
+
82
+ def pre_compile_commands
83
+ @pre_compile_commands ||= tasks.map(&:cc_json_task_name)
84
+ end
85
+
86
+ def inner_cc_commands # rubocop:disable Metrics/AbcSize,MethodLength
87
+ @inner_cc_commands ||=
88
+ begin
89
+ commands = []
90
+ raw = File.read(File.join(Rake.original_dir, 'compile_commands.json'))
91
+ JSON.parse(raw).each do |cmd_def|
92
+ commands << cmd_def['command'].split(' ')[2..-4].map do |string|
93
+ string.strip
94
+ .sub('../../../..', Rake.original_dir.to_s)
95
+ .sub('/../', '/')
96
+ .sub(/-I\.\z/, "-I#{Rake.original_dir}/ext/.")
97
+ end
98
+ end
99
+ commands.uniq
100
+ rescue Errno::ENOENT
101
+ puts "File not found: #{raw}"
102
+ exit 2
103
+ end
104
+ end
105
+ end
106
+
107
+ class Task < ::Rake::TaskLib
108
+ include ::Rake::DSL
8
109
  extend Forwardable
9
- attr_writer :exttask
10
110
 
11
- def exttask
12
- @exttask || raise('No extension task present!')
111
+ attr_accessor :ext_task
112
+
113
+ def initialize(ext_task, *args, **opts)
114
+ @ext_task = ext_task
115
+ @_name = args.shift || ext_task.name
116
+ @namespace = opts.fetch(:namespace, :tooling)
117
+ @namespaced = opts.fetch(:namespaced, !@namespace.nil?)
118
+ yield self if block_given?
119
+
120
+ Tooling.tasks << self
121
+
122
+ define(args)
13
123
  end
14
124
 
15
- def_delegators :exttask, :tmp_dir, :platform
16
- def_delegator :exttask, :name, :extname
125
+ def name
126
+ @_name ||= extname.dup
127
+ end
128
+
129
+ def_delegators :ext_task, :tmp_dir, :platform
130
+ def_delegator :ext_task, :name, :extname
17
131
 
18
132
  def platform_tmp_dir
19
- Pathname.new(File.join(exttask.tmp_dir, exttask.platform, exttask.name))
133
+ Pathname.new(File.join(ext_task.tmp_dir, ext_task.platform, ext_task.name))
20
134
  end
21
135
 
22
136
  def build_dir
23
137
  platform_tmp_dir.join(RUBY_VERSION.to_s)
24
138
  end
139
+
140
+ def cc_json_task_name
141
+ task_name :pre_compile_commands
142
+ end
143
+
144
+ protected
145
+
146
+ def namespaced?
147
+ @namespaced
148
+ end
149
+
150
+ def define(args)
151
+ desc "Required setup for compile_commands.json for #{name}"
152
+ task cc_json_task_name, *args do
153
+ add_cc_json
154
+ end
155
+
156
+ task 'tooling:pre_compile_commands' => cc_json_task_name
157
+ end
158
+
159
+ private
160
+
161
+ def run_file_tasks(_args)
162
+ add_cc_json
163
+ end
164
+
165
+ def cc_json
166
+ @cc_json ||=
167
+ begin
168
+ file = File.join(build_dir, 'compile_commands.json')
169
+ JSON.parse(File.read(file))
170
+ rescue Errno::ENOENT => e
171
+ puts nil, '=' * 70
172
+ puts "File not found: #{File.expand_path(file)} (#{e})"
173
+ puts '=' * 70
174
+ exit 1
175
+ end
176
+ end
177
+
178
+ def add_cc_json
179
+ # puts "Adding compile_commands.json for #{name}"
180
+ Tooling.cc_jsons << cc_json
181
+ end
182
+
183
+ def task_name(task)
184
+ "#{name}:#{task}" unless namespaced?
185
+ "#{@namespace}:#{name}:#{task}"
186
+ end
25
187
  end
26
188
 
27
189
  XCODE_TOOLCHAIN_PATH = '/Applications/Xcode.app/Contents/Developer' \
28
- '/Toolchains/XcodeDefault.xctoolchain'.freeze
190
+ '/Toolchains/XcodeDefault.xctoolchain'
29
191
  PRE_COMPILE_FLAGS = %w(-x c -std=c99).freeze
30
192
 
31
193
  POST_COMPILE_FLAGS = %W(
@@ -42,7 +204,7 @@ module Tooling
42
204
  -isystem
43
205
  /Library/Frameworks
44
206
  -isystem
45
- #{XCODE_TOOLCHAIN_PATH}/usr/lib/clang/7.3.0/include
207
+ #{XCODE_TOOLCHAIN_PATH}/usr/lib/clang/8.0.0/include
46
208
  -fspell-checking
47
209
  ).freeze
48
210
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: faster_support
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - J. Morgan Lieberthal
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-01-09 00:00:00.000000000 Z
11
+ date: 2017-01-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -72,6 +72,7 @@ email:
72
72
  executables: []
73
73
  extensions:
74
74
  - ext/faster_support/extconf.rb
75
+ - ext/faster_support/object/blank/extconf.rb
75
76
  extra_rdoc_files: []
76
77
  files:
77
78
  - ".clang-format"
@@ -91,14 +92,17 @@ files:
91
92
  - bin/console
92
93
  - bin/setup
93
94
  - compile_commands.json
94
- - ext/faster_support/array_blank.c
95
95
  - ext/faster_support/extconf.rb
96
96
  - ext/faster_support/faster_support.c
97
97
  - ext/faster_support/faster_support.h
98
- - ext/faster_support/object_blank.c
99
- - ext/faster_support/string_blank.c
98
+ - ext/faster_support/object/blank/blank.h
99
+ - ext/faster_support/object/blank/extconf.rb
100
+ - ext/faster_support/object/blank/object_blank.c
101
+ - ext/faster_support/object/blank/string_blank.c
100
102
  - faster_support.gemspec
101
103
  - lib/faster_support.rb
104
+ - lib/faster_support/core_ext.rb
105
+ - lib/faster_support/core_ext/object.rb
102
106
  - lib/faster_support/version.rb
103
107
  - lib/tasks/tooling.rake
104
108
  - lib/tasks/tooling.rb
@@ -1,35 +0,0 @@
1
- /* Array#blank? implementation */
2
-
3
- #include "faster_support.h"
4
-
5
- static VALUE rb_ary_blank(VALUE ary)
6
- {
7
- if (RARRAY_LEN(ary) == 0) {
8
- return Qtrue;
9
- }
10
-
11
- return Qfalse;
12
- }
13
-
14
- static VALUE rb_ary_present(VALUE ary)
15
- {
16
- return RB_NEGATE(rb_ary_blank(ary));
17
- }
18
-
19
- static VALUE rb_hash_blank(VALUE self)
20
- {
21
- return RHASH_EMPTY_P(self) ? Qtrue : Qfalse;
22
- }
23
-
24
- static VALUE rb_hash_present(VALUE self)
25
- {
26
- return RB_NEGATE(rb_hash_blank(self));
27
- }
28
-
29
- void Init_ary_blank(void)
30
- {
31
- rb_define_method(rb_cArray, "blank?", rb_ary_blank, 0);
32
- rb_define_method(rb_cArray, "present?", rb_ary_present, 0);
33
- rb_define_method(rb_cHash, "blank?", rb_hash_blank, 0);
34
- rb_define_method(rb_cHash, "present?", rb_hash_present, 0);
35
- }
@@ -1,65 +0,0 @@
1
- /* Object#blank? implementation */
2
-
3
- #include "faster_support.h"
4
-
5
- static ID id_empty;
6
-
7
- static VALUE rb_obj_blank(VALUE obj)
8
- {
9
- VALUE empty;
10
-
11
- if (rb_respond_to(obj, id_empty)) {
12
- empty = rb_funcall(obj, id_empty, 0);
13
- if (empty == Qnil || empty == Qfalse) {
14
- return Qfalse;
15
- }
16
-
17
- return Qtrue;
18
- }
19
-
20
- empty = (obj == Qnil || obj == Qfalse) ? Qtrue : Qfalse;
21
-
22
- return empty;
23
- }
24
-
25
- static VALUE rb_obj_present(VALUE obj)
26
- {
27
- return RB_NEGATE(rb_obj_blank(obj));
28
- }
29
-
30
- static VALUE rb_nil_blank(VALUE self)
31
- {
32
- return Qtrue;
33
- }
34
-
35
- static VALUE rb_nil_present(VALUE self)
36
- {
37
- return Qfalse;
38
- }
39
-
40
- static VALUE rb_true_blank(VALUE self)
41
- {
42
- return Qfalse;
43
- }
44
-
45
- static VALUE rb_true_present(VALUE self)
46
- {
47
- return Qtrue;
48
- }
49
-
50
- void Init_obj_blank(void)
51
- {
52
- id_empty = rb_intern("empty?");
53
- rb_define_method(rb_cObject, "blank?", rb_obj_blank, 0);
54
- rb_define_method(rb_cObject, "present?", rb_obj_present, 0);
55
- rb_define_method(rb_cNilClass, "blank?", rb_nil_blank, 0);
56
- rb_define_method(rb_cNilClass, "present?", rb_nil_present, 0);
57
- rb_define_method(rb_cFalseClass, "blank?", rb_nil_blank, 0);
58
- rb_define_method(rb_cFalseClass, "present?", rb_nil_present, 0);
59
- rb_define_method(rb_cTrueClass, "blank?", rb_true_blank, 0);
60
- rb_define_method(rb_cTrueClass, "present?", rb_true_present, 0);
61
- rb_define_method(rb_cNumeric, "blank?", rb_true_blank, 0);
62
- rb_define_method(rb_cNumeric, "present?", rb_true_present, 0);
63
- rb_define_method(rb_cTime, "blank?", rb_true_blank, 0);
64
- rb_define_method(rb_cTime, "present?", rb_true_present, 0);
65
- }