efficient_join 2.0.0 → 2.1.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 +7 -0
- data/ext/efficient_join/efficient_join.c +8 -12
- data/lib/efficient_join/version.rb +1 -1
- data/lib/efficient_join.rb +3 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7e939e7d2de4992664e192b1b2851c81931023d49038d0533d8f065379260004
|
4
|
+
data.tar.gz: 48183fea3587d9d415256797baa343aefef074970d8f0813d1fa98aecab00bc1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1b5a44b860c8ccb7f1f005c9766cd11ff44878efcc8b7121e115df32b30fc78d472b594c852d7428335164c97680bbf954fd6da0be207f8096ae60ae7353b943
|
7
|
+
data.tar.gz: 4e8cf6f00b49f3046037425bca7963d641c09d69fb277a0e1703ee3b07075fc3358847340a936075b3aea74002eae4100a03e2934e333b5013e8a45a4ed26cd4
|
data/README.md
CHANGED
@@ -64,6 +64,13 @@ EfficientJoin.join_pg_array([1,2,3,4])
|
|
64
64
|
=> "{1,2,3,4}"
|
65
65
|
```
|
66
66
|
|
67
|
+
Which is equivalent to:
|
68
|
+
|
69
|
+
```
|
70
|
+
EfficientJoin.join([1,2,3,4], header: '{', footer: '}')
|
71
|
+
=> "{1,2,3,4}"
|
72
|
+
```
|
73
|
+
|
67
74
|
## Development
|
68
75
|
|
69
76
|
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
@@ -54,15 +54,15 @@ static VALUE _join(const char *header, const char *footer, const char *item_pref
|
|
54
54
|
const size_t suffix_len = strlen(item_suffix);
|
55
55
|
const size_t join_len = strlen(join);
|
56
56
|
|
57
|
-
// build joining string
|
58
57
|
struct strbuf_t join_buf = strbuf_new(suffix_len + join_len + prefix_len);
|
58
|
+
// estimate likely maximum buffer size, to avoid reallocs
|
59
|
+
struct strbuf_t buf = strbuf_new((array_len + 1) * (join_buf.pos + 10));
|
60
|
+
|
61
|
+
// build joining string
|
59
62
|
strbuf_write_str(&join_buf, item_suffix, suffix_len);
|
60
63
|
strbuf_write_str(&join_buf, join, join_len);
|
61
64
|
strbuf_write_str(&join_buf, item_prefix, prefix_len);
|
62
65
|
|
63
|
-
// estimate likely maximum buffer size, to avoid reallocs
|
64
|
-
struct strbuf_t buf = strbuf_new((array_len + 1) * (join_buf.pos + 10));
|
65
|
-
|
66
66
|
strbuf_write_str(&buf, header, strlen(header));
|
67
67
|
strbuf_write_str(&buf, item_prefix, prefix_len);
|
68
68
|
|
@@ -101,9 +101,10 @@ static VALUE _join(const char *header, const char *footer, const char *item_pref
|
|
101
101
|
return out;
|
102
102
|
}
|
103
103
|
|
104
|
-
VALUE rb_efficient_join(VALUE self, VALUE prefix, VALUE suffix, VALUE join, VALUE number_array) {
|
104
|
+
VALUE rb_efficient_join(VALUE self, VALUE header, VALUE footer, VALUE prefix, VALUE suffix, VALUE join, VALUE number_array) {
|
105
105
|
return _join(
|
106
|
-
|
106
|
+
StringValueCStr(header),
|
107
|
+
StringValueCStr(footer),
|
107
108
|
StringValueCStr(prefix),
|
108
109
|
StringValueCStr(suffix),
|
109
110
|
StringValueCStr(join),
|
@@ -111,14 +112,9 @@ VALUE rb_efficient_join(VALUE self, VALUE prefix, VALUE suffix, VALUE join, VALU
|
|
111
112
|
);
|
112
113
|
}
|
113
114
|
|
114
|
-
VALUE rb_efficient_join_pg_array(VALUE self, VALUE number_array) {
|
115
|
-
return _join("{", "}", "", "", ",", number_array);
|
116
|
-
}
|
117
|
-
|
118
115
|
void Init_efficient_join()
|
119
116
|
{
|
120
117
|
VALUE mod = rb_define_module("EfficientJoinCExt");
|
121
118
|
|
122
|
-
rb_define_method(mod, "_join", rb_efficient_join,
|
123
|
-
rb_define_method(mod, "_join_pg_array", rb_efficient_join_pg_array, 1);
|
119
|
+
rb_define_method(mod, "_join", rb_efficient_join, 6);
|
124
120
|
}
|
data/lib/efficient_join.rb
CHANGED
@@ -7,12 +7,12 @@ module EfficientJoin
|
|
7
7
|
class << self
|
8
8
|
include EfficientJoinCExt
|
9
9
|
|
10
|
-
def join(array, separator: ',', item_prefix: '', item_suffix: '')
|
11
|
-
_join(item_prefix, item_suffix, separator, array)
|
10
|
+
def join(array, header: '', footer: '', separator: ',', item_prefix: '', item_suffix: '')
|
11
|
+
_join(header, footer, item_prefix, item_suffix, separator, array)
|
12
12
|
end
|
13
13
|
|
14
14
|
def join_pg_array(array)
|
15
|
-
|
15
|
+
_join('{', '}', '', '', ',', array)
|
16
16
|
end
|
17
17
|
end
|
18
18
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: efficient_join
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tom Morton
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-05-
|
11
|
+
date: 2020-05-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|