oj 3.10.6 → 3.12.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -1
- data/ext/oj/buf.h +36 -68
- data/ext/oj/cache8.c +59 -62
- data/ext/oj/cache8.h +9 -36
- data/ext/oj/circarray.c +36 -42
- data/ext/oj/circarray.h +12 -13
- data/ext/oj/code.c +172 -179
- data/ext/oj/code.h +22 -24
- data/ext/oj/compat.c +176 -181
- data/ext/oj/custom.c +800 -864
- data/ext/oj/dump.c +774 -776
- data/ext/oj/dump.h +50 -55
- data/ext/oj/dump_compat.c +2 -4
- data/ext/oj/dump_leaf.c +118 -162
- data/ext/oj/dump_object.c +610 -632
- data/ext/oj/dump_strict.c +319 -331
- data/ext/oj/encode.h +4 -33
- data/ext/oj/err.c +40 -29
- data/ext/oj/err.h +25 -44
- data/ext/oj/extconf.rb +2 -1
- data/ext/oj/fast.c +1054 -1081
- data/ext/oj/hash.c +102 -97
- data/ext/oj/hash.h +10 -35
- data/ext/oj/hash_test.c +451 -472
- data/ext/oj/mimic_json.c +415 -402
- data/ext/oj/object.c +588 -532
- data/ext/oj/odd.c +124 -132
- data/ext/oj/odd.h +28 -29
- data/ext/oj/oj.c +1186 -906
- data/ext/oj/oj.h +289 -298
- data/ext/oj/parse.c +946 -870
- data/ext/oj/parse.h +81 -79
- data/ext/oj/rails.c +837 -842
- data/ext/oj/rails.h +8 -11
- data/ext/oj/reader.c +139 -147
- data/ext/oj/reader.h +68 -84
- data/ext/oj/resolve.c +44 -47
- data/ext/oj/resolve.h +4 -6
- data/ext/oj/rxclass.c +69 -73
- data/ext/oj/rxclass.h +13 -14
- data/ext/oj/saj.c +453 -484
- data/ext/oj/scp.c +88 -113
- data/ext/oj/sparse.c +783 -714
- data/ext/oj/stream_writer.c +123 -157
- data/ext/oj/strict.c +133 -106
- data/ext/oj/string_writer.c +199 -247
- data/ext/oj/trace.c +34 -41
- data/ext/oj/trace.h +15 -15
- data/ext/oj/util.c +104 -104
- data/ext/oj/util.h +4 -3
- data/ext/oj/val_stack.c +48 -76
- data/ext/oj/val_stack.h +80 -115
- data/ext/oj/wab.c +321 -325
- data/lib/oj.rb +0 -8
- data/lib/oj/bag.rb +1 -0
- data/lib/oj/easy_hash.rb +5 -4
- data/lib/oj/mimic.rb +47 -13
- data/lib/oj/version.rb +1 -1
- data/pages/Modes.md +1 -0
- data/pages/Options.md +23 -11
- data/test/activerecord/result_test.rb +7 -2
- data/test/foo.rb +8 -40
- data/test/helper.rb +10 -0
- data/test/json_gem/json_common_interface_test.rb +8 -3
- data/test/json_gem/json_generator_test.rb +15 -3
- data/test/json_gem/test_helper.rb +8 -0
- data/test/perf.rb +1 -1
- data/test/perf_scp.rb +11 -10
- data/test/perf_strict.rb +17 -23
- data/test/prec.rb +23 -0
- data/test/sample_json.rb +1 -1
- data/test/test_compat.rb +16 -3
- data/test/test_custom.rb +11 -0
- data/test/test_fast.rb +32 -2
- data/test/test_generate.rb +21 -0
- data/test/test_hash.rb +10 -0
- data/test/test_rails.rb +9 -0
- data/test/test_scp.rb +1 -1
- data/test/test_various.rb +4 -2
- metadata +89 -85
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7316e25014cf4268799f3f1e4a01a74fada832b1d68bf64d82cbeb42b2caf1dd
|
4
|
+
data.tar.gz: a02fdb9676efeacfec86475ff35afdb88cfef33e0c94188355cad69401ee2304
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8f83d20545998db46a7dd0bd0e2560f47198fbb0f192bc80f17ffbce046e38727e0c143e022f8d00ba2332e2cb0be27ddda294b6a96d6f4b091ec95e282d2f01
|
7
|
+
data.tar.gz: e62a125cf992f510296bbe6b3eeeaaadaa8ccd2891b764a290518f785b706a797af7fbd247ac360364cd610e67ad038488d6eefb55e4dc028a3b20540995e4df
|
data/README.md
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
# [![{}j](http://www.ohler.com/dev/images/oj_comet_64.svg)](http://www.ohler.com/oj) gem
|
2
2
|
|
3
|
-
[![Build Status](https://img.shields.io/
|
3
|
+
[![Build Status](https://img.shields.io/github/workflow/status/ohler55/oj/CI?logo=github)](https://github.com/ohler55/oj/actions/workflows/CI.yml)
|
4
|
+
![Gem](https://img.shields.io/gem/v/oj.svg)
|
5
|
+
![Gem](https://img.shields.io/gem/dt/oj.svg)
|
6
|
+
[![SemVer compatibility](https://api.dependabot.com/badges/compatibility_score?dependency-name=oj&package-manager=bundler&version-scheme=semver)](https://dependabot.com/compatibility-score.html?dependency-name=oj&package-manager=bundler&version-scheme=semver)
|
7
|
+
[![TideLift](https://tidelift.com/badges/github/ohler55/oj)](https://tidelift.com/subscription/pkg/rubygems-oj?utm_source=rubygems-oj&utm_medium=referral&utm_campaign=readme)
|
4
8
|
|
5
9
|
A *fast* JSON parser and Object marshaller as a Ruby gem.
|
6
10
|
|
@@ -102,3 +106,4 @@ Follow [@peterohler on Twitter](http://twitter.com/peterohler) for announcements
|
|
102
106
|
+ Provide a Pull Request off the `develop` branch.
|
103
107
|
+ Report a bug
|
104
108
|
+ Suggest an idea
|
109
|
+
+ 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,32 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
* All rights reserved.
|
4
|
-
*
|
5
|
-
* Redistribution and use in source and binary forms, with or without
|
6
|
-
* modification, are permitted provided that the following conditions are met:
|
7
|
-
*
|
8
|
-
* - Redistributions of source code must retain the above copyright notice, this
|
9
|
-
* list of conditions and the following disclaimer.
|
10
|
-
*
|
11
|
-
* - Redistributions in binary form must reproduce the above copyright notice,
|
12
|
-
* this list of conditions and the following disclaimer in the documentation
|
13
|
-
* and/or other materials provided with the distribution.
|
14
|
-
*
|
15
|
-
* - Neither the name of Peter Ohler nor the names of its contributors may be
|
16
|
-
* used to endorse or promote products derived from this software without
|
17
|
-
* specific prior written permission.
|
18
|
-
*
|
19
|
-
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
20
|
-
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
21
|
-
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
22
|
-
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
23
|
-
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
24
|
-
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
25
|
-
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
26
|
-
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
27
|
-
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
28
|
-
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
29
|
-
*/
|
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.
|
30
3
|
|
31
4
|
#ifndef OJ_BUF_H
|
32
5
|
#define OJ_BUF_H
|
@@ -34,66 +7,61 @@
|
|
34
7
|
#include "ruby.h"
|
35
8
|
|
36
9
|
typedef struct _buf {
|
37
|
-
char
|
38
|
-
char
|
39
|
-
char
|
40
|
-
char
|
41
|
-
} *Buf;
|
10
|
+
char *head;
|
11
|
+
char *end;
|
12
|
+
char *tail;
|
13
|
+
char base[1024];
|
14
|
+
} * Buf;
|
42
15
|
|
43
|
-
inline static void
|
44
|
-
buf_init(Buf buf) {
|
16
|
+
inline static void buf_init(Buf buf) {
|
45
17
|
buf->head = buf->base;
|
46
|
-
buf->end
|
18
|
+
buf->end = buf->base + sizeof(buf->base) - 1;
|
47
19
|
buf->tail = buf->head;
|
48
20
|
}
|
49
21
|
|
50
|
-
inline static void
|
51
|
-
buf_cleanup(Buf buf) {
|
22
|
+
inline static void buf_cleanup(Buf buf) {
|
52
23
|
if (buf->base != buf->head) {
|
53
24
|
xfree(buf->head);
|
54
25
|
}
|
55
26
|
}
|
56
27
|
|
57
|
-
inline static size_t
|
58
|
-
buf_len(Buf buf) {
|
28
|
+
inline static size_t buf_len(Buf buf) {
|
59
29
|
return buf->tail - buf->head;
|
60
30
|
}
|
61
31
|
|
62
|
-
inline static void
|
63
|
-
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) {
|
64
33
|
if (buf->end <= buf->tail + slen) {
|
65
|
-
|
66
|
-
|
67
|
-
|
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;
|
68
37
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
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;
|
77
46
|
}
|
78
47
|
memcpy(buf->tail, s, slen);
|
79
48
|
buf->tail += slen;
|
80
49
|
}
|
81
|
-
|
82
|
-
inline static void
|
83
|
-
buf_append(Buf buf, char c) {
|
50
|
+
|
51
|
+
inline static void buf_append(Buf buf, char c) {
|
84
52
|
if (buf->end <= buf->tail) {
|
85
|
-
|
86
|
-
|
87
|
-
|
53
|
+
size_t len = buf->end - buf->head;
|
54
|
+
size_t toff = buf->tail - buf->head;
|
55
|
+
size_t new_len = len + len / 2;
|
88
56
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
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;
|
97
65
|
}
|
98
66
|
*buf->tail = c;
|
99
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,32 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
* All rights reserved.
|
4
|
-
*
|
5
|
-
* Redistribution and use in source and binary forms, with or without
|
6
|
-
* modification, are permitted provided that the following conditions are met:
|
7
|
-
*
|
8
|
-
* - Redistributions of source code must retain the above copyright notice, this
|
9
|
-
* list of conditions and the following disclaimer.
|
10
|
-
*
|
11
|
-
* - Redistributions in binary form must reproduce the above copyright notice,
|
12
|
-
* this list of conditions and the following disclaimer in the documentation
|
13
|
-
* and/or other materials provided with the distribution.
|
14
|
-
*
|
15
|
-
* - Neither the name of Peter Ohler nor the names of its contributors may be
|
16
|
-
* used to endorse or promote products derived from this software without
|
17
|
-
* specific prior written permission.
|
18
|
-
*
|
19
|
-
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
20
|
-
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
21
|
-
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
22
|
-
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
23
|
-
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
24
|
-
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
25
|
-
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
26
|
-
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
27
|
-
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
28
|
-
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
29
|
-
*/
|
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.
|
30
3
|
|
31
4
|
#ifndef OJ_CACHE8_H
|
32
5
|
#define OJ_CACHE8_H
|
@@ -34,15 +7,15 @@
|
|
34
7
|
#include "ruby.h"
|
35
8
|
#include "stdint.h"
|
36
9
|
|
37
|
-
typedef struct _cache8
|
38
|
-
typedef uint64_t
|
39
|
-
typedef uint64_t
|
10
|
+
typedef struct _cache8 *Cache8;
|
11
|
+
typedef uint64_t slot_t;
|
12
|
+
typedef uint64_t sid_t;
|
40
13
|
|
41
|
-
extern void
|
42
|
-
extern void
|
14
|
+
extern void oj_cache8_new(Cache8 *cache);
|
15
|
+
extern void oj_cache8_delete(Cache8 cache);
|
43
16
|
|
44
|
-
extern slot_t
|
17
|
+
extern slot_t oj_cache8_get(Cache8 cache, sid_t key, slot_t **slot);
|
45
18
|
|
46
|
-
extern void
|
19
|
+
extern void oj_cache8_print(Cache8 cache);
|
47
20
|
|
48
21
|
#endif /* OJ_CACHE8_H */
|
data/ext/oj/circarray.c
CHANGED
@@ -1,68 +1,62 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
* All rights reserved.
|
4
|
-
*/
|
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.
|
5
3
|
|
6
4
|
#include "circarray.h"
|
7
5
|
|
8
|
-
CircArray
|
9
|
-
|
10
|
-
|
11
|
-
|
6
|
+
CircArray oj_circ_array_new() {
|
7
|
+
CircArray ca;
|
8
|
+
|
12
9
|
if (0 == (ca = ALLOC(struct _circArray))) {
|
13
|
-
|
10
|
+
rb_raise(rb_eNoMemError, "not enough memory\n");
|
14
11
|
}
|
15
12
|
ca->objs = ca->obj_array;
|
16
13
|
ca->size = sizeof(ca->obj_array) / sizeof(VALUE);
|
17
|
-
ca->cnt
|
18
|
-
|
14
|
+
ca->cnt = 0;
|
15
|
+
|
19
16
|
return ca;
|
20
17
|
}
|
21
18
|
|
22
|
-
void
|
23
|
-
oj_circ_array_free(CircArray ca) {
|
19
|
+
void oj_circ_array_free(CircArray ca) {
|
24
20
|
if (ca->objs != ca->obj_array) {
|
25
|
-
|
21
|
+
xfree(ca->objs);
|
26
22
|
}
|
27
23
|
xfree(ca);
|
28
24
|
}
|
29
25
|
|
30
|
-
void
|
31
|
-
oj_circ_array_set(CircArray ca, VALUE obj, unsigned long id) {
|
26
|
+
void oj_circ_array_set(CircArray ca, VALUE obj, unsigned long id) {
|
32
27
|
if (0 < id && 0 != ca) {
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
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
|
+
}
|
56
51
|
}
|
57
52
|
}
|
58
53
|
|
59
54
|
VALUE
|
60
55
|
oj_circ_array_get(CircArray ca, unsigned long id) {
|
61
|
-
VALUE
|
56
|
+
VALUE obj = Qnil;
|
62
57
|
|
63
58
|
if (id <= ca->cnt && 0 != ca) {
|
64
|
-
|
59
|
+
obj = ca->objs[id - 1];
|
65
60
|
}
|
66
61
|
return obj;
|
67
62
|
}
|
68
|
-
|