efficient_join 1.2.0 → 1.4.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: 0eb0fc1fe97206cfe1fc37b6dcc15904d9ab7276add24337afedc487255bab35
4
- data.tar.gz: 98a1732e553cb92eae5c957e34353c79924b6ea8d8fdd23259f20366a02142e2
3
+ metadata.gz: e67d8cd6098b472380780f923955d25c1dc2777afa768f22552e780823ac63ab
4
+ data.tar.gz: 3d0d6057ee163ef3498f3e9563097489cd04ae074c88fa43a1b35356b156e955
5
5
  SHA512:
6
- metadata.gz: 9352ba250499feb06620b23ba816c5ab12dbf91e25f689d78c1a36b842f6767a94d1361a92fc903b1a9bbc4d423fca19d72596ffd270666467e0069791f5620e
7
- data.tar.gz: 908e42ce26f867477eabf07f5738d2abd33838c2731c54464130b5e93886e484584f5e1f23cb25bd52202d5fd2a797499115212adc9300c54f3f68e14ceb9977
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('','',',',(0...1000000).to_a)
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 takes prefix and suffix:
53
+ It can also take separator, item prefix and item suffix:
54
54
  ```
55
- EfficientJoin.join('(', ',now(),now())', ',', [1,2,3,4])
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
- fprintf(stream, "%s%ld%s", item_prefix, FIX2LONG(RARRAY_PTR(number_array)[i]), item_suffix);
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, "join", rb_efficient_join, 4);
49
- rb_define_method(mod, "join_pg_array", rb_efficient_join_pg_array, 1);
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
 
@@ -1,3 +1,3 @@
1
1
  module EfficientJoin
2
- VERSION = "1.2.0"
2
+ VERSION = "1.4.0"
3
3
  end
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: efficient_join
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Morton