oj 3.11.3 → 3.11.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -0
- data/ext/oj/buf.h +34 -38
- data/ext/oj/cache8.c +59 -62
- data/ext/oj/cache8.h +8 -7
- data/ext/oj/circarray.c +33 -35
- data/ext/oj/circarray.h +11 -9
- data/ext/oj/code.c +170 -174
- data/ext/oj/code.h +21 -20
- data/ext/oj/compat.c +159 -166
- data/ext/oj/custom.c +802 -851
- data/ext/oj/dump.c +766 -778
- data/ext/oj/dump.h +49 -51
- data/ext/oj/dump_compat.c +1 -0
- data/ext/oj/dump_leaf.c +116 -157
- data/ext/oj/dump_object.c +609 -628
- data/ext/oj/dump_strict.c +318 -327
- data/ext/oj/encode.h +3 -4
- data/ext/oj/err.c +39 -25
- data/ext/oj/err.h +24 -15
- data/ext/oj/extconf.rb +2 -1
- data/ext/oj/fast.c +1008 -1038
- data/ext/oj/hash.c +62 -66
- data/ext/oj/hash.h +7 -6
- data/ext/oj/hash_test.c +450 -443
- data/ext/oj/mimic_json.c +412 -402
- data/ext/oj/object.c +559 -528
- data/ext/oj/odd.c +123 -128
- data/ext/oj/odd.h +27 -25
- data/ext/oj/oj.c +1123 -922
- data/ext/oj/oj.h +286 -298
- data/ext/oj/parse.c +938 -930
- data/ext/oj/parse.h +70 -69
- data/ext/oj/rails.c +836 -839
- data/ext/oj/rails.h +7 -7
- data/ext/oj/reader.c +135 -140
- data/ext/oj/reader.h +66 -79
- data/ext/oj/resolve.c +43 -43
- data/ext/oj/resolve.h +3 -2
- data/ext/oj/rxclass.c +67 -68
- data/ext/oj/rxclass.h +12 -10
- data/ext/oj/saj.c +451 -479
- data/ext/oj/scp.c +93 -103
- data/ext/oj/sparse.c +770 -730
- data/ext/oj/stream_writer.c +120 -149
- data/ext/oj/strict.c +71 -86
- data/ext/oj/string_writer.c +198 -243
- data/ext/oj/trace.c +29 -33
- data/ext/oj/trace.h +14 -11
- data/ext/oj/util.c +103 -103
- data/ext/oj/util.h +3 -2
- data/ext/oj/val_stack.c +47 -47
- data/ext/oj/val_stack.h +79 -86
- data/ext/oj/wab.c +291 -309
- data/lib/oj/bag.rb +1 -0
- data/lib/oj/mimic.rb +0 -12
- data/lib/oj/version.rb +1 -1
- data/test/activerecord/result_test.rb +7 -2
- data/test/foo.rb +35 -32
- data/test/test_generate.rb +21 -0
- data/test/test_scp.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 964a9272c141179cf6f61317e89bc8dab43184b0d143355dc2212b89f123ccad
|
4
|
+
data.tar.gz: 53a3b3cd773a87953cec71a649f491682b022c13d56ebcc4eb5653bc9cbb560e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 947dad8a5cfc4d5adb3efbd40218439c984ae6084ef304f6b3012e26e047438a03b6f149b7c224982fc8fd0a699b56fa0e6b9a174e8b00d6567dd911f601f227
|
7
|
+
data.tar.gz: 536b05addb483b631883ccfb9269c6cd93b3e988ea9845021be3e2383a708974ff4e63a9d64a1a76bd8a9934969c42aa16495eccd75e88b7cf4704f619e7b693
|
data/README.md
CHANGED
@@ -102,3 +102,4 @@ Follow [@peterohler on Twitter](http://twitter.com/peterohler) for announcements
|
|
102
102
|
+ Provide a Pull Request off the `develop` branch.
|
103
103
|
+ Report a bug
|
104
104
|
+ Suggest an idea
|
105
|
+
+ Code is now formatted with the clang-format tool with the configuration file in the root of the repo.
|
data/ext/oj/buf.h
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
// Copyright (c) 2011 Peter Ohler. All rights reserved.
|
2
|
+
// Licensed under the MIT License. See LICENSE file in the project root for license details.
|
2
3
|
|
3
4
|
#ifndef OJ_BUF_H
|
4
5
|
#define OJ_BUF_H
|
@@ -6,66 +7,61 @@
|
|
6
7
|
#include "ruby.h"
|
7
8
|
|
8
9
|
typedef struct _buf {
|
9
|
-
char
|
10
|
-
char
|
11
|
-
char
|
12
|
-
char
|
13
|
-
} *Buf;
|
10
|
+
char *head;
|
11
|
+
char *end;
|
12
|
+
char *tail;
|
13
|
+
char base[1024];
|
14
|
+
} * Buf;
|
14
15
|
|
15
|
-
inline static void
|
16
|
-
buf_init(Buf buf) {
|
16
|
+
inline static void buf_init(Buf buf) {
|
17
17
|
buf->head = buf->base;
|
18
|
-
buf->end
|
18
|
+
buf->end = buf->base + sizeof(buf->base) - 1;
|
19
19
|
buf->tail = buf->head;
|
20
20
|
}
|
21
21
|
|
22
|
-
inline static void
|
23
|
-
buf_cleanup(Buf buf) {
|
22
|
+
inline static void buf_cleanup(Buf buf) {
|
24
23
|
if (buf->base != buf->head) {
|
25
24
|
xfree(buf->head);
|
26
25
|
}
|
27
26
|
}
|
28
27
|
|
29
|
-
inline static size_t
|
30
|
-
buf_len(Buf buf) {
|
28
|
+
inline static size_t buf_len(Buf buf) {
|
31
29
|
return buf->tail - buf->head;
|
32
30
|
}
|
33
31
|
|
34
|
-
inline static void
|
35
|
-
buf_append_string(Buf buf, const char *s, size_t slen) {
|
32
|
+
inline static void buf_append_string(Buf buf, const char *s, size_t slen) {
|
36
33
|
if (buf->end <= buf->tail + slen) {
|
37
|
-
|
38
|
-
|
39
|
-
|
34
|
+
size_t len = buf->end - buf->head;
|
35
|
+
size_t toff = buf->tail - buf->head;
|
36
|
+
size_t new_len = len + slen + len / 2;
|
40
37
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
38
|
+
if (buf->base == buf->head) {
|
39
|
+
buf->head = ALLOC_N(char, new_len);
|
40
|
+
memcpy(buf->head, buf->base, len);
|
41
|
+
} else {
|
42
|
+
REALLOC_N(buf->head, char, new_len);
|
43
|
+
}
|
44
|
+
buf->tail = buf->head + toff;
|
45
|
+
buf->end = buf->head + new_len - 1;
|
49
46
|
}
|
50
47
|
memcpy(buf->tail, s, slen);
|
51
48
|
buf->tail += slen;
|
52
49
|
}
|
53
50
|
|
54
|
-
inline static void
|
55
|
-
buf_append(Buf buf, char c) {
|
51
|
+
inline static void buf_append(Buf buf, char c) {
|
56
52
|
if (buf->end <= buf->tail) {
|
57
|
-
|
58
|
-
|
59
|
-
|
53
|
+
size_t len = buf->end - buf->head;
|
54
|
+
size_t toff = buf->tail - buf->head;
|
55
|
+
size_t new_len = len + len / 2;
|
60
56
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
57
|
+
if (buf->base == buf->head) {
|
58
|
+
buf->head = ALLOC_N(char, new_len);
|
59
|
+
memcpy(buf->head, buf->base, len);
|
60
|
+
} else {
|
61
|
+
REALLOC_N(buf->head, char, new_len);
|
62
|
+
}
|
63
|
+
buf->tail = buf->head + toff;
|
64
|
+
buf->end = buf->head + new_len - 1;
|
69
65
|
}
|
70
66
|
*buf->tail = c;
|
71
67
|
buf->tail++;
|
data/ext/oj/cache8.c
CHANGED
@@ -1,107 +1,104 @@
|
|
1
|
+
// Copyright (c) 2011 Peter Ohler. All rights reserved.
|
2
|
+
// Licensed under the MIT License. See LICENSE file in the project root for license details.
|
3
|
+
|
4
|
+
#include "cache8.h"
|
1
5
|
|
2
|
-
#include <stdlib.h>
|
3
6
|
#include <errno.h>
|
7
|
+
#include <stdarg.h>
|
4
8
|
#include <stdio.h>
|
9
|
+
#include <stdlib.h>
|
5
10
|
#include <string.h>
|
6
|
-
#include <stdarg.h>
|
7
11
|
|
8
12
|
#include "ruby.h"
|
9
|
-
#include "cache8.h"
|
10
13
|
|
11
|
-
#define BITS
|
12
|
-
#define MASK
|
13
|
-
#define SLOT_CNT
|
14
|
-
#define DEPTH
|
14
|
+
#define BITS 4
|
15
|
+
#define MASK 0x000000000000000FULL
|
16
|
+
#define SLOT_CNT 16
|
17
|
+
#define DEPTH 16
|
15
18
|
|
16
19
|
typedef union {
|
17
|
-
struct _cache8
|
18
|
-
slot_t
|
20
|
+
struct _cache8 *child;
|
21
|
+
slot_t value;
|
19
22
|
} Bucket;
|
20
23
|
|
21
24
|
struct _cache8 {
|
22
|
-
Bucket
|
25
|
+
Bucket buckets[SLOT_CNT];
|
23
26
|
};
|
24
27
|
|
25
|
-
static void
|
26
|
-
static void
|
28
|
+
static void cache8_delete(Cache8 cache, int depth);
|
29
|
+
static void slot_print(Cache8 cache, sid_t key, unsigned int depth);
|
30
|
+
|
31
|
+
void oj_cache8_new(Cache8 *cache) {
|
32
|
+
Bucket *b;
|
33
|
+
int i;
|
27
34
|
|
28
|
-
void
|
29
|
-
oj_cache8_new(Cache8 *cache) {
|
30
|
-
Bucket *b;
|
31
|
-
int i;
|
32
|
-
|
33
35
|
*cache = ALLOC(struct _cache8);
|
34
36
|
for (i = SLOT_CNT, b = (*cache)->buckets; 0 < i; i--, b++) {
|
35
|
-
|
37
|
+
b->value = 0;
|
36
38
|
}
|
37
39
|
}
|
38
40
|
|
39
|
-
void
|
40
|
-
oj_cache8_delete(Cache8 cache) {
|
41
|
-
cache8_delete(cache, 0);
|
42
|
-
}
|
41
|
+
void oj_cache8_delete(Cache8 cache) { cache8_delete(cache, 0); }
|
43
42
|
|
44
|
-
static void
|
45
|
-
|
46
|
-
|
47
|
-
unsigned int i;
|
43
|
+
static void cache8_delete(Cache8 cache, int depth) {
|
44
|
+
Bucket * b;
|
45
|
+
unsigned int i;
|
48
46
|
|
49
47
|
for (i = 0, b = cache->buckets; i < SLOT_CNT; i++, b++) {
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
48
|
+
if (0 != b->child) {
|
49
|
+
if (DEPTH - 1 != depth) {
|
50
|
+
cache8_delete(b->child, depth + 1);
|
51
|
+
}
|
52
|
+
}
|
55
53
|
}
|
56
54
|
xfree(cache);
|
57
55
|
}
|
58
56
|
|
59
|
-
slot_t
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
sid_t
|
64
|
-
|
65
|
-
|
57
|
+
slot_t oj_cache8_get(Cache8 cache, sid_t key, slot_t **slot) {
|
58
|
+
Bucket *b;
|
59
|
+
int i;
|
60
|
+
sid_t k8 = (sid_t)key;
|
61
|
+
sid_t k;
|
62
|
+
|
66
63
|
for (i = 64 - BITS; 0 < i; i -= BITS) {
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
64
|
+
k = (k8 >> i) & MASK;
|
65
|
+
b = cache->buckets + k;
|
66
|
+
if (0 == b->child) {
|
67
|
+
oj_cache8_new(&b->child);
|
68
|
+
}
|
69
|
+
cache = b->child;
|
73
70
|
}
|
74
71
|
*slot = &(cache->buckets + (k8 & MASK))->value;
|
75
72
|
|
76
73
|
return **slot;
|
77
74
|
}
|
78
75
|
|
79
|
-
void
|
80
|
-
oj_cache8_print(Cache8 cache) {
|
76
|
+
void oj_cache8_print(Cache8 cache) {
|
81
77
|
/*printf("-------------------------------------------\n"); */
|
82
78
|
slot_print(cache, 0, 0);
|
83
79
|
}
|
84
80
|
|
85
|
-
static void
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
sid_t
|
90
|
-
sid_t k;
|
81
|
+
static void slot_print(Cache8 c, sid_t key, unsigned int depth) {
|
82
|
+
Bucket * b;
|
83
|
+
unsigned int i;
|
84
|
+
sid_t k8 = (sid_t)key;
|
85
|
+
sid_t k;
|
91
86
|
|
92
87
|
for (i = 0, b = c->buckets; i < SLOT_CNT; i++, b++) {
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
88
|
+
if (0 != b->child) {
|
89
|
+
k = (k8 << BITS) | i;
|
90
|
+
/*printf("*** key: 0x%016llx depth: %u i: %u\n", k, depth, i); */
|
91
|
+
if (DEPTH - 1 == depth) {
|
97
92
|
#if IS_WINDOWS
|
98
|
-
|
93
|
+
printf("0x%016lx: %4lu\n", (long unsigned int)k,
|
94
|
+
(long unsigned int)b->value);
|
99
95
|
#else
|
100
|
-
|
96
|
+
printf("0x%016llx: %4llu\n", (long long unsigned int)k,
|
97
|
+
(long long unsigned int)b->value);
|
101
98
|
#endif
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
99
|
+
} else {
|
100
|
+
slot_print(b->child, k, depth + 1);
|
101
|
+
}
|
102
|
+
}
|
106
103
|
}
|
107
104
|
}
|
data/ext/oj/cache8.h
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
// Copyright (c) 2011 Peter Ohler. All rights reserved.
|
2
|
+
// Licensed under the MIT License. See LICENSE file in the project root for license details.
|
2
3
|
|
3
4
|
#ifndef OJ_CACHE8_H
|
4
5
|
#define OJ_CACHE8_H
|
@@ -6,15 +7,15 @@
|
|
6
7
|
#include "ruby.h"
|
7
8
|
#include "stdint.h"
|
8
9
|
|
9
|
-
typedef struct _cache8
|
10
|
-
typedef uint64_t
|
11
|
-
typedef uint64_t
|
10
|
+
typedef struct _cache8 *Cache8;
|
11
|
+
typedef uint64_t slot_t;
|
12
|
+
typedef uint64_t sid_t;
|
12
13
|
|
13
|
-
extern void
|
14
|
-
extern void
|
14
|
+
extern void oj_cache8_new(Cache8 *cache);
|
15
|
+
extern void oj_cache8_delete(Cache8 cache);
|
15
16
|
|
16
|
-
extern slot_t
|
17
|
+
extern slot_t oj_cache8_get(Cache8 cache, sid_t key, slot_t **slot);
|
17
18
|
|
18
|
-
extern void
|
19
|
+
extern void oj_cache8_print(Cache8 cache);
|
19
20
|
|
20
21
|
#endif /* OJ_CACHE8_H */
|
data/ext/oj/circarray.c
CHANGED
@@ -1,64 +1,62 @@
|
|
1
1
|
// Copyright (c) 2012 Peter Ohler. All rights reserved.
|
2
|
+
// Licensed under the MIT License. See LICENSE file in the project root for license details.
|
2
3
|
|
3
4
|
#include "circarray.h"
|
4
5
|
|
5
|
-
CircArray
|
6
|
-
|
7
|
-
CircArray ca;
|
6
|
+
CircArray oj_circ_array_new() {
|
7
|
+
CircArray ca;
|
8
8
|
|
9
9
|
if (0 == (ca = ALLOC(struct _circArray))) {
|
10
|
-
|
10
|
+
rb_raise(rb_eNoMemError, "not enough memory\n");
|
11
11
|
}
|
12
12
|
ca->objs = ca->obj_array;
|
13
13
|
ca->size = sizeof(ca->obj_array) / sizeof(VALUE);
|
14
|
-
ca->cnt
|
14
|
+
ca->cnt = 0;
|
15
15
|
|
16
16
|
return ca;
|
17
17
|
}
|
18
18
|
|
19
|
-
void
|
20
|
-
oj_circ_array_free(CircArray ca) {
|
19
|
+
void oj_circ_array_free(CircArray ca) {
|
21
20
|
if (ca->objs != ca->obj_array) {
|
22
|
-
|
21
|
+
xfree(ca->objs);
|
23
22
|
}
|
24
23
|
xfree(ca);
|
25
24
|
}
|
26
25
|
|
27
|
-
void
|
28
|
-
oj_circ_array_set(CircArray ca, VALUE obj, unsigned long id) {
|
26
|
+
void oj_circ_array_set(CircArray ca, VALUE obj, unsigned long id) {
|
29
27
|
if (0 < id && 0 != ca) {
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
28
|
+
unsigned long i;
|
29
|
+
|
30
|
+
if (ca->size < id) {
|
31
|
+
unsigned long cnt = id + 512;
|
32
|
+
|
33
|
+
if (ca->objs == ca->obj_array) {
|
34
|
+
if (0 == (ca->objs = ALLOC_N(VALUE, cnt))) {
|
35
|
+
rb_raise(rb_eNoMemError, "not enough memory\n");
|
36
|
+
}
|
37
|
+
memcpy(ca->objs, ca->obj_array, sizeof(VALUE) * ca->cnt);
|
38
|
+
} else {
|
39
|
+
REALLOC_N(ca->objs, VALUE, cnt);
|
40
|
+
}
|
41
|
+
ca->size = cnt;
|
42
|
+
}
|
43
|
+
id--;
|
44
|
+
for (i = ca->cnt; i < id; i++) {
|
45
|
+
ca->objs[i] = Qnil;
|
46
|
+
}
|
47
|
+
ca->objs[id] = obj;
|
48
|
+
if (ca->cnt <= id) {
|
49
|
+
ca->cnt = id + 1;
|
50
|
+
}
|
53
51
|
}
|
54
52
|
}
|
55
53
|
|
56
54
|
VALUE
|
57
55
|
oj_circ_array_get(CircArray ca, unsigned long id) {
|
58
|
-
VALUE
|
56
|
+
VALUE obj = Qnil;
|
59
57
|
|
60
58
|
if (id <= ca->cnt && 0 != ca) {
|
61
|
-
|
59
|
+
obj = ca->objs[id - 1];
|
62
60
|
}
|
63
61
|
return obj;
|
64
62
|
}
|
data/ext/oj/circarray.h
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
// Copyright (c) 2012 Peter Ohler. All rights reserved.
|
2
|
+
// Licensed under the MIT License. See LICENSE file in the project root for
|
3
|
+
// license details.
|
2
4
|
|
3
5
|
#ifndef OJ_CIRCARRAY_H
|
4
6
|
#define OJ_CIRCARRAY_H
|
@@ -6,15 +8,15 @@
|
|
6
8
|
#include "ruby.h"
|
7
9
|
|
8
10
|
typedef struct _circArray {
|
9
|
-
VALUE
|
10
|
-
VALUE
|
11
|
-
unsigned long
|
12
|
-
unsigned long
|
13
|
-
} *CircArray;
|
11
|
+
VALUE obj_array[1024];
|
12
|
+
VALUE * objs;
|
13
|
+
unsigned long size; // allocated size or initial array size
|
14
|
+
unsigned long cnt;
|
15
|
+
} * CircArray;
|
14
16
|
|
15
|
-
extern CircArray
|
16
|
-
extern void
|
17
|
-
extern void
|
18
|
-
extern VALUE
|
17
|
+
extern CircArray oj_circ_array_new(void);
|
18
|
+
extern void oj_circ_array_free(CircArray ca);
|
19
|
+
extern void oj_circ_array_set(CircArray ca, VALUE obj, unsigned long id);
|
20
|
+
extern VALUE oj_circ_array_get(CircArray ca, unsigned long id);
|
19
21
|
|
20
22
|
#endif /* OJ_CIRCARRAY_H */
|