sereal 0.0.11 → 0.0.12

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
2
  SHA1:
3
- metadata.gz: 334da6fca79a66f53b566b05c919622bf4014270
4
- data.tar.gz: 9e409dcd1d974402d32aac4cc60515c9a6dac191
3
+ metadata.gz: 93b2d3dcf39684fbf9fd094b94b4d78227bc0877
4
+ data.tar.gz: ce21c8d417fcf323d316e3364fdabb3f4d35def5
5
5
  SHA512:
6
- metadata.gz: 494b505134654159a0b1167fb2a151c62678f693a5807d90946104e82a384207dfd03cf7feeef6e468c3a1e37ed6f568483bc9a5a9aededceb06f5f7cf2ab72d
7
- data.tar.gz: 1f1d986d319675b80b389c14b07d5208d173ffbbb4b5b8ef677a57aedac641c549079fa1ce9864ef8f58b958651ead102e50d6d057582238a5e89dc6e3d4b6e6
6
+ metadata.gz: fc1d1ff34c241d8d9a31a4e3d9bf97683e0517cac457e97cb385d5656f0f07e436c029d09691736fd8909948ad2e85fcd285b7d27e6b3773e81fbbad783a5787
7
+ data.tar.gz: c3e9c73be0841b2beb34958b2972701604bbd7d3d014f1fdbcdd56612aef46614d6cf8b9d474a080a78f0b52dbcdb0fb27033bfce0caf9a3c06815fda4fefc85
data/ext/sereal/decode.c CHANGED
@@ -26,11 +26,7 @@ static u64 s_get_varint_bang(sereal_t *s) {
26
26
  static VALUE s_read_zigzag(sereal_t *s, u8 tag) {
27
27
  signed long long z = 0;
28
28
  u64 v = s_get_varint_bang(s);
29
- if (v & 1) {
30
- z = ((long) v >> 1);
31
- } else {
32
- z = (long) v >> 1;
33
- }
29
+ z = (v >> 1) ^ -(v & 0x01);
34
30
  return LL2NUM(z);
35
31
  }
36
32
 
data/ext/sereal/encode.c CHANGED
@@ -41,7 +41,7 @@ void (*WRITER[W_SIZE])(sereal_t *,VALUE);
41
41
  static void rb_object_to_sereal(sereal_t *s, VALUE object);
42
42
  static void s_append_varint(sereal_t *s,u64 n);
43
43
  static void s_append_hdr_with_varint(sereal_t *s,u8 hdr, u64 n);
44
- static void s_append_zigzag(sereal_t *s,u64 n);
44
+ static void s_append_zigzag(sereal_t *s,long long n);
45
45
  static void s_append_string(sereal_t *s,u8 *string, u32 len,u8 is_utf8);
46
46
  static void s_append_rb_string(sereal_t *s, VALUE object);
47
47
  static void s_append_array(sereal_t *s, VALUE object);
@@ -49,7 +49,8 @@ static void s_append_hash(sereal_t *s, VALUE object);
49
49
  static void s_append_symbol(sereal_t *s, VALUE object);
50
50
  static void s_append_object(sereal_t *s, VALUE object);
51
51
  static void s_append_regexp(sereal_t *s, VALUE object);
52
- static void s_append_integer(sereal_t *s, VALUE object);
52
+ static void s_append_bignum(sereal_t *s, VALUE object);
53
+ static void s_append_fixnum(sereal_t *s, VALUE object);
53
54
  static void s_append_double(sereal_t *s, VALUE object);
54
55
  static void s_append_true(sereal_t *s, VALUE object);
55
56
  static void s_append_false(sereal_t *s, VALUE object);
@@ -61,8 +62,8 @@ void s_init_writers(void) {
61
62
  for (i = 0; i < sizeof(WRITER)/sizeof(WRITER[0]); i++)
62
63
  WRITER[i] = s_default_writer;
63
64
 
64
- WRITER[T_FIXNUM] = s_append_integer;
65
- WRITER[T_BIGNUM] = s_append_integer;
65
+ WRITER[T_FIXNUM] = s_append_fixnum;
66
+ WRITER[T_BIGNUM] = s_append_bignum;
66
67
  WRITER[T_FLOAT] = s_append_double;
67
68
  WRITER[T_OBJECT] = s_append_object;
68
69
  WRITER[T_REGEXP] = s_append_regexp;
@@ -93,9 +94,8 @@ static inline void s_append_hdr_with_varint(sereal_t *s,u8 hdr, u64 n) {
93
94
  s_append_varint(s,n);
94
95
  }
95
96
 
96
- static inline void s_append_zigzag(sereal_t *s,u64 n) {
97
- s_append_hdr_with_varint(s,SRL_HDR_ZIGZAG,
98
- (n << 1) ^ (n >> (sizeof(long) * 8 - 1)));
97
+ static inline void s_append_zigzag(sereal_t *s,long long n) {
98
+ s_append_hdr_with_varint(s,SRL_HDR_ZIGZAG,(n << 1) ^ (n >> 63));
99
99
  }
100
100
 
101
101
  static inline void s_append_string(sereal_t *s,u8 *string, u32 len,u8 is_utf8) {
@@ -230,25 +230,37 @@ static void s_append_regexp(sereal_t *s, VALUE object) {
230
230
  s_append_rb_string(s,f);
231
231
  }
232
232
 
233
+ #define I_APPEND(_v) \
234
+ do { \
235
+ if (_v >= 0) { \
236
+ if (_v < 16) \
237
+ s_append_u8(s,SRL_HDR_POS_LOW | (u8) _v); \
238
+ else \
239
+ s_append_hdr_with_varint(s,SRL_HDR_VARINT,_v); \
240
+ } else { \
241
+ if (_v > -17) \
242
+ s_append_u8(s,SRL_HDR_NEG_LOW | ((u8) _v + 32)); \
243
+ else \
244
+ s_append_zigzag(s,_v); \
245
+ } \
246
+ } while(0)
247
+
248
+ static void s_append_fixnum(sereal_t *s, VALUE object) {
249
+ long long v = FIXNUM_P(object) ? FIX2LONG(object) : NUM2LL(object);
250
+ I_APPEND(v);
251
+ }
233
252
 
234
- static void s_append_integer(sereal_t *s, VALUE object) {
235
- long long v = FIXNUM_P(object) ? FIX2LONG(object) : rb_num2ll(object);
236
- if (v >= 0) {
237
- if (v < 16)
238
- s_append_u8(s,SRL_HDR_POS_LOW | (u8) v);
239
- else {
240
- if (!FIXNUM_P(object))
241
- s_append_hdr_with_varint(s,SRL_HDR_VARINT,NUM2ULL(object));
242
- else
243
- s_append_hdr_with_varint(s,SRL_HDR_VARINT,v);
244
- }
253
+ static void s_append_bignum(sereal_t *s, VALUE object) {
254
+ if (RBIGNUM_POSITIVE_P(object)) {
255
+ unsigned long long uv = rb_big2ull(object);
256
+ I_APPEND(uv);
245
257
  } else {
246
- if (v > -17)
247
- s_append_u8(s,SRL_HDR_NEG_LOW | ((u8) v + 32));
248
- else
249
- s_append_zigzag(s,v);
258
+ long long v = rb_big2ll(object);
259
+ I_APPEND(v);
250
260
  }
251
261
  }
262
+ #undef I_APPEND
263
+
252
264
  static void s_append_double(sereal_t *s, VALUE object) {
253
265
  double d = NUM2DBL(object);
254
266
  s_append_u8(s,SRL_HDR_DOUBLE);
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sereal
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
4
+ version: 0.0.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Borislav Nikolov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-12 00:00:00.000000000 Z
11
+ date: 2014-01-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake-compiler