efficient_join 1.2.0 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -3
- data/ext/efficient_join/efficient_join.c +12 -3
- data/lib/efficient_join/version.rb +1 -1
- data/lib/efficient_join.rb +8 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e67d8cd6098b472380780f923955d25c1dc2777afa768f22552e780823ac63ab
|
4
|
+
data.tar.gz: 3d0d6057ee163ef3498f3e9563097489cd04ae074c88fa43a1b35356b156e955
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c3c1f9456f986b2cba749b351a8646fd1476ee825bf47c18bf78061a4c070f350980f40ecb31ef9b4ede1d77be01eed71e82cd3b8f3ab1c87edf37f3112129dc
|
7
|
+
data.tar.gz: 24d0e958eeff1ed02f7bc5cb37c831de6d5f27253e3da4885db9b6ad728b489e64db0111981281d5e7d1ae1bc8c5d2b66c6bc446d2860bda2f8bc699de08fca4
|
data/README.md
CHANGED
@@ -44,15 +44,15 @@ MemoryProfiler.report { (0...1000000).to_a.join(',') }
|
|
44
44
|
With efficient join:
|
45
45
|
```
|
46
46
|
require 'efficient_join'
|
47
|
-
EfficientJoin.join(
|
47
|
+
EfficientJoin.join((0...1000000).to_a)
|
48
48
|
...
|
49
49
|
@total_allocated=5,
|
50
50
|
@total_allocated_memsize=18525362
|
51
51
|
```
|
52
52
|
|
53
|
-
It
|
53
|
+
It can also take separator, item prefix and item suffix:
|
54
54
|
```
|
55
|
-
EfficientJoin.join('(', ',now(),now())'
|
55
|
+
EfficientJoin.join([1,2,3,4], separator: ',', item_prefix: '(', item_suffix: ',now(),now())')
|
56
56
|
=> "(1,now(),now()),(2,now(),now()),(3,now(),now()),(4,now(),now())"
|
57
57
|
```
|
58
58
|
|
@@ -10,7 +10,16 @@ static VALUE _join(const char *header, const char *footer, const char *item_pref
|
|
10
10
|
fputs(header, stream);
|
11
11
|
|
12
12
|
for (long i=0; i<array_len; ++i) {
|
13
|
-
|
13
|
+
const VALUE v = RARRAY_PTR(number_array)[i];
|
14
|
+
|
15
|
+
if (TYPE(v) != T_FIXNUM) {
|
16
|
+
// rb_raise does not return control, so clean up first
|
17
|
+
fclose(stream);
|
18
|
+
free(buf);
|
19
|
+
rb_raise(rb_eTypeError, "array must contain only integers");
|
20
|
+
}
|
21
|
+
|
22
|
+
fprintf(stream, "%s%ld%s", item_prefix, FIX2LONG(v), item_suffix);
|
14
23
|
|
15
24
|
if (i < array_len - 1) {
|
16
25
|
fputs(join, stream);
|
@@ -45,7 +54,7 @@ void Init_efficient_join()
|
|
45
54
|
{
|
46
55
|
VALUE mod = rb_define_module("EfficientJoinCExt");
|
47
56
|
|
48
|
-
rb_define_method(mod, "
|
49
|
-
rb_define_method(mod, "
|
57
|
+
rb_define_method(mod, "_join", rb_efficient_join, 4);
|
58
|
+
rb_define_method(mod, "_join_pg_array", rb_efficient_join_pg_array, 1);
|
50
59
|
}
|
51
60
|
|
data/lib/efficient_join.rb
CHANGED
@@ -6,5 +6,13 @@ module EfficientJoin
|
|
6
6
|
|
7
7
|
class << self
|
8
8
|
include EfficientJoinCExt
|
9
|
+
|
10
|
+
def join(array, separator: ',', item_prefix: '', item_suffix: '')
|
11
|
+
_join(item_prefix, item_suffix, separator, array)
|
12
|
+
end
|
13
|
+
|
14
|
+
def join_pg_array(array)
|
15
|
+
_join_pg_array(array)
|
16
|
+
end
|
9
17
|
end
|
10
18
|
end
|