efficient_join 2.0.0 → 2.1.4
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 +4 -4
 - data/README.md +7 -0
 - data/efficient_join.gemspec +3 -3
 - data/ext/efficient_join/efficient_join.c +22 -32
 - data/lib/efficient_join.rb +3 -3
 - data/lib/efficient_join/version.rb +1 -1
 - metadata +10 -9
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: d76d30fa5be5263c9d28faa2cb320dc4a3c61d9baf1fbefcc7cab69564bdc1cf
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 7f4a5598aa3ed81761842bdaf0f92614c33108ecda16617453284fee1e4848d0
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: f546d93a65ee3158bc1ff764d6b9af90b37250ce25eff8dbc44928720a48eee0b7a3c1a3606efd809fddea0fe6e0df205b224e11114f135ddf8f065aa60fea44
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: b76e0dd48ba2100e0d2903852ded4242a2adcebec7273b8c6ac72d1c9c87f1e91c6cccee5a45063c1b4a81b0231c4a1566285cd3a4214bec2a2a9cb9ec9b2378
         
     | 
    
        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.
         
     | 
    
        data/efficient_join.gemspec
    CHANGED
    
    | 
         @@ -9,7 +9,7 @@ Gem::Specification.new do |spec| 
     | 
|
| 
       9 
9 
     | 
    
         
             
              spec.email         = ["tomm8086@googlemail.com"]
         
     | 
| 
       10 
10 
     | 
    
         | 
| 
       11 
11 
     | 
    
         
             
              spec.summary       = %q{.}
         
     | 
| 
       12 
     | 
    
         
            -
              spec.description   = %q{Very fast and memory-efficient way to join  
     | 
| 
      
 12 
     | 
    
         
            +
              spec.description   = %q{Very fast and memory-efficient way to join ruby lists of numbers and strings.}
         
     | 
| 
       13 
13 
     | 
    
         
             
              spec.homepage      = "https://github.com/tomm/efficient_join"
         
     | 
| 
       14 
14 
     | 
    
         
             
              spec.license       = "MIT"
         
     | 
| 
       15 
15 
     | 
    
         | 
| 
         @@ -30,6 +30,6 @@ Gem::Specification.new do |spec| 
     | 
|
| 
       30 
30 
     | 
    
         
             
              spec.extensions    = ["ext/efficient_join/extconf.rb"]
         
     | 
| 
       31 
31 
     | 
    
         | 
| 
       32 
32 
     | 
    
         
             
              spec.add_development_dependency "bundler", "~> 2.0"
         
     | 
| 
       33 
     | 
    
         
            -
              spec.add_development_dependency "rake", "~>  
     | 
| 
       34 
     | 
    
         
            -
              spec.add_development_dependency "rake-compiler"
         
     | 
| 
      
 33 
     | 
    
         
            +
              spec.add_development_dependency "rake", "~> 12.3.3"
         
     | 
| 
      
 34 
     | 
    
         
            +
              spec.add_development_dependency "rake-compiler", "~> 1.0"
         
     | 
| 
       35 
35 
     | 
    
         
             
            end
         
     | 
| 
         @@ -18,15 +18,15 @@ static void strbuf_free(struct strbuf_t *strbuf) { 
     | 
|
| 
       18 
18 
     | 
    
         
             
                free(strbuf->buf);
         
     | 
| 
       19 
19 
     | 
    
         
             
            }
         
     | 
| 
       20 
20 
     | 
    
         | 
| 
       21 
     | 
    
         
            -
            static inline void strbuf_expand(struct strbuf_t *strbuf) {
         
     | 
| 
       22 
     | 
    
         
            -
                strbuf->buf = (char *)realloc(strbuf->buf, strbuf->len * 2);
         
     | 
| 
      
 21 
     | 
    
         
            +
            static inline void strbuf_expand(struct strbuf_t *strbuf, size_t min_size) {
         
     | 
| 
      
 22 
     | 
    
         
            +
                strbuf->buf = (char *)realloc(strbuf->buf, min_size > strbuf->len * 2 ? min_size : strbuf->len * 2);
         
     | 
| 
       23 
23 
     | 
    
         
             
                strbuf->len *= 2;
         
     | 
| 
       24 
24 
     | 
    
         
             
            }
         
     | 
| 
       25 
25 
     | 
    
         | 
| 
       26 
26 
     | 
    
         
             
            static inline void strbuf_write_str(struct strbuf_t *strbuf, const char *str, size_t len)
         
     | 
| 
       27 
27 
     | 
    
         
             
            {
         
     | 
| 
       28 
28 
     | 
    
         
             
                if (strbuf->len < strbuf->pos + len) {
         
     | 
| 
       29 
     | 
    
         
            -
                    strbuf_expand(strbuf);
         
     | 
| 
      
 29 
     | 
    
         
            +
                    strbuf_expand(strbuf, strbuf->pos + len);
         
     | 
| 
       30 
30 
     | 
    
         
             
                }
         
     | 
| 
       31 
31 
     | 
    
         | 
| 
       32 
32 
     | 
    
         
             
                memcpy(strbuf->buf + strbuf->pos, str, len);
         
     | 
| 
         @@ -39,31 +39,36 @@ static inline void strbuf_write_int64(struct strbuf_t *strbuf, int64_t value) 
     | 
|
| 
       39 
39 
     | 
    
         | 
| 
       40 
40 
     | 
    
         
             
                // 22: maximum length of string representation of 64-bit int
         
     | 
| 
       41 
41 
     | 
    
         
             
                if (strbuf->len <= strbuf->pos + 22) {
         
     | 
| 
       42 
     | 
    
         
            -
                    strbuf_expand(strbuf);
         
     | 
| 
      
 42 
     | 
    
         
            +
                    strbuf_expand(strbuf, strbuf->pos + 22);
         
     | 
| 
       43 
43 
     | 
    
         
             
                }
         
     | 
| 
       44 
44 
     | 
    
         | 
| 
       45 
45 
     | 
    
         
             
                bytes_written = snprintf(strbuf->buf + strbuf->pos, 22, "%ld", value);
         
     | 
| 
       46 
46 
     | 
    
         
             
                strbuf->pos += bytes_written;
         
     | 
| 
       47 
47 
     | 
    
         
             
            }
         
     | 
| 
       48 
48 
     | 
    
         | 
| 
       49 
     | 
    
         
            -
             
     | 
| 
      
 49 
     | 
    
         
            +
            VALUE rb_efficient_join(VALUE self, VALUE _header, VALUE _footer, VALUE _item_prefix, VALUE _item_suffix, VALUE _join, VALUE number_array) {
         
     | 
| 
       50 
50 
     | 
    
         
             
                VALUE out;
         
     | 
| 
       51 
     | 
    
         
            -
                const long array_len = RARRAY_LEN( 
     | 
| 
       52 
     | 
    
         
            -
                 
     | 
| 
       53 
     | 
    
         
            -
                const  
     | 
| 
       54 
     | 
    
         
            -
                const  
     | 
| 
       55 
     | 
    
         
            -
                const  
     | 
| 
      
 51 
     | 
    
         
            +
                const long array_len = RARRAY_LEN(number_array);
         
     | 
| 
      
 52 
     | 
    
         
            +
                const char* header = StringValuePtr(_header);
         
     | 
| 
      
 53 
     | 
    
         
            +
                const char* footer = StringValuePtr(_footer);
         
     | 
| 
      
 54 
     | 
    
         
            +
                const char* item_prefix = StringValuePtr(_item_prefix);
         
     | 
| 
      
 55 
     | 
    
         
            +
                const char* item_suffix = StringValuePtr(_item_suffix);
         
     | 
| 
      
 56 
     | 
    
         
            +
                const char* join = StringValuePtr(_join);
         
     | 
| 
      
 57 
     | 
    
         
            +
                VALUE *c_array = RARRAY_PTR(number_array);
         
     | 
| 
      
 58 
     | 
    
         
            +
                const size_t prefix_len = RSTRING_LEN(_item_prefix);
         
     | 
| 
      
 59 
     | 
    
         
            +
                const size_t suffix_len = RSTRING_LEN(_item_suffix);
         
     | 
| 
      
 60 
     | 
    
         
            +
                const size_t join_len = RSTRING_LEN(_join);
         
     | 
| 
       56 
61 
     | 
    
         | 
| 
       57 
     | 
    
         
            -
                // build joining string
         
     | 
| 
       58 
62 
     | 
    
         
             
                struct strbuf_t join_buf = strbuf_new(suffix_len + join_len + prefix_len);
         
     | 
| 
      
 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 
     | 
    
         
            +
                // build joining string
         
     | 
| 
       59 
67 
     | 
    
         
             
                strbuf_write_str(&join_buf, item_suffix, suffix_len);
         
     | 
| 
       60 
68 
     | 
    
         
             
                strbuf_write_str(&join_buf, join, join_len);
         
     | 
| 
       61 
69 
     | 
    
         
             
                strbuf_write_str(&join_buf, item_prefix, prefix_len);
         
     | 
| 
       62 
70 
     | 
    
         | 
| 
       63 
     | 
    
         
            -
                 
     | 
| 
       64 
     | 
    
         
            -
                struct strbuf_t buf = strbuf_new((array_len + 1) * (join_buf.pos + 10));
         
     | 
| 
       65 
     | 
    
         
            -
             
     | 
| 
       66 
     | 
    
         
            -
                strbuf_write_str(&buf, header, strlen(header));
         
     | 
| 
      
 71 
     | 
    
         
            +
                strbuf_write_str(&buf, header, RSTRING_LEN(_header));
         
     | 
| 
       67 
72 
     | 
    
         
             
                strbuf_write_str(&buf, item_prefix, prefix_len);
         
     | 
| 
       68 
73 
     | 
    
         | 
| 
       69 
74 
     | 
    
         
             
                for (long i=0; i<array_len; ++i) {
         
     | 
| 
         @@ -91,7 +96,7 @@ static VALUE _join(const char *header, const char *footer, const char *item_pref 
     | 
|
| 
       91 
96 
     | 
    
         
             
                    }
         
     | 
| 
       92 
97 
     | 
    
         
             
                }
         
     | 
| 
       93 
98 
     | 
    
         
             
                strbuf_write_str(&buf, item_suffix, suffix_len);
         
     | 
| 
       94 
     | 
    
         
            -
                strbuf_write_str(&buf, footer,  
     | 
| 
      
 99 
     | 
    
         
            +
                strbuf_write_str(&buf, footer, RSTRING_LEN(_footer));
         
     | 
| 
       95 
100 
     | 
    
         | 
| 
       96 
101 
     | 
    
         
             
                out = rb_str_new(buf.buf, buf.pos);
         
     | 
| 
       97 
102 
     | 
    
         | 
| 
         @@ -101,24 +106,9 @@ static VALUE _join(const char *header, const char *footer, const char *item_pref 
     | 
|
| 
       101 
106 
     | 
    
         
             
                return out;
         
     | 
| 
       102 
107 
     | 
    
         
             
            }
         
     | 
| 
       103 
108 
     | 
    
         | 
| 
       104 
     | 
    
         
            -
            VALUE rb_efficient_join(VALUE self, VALUE prefix, VALUE suffix, VALUE join, VALUE number_array) {
         
     | 
| 
       105 
     | 
    
         
            -
                return _join(
         
     | 
| 
       106 
     | 
    
         
            -
                    "", "",
         
     | 
| 
       107 
     | 
    
         
            -
                    StringValueCStr(prefix),
         
     | 
| 
       108 
     | 
    
         
            -
                    StringValueCStr(suffix),
         
     | 
| 
       109 
     | 
    
         
            -
                    StringValueCStr(join),
         
     | 
| 
       110 
     | 
    
         
            -
                    number_array
         
     | 
| 
       111 
     | 
    
         
            -
                );
         
     | 
| 
       112 
     | 
    
         
            -
            }
         
     | 
| 
       113 
     | 
    
         
            -
             
     | 
| 
       114 
     | 
    
         
            -
            VALUE rb_efficient_join_pg_array(VALUE self, VALUE number_array) {
         
     | 
| 
       115 
     | 
    
         
            -
                return _join("{", "}", "", "", ",", number_array);
         
     | 
| 
       116 
     | 
    
         
            -
            }
         
     | 
| 
       117 
     | 
    
         
            -
             
     | 
| 
       118 
109 
     | 
    
         
             
            void Init_efficient_join()
         
     | 
| 
       119 
110 
     | 
    
         
             
            {
         
     | 
| 
       120 
111 
     | 
    
         
             
                VALUE mod = rb_define_module("EfficientJoinCExt");
         
     | 
| 
       121 
112 
     | 
    
         | 
| 
       122 
     | 
    
         
            -
                rb_define_method(mod, "_join", rb_efficient_join,  
     | 
| 
       123 
     | 
    
         
            -
                rb_define_method(mod, "_join_pg_array", rb_efficient_join_pg_array, 1);
         
     | 
| 
      
 113 
     | 
    
         
            +
                rb_define_method(mod, "_join", rb_efficient_join, 6);
         
     | 
| 
       124 
114 
     | 
    
         
             
            }
         
     | 
    
        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.4
         
     | 
| 
       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- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2020-09-30 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: bundler
         
     | 
| 
         @@ -30,29 +30,30 @@ dependencies: 
     | 
|
| 
       30 
30 
     | 
    
         
             
                requirements:
         
     | 
| 
       31 
31 
     | 
    
         
             
                - - "~>"
         
     | 
| 
       32 
32 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       33 
     | 
    
         
            -
                    version:  
     | 
| 
      
 33 
     | 
    
         
            +
                    version: 12.3.3
         
     | 
| 
       34 
34 
     | 
    
         
             
              type: :development
         
     | 
| 
       35 
35 
     | 
    
         
             
              prerelease: false
         
     | 
| 
       36 
36 
     | 
    
         
             
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
       37 
37 
     | 
    
         
             
                requirements:
         
     | 
| 
       38 
38 
     | 
    
         
             
                - - "~>"
         
     | 
| 
       39 
39 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       40 
     | 
    
         
            -
                    version:  
     | 
| 
      
 40 
     | 
    
         
            +
                    version: 12.3.3
         
     | 
| 
       41 
41 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       42 
42 
     | 
    
         
             
              name: rake-compiler
         
     | 
| 
       43 
43 
     | 
    
         
             
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
       44 
44 
     | 
    
         
             
                requirements:
         
     | 
| 
       45 
     | 
    
         
            -
                - - " 
     | 
| 
      
 45 
     | 
    
         
            +
                - - "~>"
         
     | 
| 
       46 
46 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       47 
     | 
    
         
            -
                    version: '0'
         
     | 
| 
      
 47 
     | 
    
         
            +
                    version: '1.0'
         
     | 
| 
       48 
48 
     | 
    
         
             
              type: :development
         
     | 
| 
       49 
49 
     | 
    
         
             
              prerelease: false
         
     | 
| 
       50 
50 
     | 
    
         
             
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
       51 
51 
     | 
    
         
             
                requirements:
         
     | 
| 
       52 
     | 
    
         
            -
                - - " 
     | 
| 
      
 52 
     | 
    
         
            +
                - - "~>"
         
     | 
| 
       53 
53 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       54 
     | 
    
         
            -
                    version: '0'
         
     | 
| 
       55 
     | 
    
         
            -
            description: Very fast and memory-efficient way to join  
     | 
| 
      
 54 
     | 
    
         
            +
                    version: '1.0'
         
     | 
| 
      
 55 
     | 
    
         
            +
            description: Very fast and memory-efficient way to join ruby lists of numbers and
         
     | 
| 
      
 56 
     | 
    
         
            +
              strings.
         
     | 
| 
       56 
57 
     | 
    
         
             
            email:
         
     | 
| 
       57 
58 
     | 
    
         
             
            - tomm8086@googlemail.com
         
     | 
| 
       58 
59 
     | 
    
         
             
            executables: []
         
     |