fast_slice 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/fast_slice/fast_slice.c +33 -21
- data/lib/fast_slice/version.rb +3 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ad4a9a197c0d531c6a12eb2ba3dcb8b6dbe677b6
|
4
|
+
data.tar.gz: c34e41dc8b0989a9db29a725256e0a061132eb29
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8f79eaef84b1910772c27923b348346dcf318bfdb5b607c73b5290a86af8df77acf3f02940354325e24970ee80b08a8bceff8a1f2f5a0c4f67dfd0c70b2e3ec2
|
7
|
+
data.tar.gz: 51ac330d592cea1611037e9d4e6629f3924606b5210b7b6914c0489a804c7c754fbc1318d410d7e2844a83fe52b973d12ac027f6b5ab48301eca54aa2ef38a14
|
data/ext/fast_slice/fast_slice.c
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
#include <ruby.h>
|
2
2
|
|
3
|
+
static VALUE FastSlice = Qnil;
|
4
|
+
|
3
5
|
// Effectively a copy and paste from hash.c
|
4
6
|
// but replacing RHASH(hash)->tbl with RHASH_TBL (RHASH is not public)
|
5
|
-
VALUE
|
6
|
-
|
7
|
+
static VALUE
|
8
|
+
rb_hash_has_key(VALUE hash, VALUE key)
|
7
9
|
{
|
8
10
|
if (!RHASH_TBL(hash))
|
9
11
|
return Qfalse;
|
@@ -13,12 +15,9 @@ __rb_hash_has_key(VALUE hash, VALUE key)
|
|
13
15
|
return Qfalse;
|
14
16
|
}
|
15
17
|
|
16
|
-
VALUE
|
17
|
-
|
18
|
+
static VALUE
|
19
|
+
fast_slice(VALUE hash, VALUE keys)
|
18
20
|
{
|
19
|
-
VALUE hash, args;
|
20
|
-
rb_scan_args(argc, argv, "1*", &hash, &args);
|
21
|
-
|
22
21
|
if (TYPE(hash) != T_HASH) {
|
23
22
|
rb_raise(rb_eTypeError, "expected a Hash");
|
24
23
|
return Qfalse;
|
@@ -29,11 +28,11 @@ rb_fast_slice(int argc, VALUE *argv, VALUE self)
|
|
29
28
|
result = rb_hash_new();
|
30
29
|
|
31
30
|
int i;
|
32
|
-
for (i=0; i < RARRAY_LEN(
|
33
|
-
VALUE
|
34
|
-
|
35
|
-
if(
|
36
|
-
rb_hash_aset(result,
|
31
|
+
for (i=0; i < RARRAY_LEN(keys); i++) {
|
32
|
+
VALUE key;
|
33
|
+
key = rb_ary_entry(keys, i);
|
34
|
+
if(rb_hash_has_key(hash, key) == Qtrue) {
|
35
|
+
rb_hash_aset(result, key, rb_hash_aref(hash, key));
|
37
36
|
}
|
38
37
|
}
|
39
38
|
|
@@ -43,20 +42,33 @@ rb_fast_slice(int argc, VALUE *argv, VALUE self)
|
|
43
42
|
return rb_hash_dup(hash);
|
44
43
|
}
|
45
44
|
|
46
|
-
|
47
|
-
|
48
|
-
VALUE rb_define_hash_slice(int argc, VALUE *argv, VALUE self)
|
45
|
+
VALUE
|
46
|
+
rb_fast_slice_m(int argc, VALUE *argv, VALUE self)
|
49
47
|
{
|
50
|
-
|
48
|
+
VALUE hash, args;
|
49
|
+
rb_scan_args(argc, argv, "1*", &hash, &args);
|
50
|
+
return fast_slice(hash, args);
|
51
|
+
}
|
51
52
|
|
53
|
+
VALUE
|
54
|
+
rb_fast_slice(int argc, VALUE *argv, VALUE self)
|
55
|
+
{
|
56
|
+
VALUE args;
|
57
|
+
rb_scan_args(argc, argv, "0*", &args);
|
58
|
+
return fast_slice(self, args);
|
59
|
+
}
|
60
|
+
|
61
|
+
static VALUE
|
62
|
+
rb_define_hash_slice_m(void)
|
63
|
+
{
|
64
|
+
rb_define_method(rb_cHash, "slice", rb_fast_slice, -1);
|
52
65
|
return Qtrue;
|
53
66
|
}
|
54
67
|
|
55
68
|
void Init_fast_slice( void )
|
56
69
|
{
|
57
|
-
|
58
|
-
FastSlice
|
59
|
-
|
60
|
-
rb_define_singleton_method(FastSlice, "
|
61
|
-
// rb_define_singleton_method(FastSlice, "define_on_hash", rb_define_hash_slice, 0);
|
70
|
+
FastSlice = rb_define_module_under(rb_cObject, "FastSlice");
|
71
|
+
rb_define_singleton_method(FastSlice, "slice", rb_fast_slice_m, -1);
|
72
|
+
rb_define_method(FastSlice, "slice", rb_fast_slice, -1);
|
73
|
+
rb_define_singleton_method(FastSlice, "define_on_hash", rb_define_hash_slice_m, 0);
|
62
74
|
}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fast_slice
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Cook
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-11-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake-compiler
|
@@ -47,6 +47,7 @@ extra_rdoc_files: []
|
|
47
47
|
files:
|
48
48
|
- ext/fast_slice/extconf.rb
|
49
49
|
- ext/fast_slice/fast_slice.c
|
50
|
+
- lib/fast_slice/version.rb
|
50
51
|
homepage:
|
51
52
|
licenses: []
|
52
53
|
metadata: {}
|