version_sorter 2.0.3 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: ca2c813ab2e3b07a3c6ba8c7cbac756613b61e7b514b0c06deac6d43b01d819e
4
- data.tar.gz: caacf05c4444ed24ce2ec866af9bdc2b9455af2eba50afde6010a3d440088389
2
+ SHA1:
3
+ metadata.gz: a8c82692288ea72e0ad0c5318293c8129299a147
4
+ data.tar.gz: a03518ac5700f0ff074cd02cbff312088686e1b7
5
5
  SHA512:
6
- metadata.gz: 7cb7c84a4213cb66509f06809422892d9f14b0d95a955c5124764fa5fdb9881e8f0df86dec159d02fc585d3ee5b0816e39ac451135b675f1e3272ac512b8b93a
7
- data.tar.gz: 493b92cb2e19a9e2d3b7cb2078c1965860fa299f35b3a07bc6342438903d2b379eb221ca6e32e074045f03ebb51bbc4740ec6beaa11d7f1678c8f325919dc027
6
+ metadata.gz: b31e76a36fd9d14ecdbc396802d0c52bd99ade19c60b18fe29ca08a4519e586d90bc34d8847da0dfaf73eae87d58990d642c5aec3e6704a6e6a986a2c88f93dd
7
+ data.tar.gz: 39467bac6e670ab4d6e47a10a1122d0b8fe4113764dc68889b0d0a18f840729c29e5e94a94b5c4ba6a433472cf59f2a0c34dd01cc8057c7458dbce5b3efbe159
@@ -15,7 +15,6 @@
15
15
  #include <ruby.h>
16
16
 
17
17
  #define min(a, b) ((a) < (b) ? (a) : (b))
18
- #define max(a, b) ((a) > (b) ? (a) : (b))
19
18
  typedef int compare_callback_t(const void *, const void *);
20
19
 
21
20
  struct version_number {
@@ -57,8 +56,7 @@ compare_version_number(const struct version_number *a,
57
56
  int cmp = 0;
58
57
 
59
58
  if (num_a) {
60
- int64_t cmp64 = (int64_t)ca->number - (int64_t)cb->number;
61
- cmp = (int)max(-1, min(1, cmp64));
59
+ cmp = (int)ca->number - (int)cb->number;
62
60
  } else {
63
61
  cmp = strchunk_cmp(
64
62
  a->original, &ca->string,
@@ -140,7 +138,7 @@ parse_version_number(const char *string)
140
138
  version->comp[comp_n].string.len = offset - start;
141
139
  } else {
142
140
  version->comp[comp_n].number = number;
143
- num_flags |= (1ull << comp_n);
141
+ num_flags |= (1 << comp_n);
144
142
  }
145
143
  comp_n++;
146
144
  continue;
@@ -171,42 +169,12 @@ parse_version_number(const char *string)
171
169
  return version;
172
170
  }
173
171
 
174
- struct sort_context {
175
- VALUE rb_self;
176
- VALUE rb_version_array;
177
- compare_callback_t *cmp;
178
- struct version_number **versions;
179
- };
180
-
181
- static VALUE
182
- rb_version_sort_1_cb(VALUE arg)
183
- {
184
- struct sort_context *context = (struct sort_context *)arg;
185
- long length, i;
186
- VALUE *rb_version_ptr;
187
-
188
- length = RARRAY_LEN(context->rb_version_array);
189
- for (i = 0; i < length; ++i) {
190
- VALUE rb_version = rb_ary_entry(context->rb_version_array, i);
191
- context->versions[i] = parse_version_number(StringValueCStr(rb_version));
192
- context->versions[i]->rb_version = rb_version;
193
- }
194
-
195
- qsort(context->versions, length, sizeof(struct version_number *), context->cmp);
196
- rb_version_ptr = RARRAY_PTR(context->rb_version_array);
197
-
198
- for (i = 0; i < length; ++i) {
199
- rb_version_ptr[i] = context->versions[i]->rb_version;
200
- }
201
-
202
- return context->rb_version_array;
203
- }
204
-
205
172
  static VALUE
206
173
  rb_version_sort_1(VALUE rb_self, VALUE rb_version_array, compare_callback_t cmp)
207
174
  {
175
+ struct version_number **versions;
208
176
  long length, i;
209
- int exception;
177
+ VALUE *rb_version_ptr;
210
178
 
211
179
  Check_Type(rb_version_array, T_ARRAY);
212
180
 
@@ -214,25 +182,30 @@ rb_version_sort_1(VALUE rb_self, VALUE rb_version_array, compare_callback_t cmp)
214
182
  if (!length)
215
183
  return rb_ary_new();
216
184
 
217
- struct sort_context context = {
218
- rb_self,
219
- rb_version_array,
220
- cmp,
221
- xcalloc(length, sizeof(struct version_number *)),
222
- };
223
-
224
- VALUE result = rb_protect(rb_version_sort_1_cb, (VALUE)&context, &exception);
185
+ versions = xcalloc(length, sizeof(struct version_number *));
225
186
 
226
187
  for (i = 0; i < length; ++i) {
227
- xfree(context.versions[i]);
228
- }
229
- xfree(context.versions);
188
+ VALUE rb_version, rb_version_string;
189
+
190
+ rb_version = rb_ary_entry(rb_version_array, i);
191
+ if (rb_block_given_p())
192
+ rb_version_string = rb_yield(rb_version);
193
+ else
194
+ rb_version_string = rb_version;
230
195
 
231
- if (exception) {
232
- rb_jump_tag(exception);
196
+ versions[i] = parse_version_number(StringValuePtr(rb_version_string));
197
+ versions[i]->rb_version = rb_version;
233
198
  }
234
199
 
235
- return result;
200
+ qsort(versions, length, sizeof(struct version_number *), cmp);
201
+ rb_version_ptr = RARRAY_PTR(rb_version_array);
202
+
203
+ for (i = 0; i < length; ++i) {
204
+ rb_version_ptr[i] = versions[i]->rb_version;
205
+ xfree(versions[i]);
206
+ }
207
+ xfree(versions);
208
+ return rb_version_array;
236
209
  }
237
210
 
238
211
  static VALUE
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: version_sorter
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.3
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Wanstrath
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-02-12 00:00:00.000000000 Z
12
+ date: 2016-08-07 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: VersionSorter is a C extension that does fast sorting of large sets of
15
15
  version strings.
@@ -22,7 +22,7 @@ files:
22
22
  - LICENSE
23
23
  - ext/version_sorter/extconf.rb
24
24
  - ext/version_sorter/version_sorter.c
25
- homepage: https://github.com/defunkt/version_sorter
25
+ homepage: https://github.com/github/version_sorter#readme
26
26
  licenses:
27
27
  - MIT
28
28
  metadata: {}
@@ -42,7 +42,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
42
42
  version: '0'
43
43
  requirements: []
44
44
  rubyforge_project:
45
- rubygems_version: 2.7.3
45
+ rubygems_version: 2.4.5.1
46
46
  signing_key:
47
47
  specification_version: 4
48
48
  summary: Fast sorting of version strings