b62 1.0.0 → 1.0.1

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.
Files changed (2) hide show
  1. data/ext/b62/b62.c +10 -18
  2. metadata +2 -2
@@ -14,33 +14,25 @@ static const char b62_table[] = { "0123456789"
14
14
  "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
15
15
  "abcdefghijklmnopqrstuvwxyz" };
16
16
 
17
- int encode(u_int64_t input, char* ptr)
17
+ static VALUE encode(VALUE self, VALUE arg)
18
18
  {
19
- short i = 11;
20
- u_int64_t r = 0;
19
+ u_int64_t input = NUM2ULL(arg);
20
+ char output[12];
21
+ unsigned short i = 11;
21
22
 
22
- ptr[i] = '\0';
23
+ output[i] = '\0';
23
24
 
24
25
  do
25
26
  {
26
- i--;
27
- r = input % 62;
28
- input = (input - r) / 62;
29
- ptr[i] = b62_table[r];
30
- }while(input > 0);
31
-
32
- return i;
33
- }
27
+ output[--i] = b62_table[input % 62];
28
+ }
29
+ while((input = input / 62) > 0);
34
30
 
35
- static VALUE encode62(VALUE self, VALUE arg)
36
- {
37
- char output[12];
38
-
39
- return rb_str_new2(&output[encode(NUM2ULL(arg), output)]);
31
+ return rb_str_new2(&output[i]);
40
32
  }
41
33
 
42
34
  void Init_b62(void)
43
35
  {
44
36
  VALUE klass = rb_define_class("B62", rb_cObject);
45
- rb_define_singleton_method(klass, "to_b62", encode62, 1);
37
+ rb_define_singleton_method(klass, "to_b62", encode, 1);
46
38
  }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: b62
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-12 00:00:00.000000000 Z
12
+ date: 2013-01-13 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: ! " Adds a to_b62 function to the Integer class that encodes \n any
15
15
  integer between 0 and 18446744073709551615 to base 62.\n The encode function is