oj 3.12.0 → 3.12.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.
- checksums.yaml +4 -4
- data/ext/oj/compat.c +22 -14
- data/ext/oj/hash.c +28 -6
- data/ext/oj/oj.c +8 -1
- data/ext/oj/wab.c +11 -4
- data/lib/oj/mimic.rb +2 -0
- data/lib/oj/version.rb +1 -1
- data/test/foo.rb +9 -9
- metadata +2 -2
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/ext/oj/compat.c
CHANGED
@@ -26,22 +26,30 @@ static void hash_set_cstr(ParseInfo pi, Val kval, const char *str, size_t len, c
|
|
26
26
|
volatile VALUE rstr = oj_cstr_to_value(str, len, (size_t)pi->options.cache_str);
|
27
27
|
|
28
28
|
if (Qundef == rkey) {
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
if (
|
33
|
-
rkey
|
34
|
-
rkey = oj_encode(rkey);
|
35
|
-
rkey = rb_str_intern(rkey);
|
36
|
-
*slot = rkey;
|
37
|
-
rb_gc_register_address(slot);
|
29
|
+
if (Yes != pi->options.cache_keys) {
|
30
|
+
rkey = rb_str_new(key, klen);
|
31
|
+
rkey = oj_encode(rkey);
|
32
|
+
if (Yes == pi->options.sym_key) {
|
33
|
+
rkey = rb_str_intern(rkey);
|
38
34
|
}
|
39
35
|
} else {
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
36
|
+
VALUE *slot;
|
37
|
+
|
38
|
+
if (Yes == pi->options.sym_key) {
|
39
|
+
if (Qnil == (rkey = oj_sym_hash_get(key, klen, &slot))) {
|
40
|
+
rkey = rb_str_new(key, klen);
|
41
|
+
rkey = oj_encode(rkey);
|
42
|
+
rkey = rb_str_intern(rkey);
|
43
|
+
*slot = rkey;
|
44
|
+
rb_gc_register_address(slot);
|
45
|
+
}
|
46
|
+
} else {
|
47
|
+
if (Qnil == (rkey = oj_str_hash_get(key, klen, &slot))) {
|
48
|
+
rkey = rb_str_new(key, klen);
|
49
|
+
rkey = oj_encode(rkey);
|
50
|
+
*slot = rkey;
|
51
|
+
rb_gc_register_address(slot);
|
52
|
+
}
|
45
53
|
}
|
46
54
|
}
|
47
55
|
}
|
data/ext/oj/hash.c
CHANGED
@@ -5,8 +5,8 @@
|
|
5
5
|
|
6
6
|
#include <stdint.h>
|
7
7
|
|
8
|
-
#define
|
9
|
-
#define HASH_SLOT_CNT
|
8
|
+
#define HASH_SLOT_CNT ((uint32_t)8192)
|
9
|
+
#define HASH_MASK (HASH_SLOT_CNT - 1)
|
10
10
|
|
11
11
|
typedef struct _keyVal {
|
12
12
|
struct _keyVal *next;
|
@@ -104,8 +104,8 @@ static VALUE hash_get(Hash hash, const char *key, size_t len, VALUE **slotp, VAL
|
|
104
104
|
}
|
105
105
|
|
106
106
|
void oj_hash_print() {
|
107
|
-
|
108
|
-
KeyVal
|
107
|
+
uint32_t i;
|
108
|
+
KeyVal b;
|
109
109
|
|
110
110
|
for (i = 0; i < HASH_SLOT_CNT; i++) {
|
111
111
|
printf("%4d:", i);
|
@@ -116,6 +116,29 @@ void oj_hash_print() {
|
|
116
116
|
}
|
117
117
|
}
|
118
118
|
|
119
|
+
void oj_hash_sizes() {
|
120
|
+
uint32_t i;
|
121
|
+
KeyVal b;
|
122
|
+
int max = 0;
|
123
|
+
int min = 1000000;
|
124
|
+
|
125
|
+
for (i = 0; i < HASH_SLOT_CNT; i++) {
|
126
|
+
int cnt = 0;
|
127
|
+
|
128
|
+
for (b = str_hash.slots + i; 0 != b && 0 != b->key; b = b->next) {
|
129
|
+
cnt++;
|
130
|
+
}
|
131
|
+
// printf(" %4d\n", cnt);
|
132
|
+
if (max < cnt) {
|
133
|
+
max = cnt;
|
134
|
+
}
|
135
|
+
if (cnt < min) {
|
136
|
+
min = cnt;
|
137
|
+
}
|
138
|
+
}
|
139
|
+
printf("min: %d max: %d\n", min, max);
|
140
|
+
}
|
141
|
+
|
119
142
|
VALUE
|
120
143
|
oj_class_hash_get(const char *key, size_t len, VALUE **slotp) {
|
121
144
|
return hash_get(&class_hash, key, len, slotp, Qnil);
|
@@ -131,8 +154,7 @@ oj_sym_hash_get(const char *key, size_t len, VALUE **slotp) {
|
|
131
154
|
return hash_get(&sym_hash, key, len, slotp, Qnil);
|
132
155
|
}
|
133
156
|
|
134
|
-
ID
|
135
|
-
oj_attr_hash_get(const char *key, size_t len, ID **slotp) {
|
157
|
+
ID oj_attr_hash_get(const char *key, size_t len, ID **slotp) {
|
136
158
|
return (ID)hash_get(&intern_hash, key, len, (VALUE **)slotp, 0);
|
137
159
|
}
|
138
160
|
|
data/ext/oj/oj.c
CHANGED
@@ -1673,13 +1673,20 @@ extern VALUE oj_optimize_rails(VALUE self);
|
|
1673
1673
|
|
1674
1674
|
/*
|
1675
1675
|
extern void oj_hash_test();
|
1676
|
-
|
1677
1676
|
static VALUE
|
1678
1677
|
hash_test(VALUE self) {
|
1679
1678
|
oj_hash_test();
|
1680
1679
|
return Qnil;
|
1681
1680
|
}
|
1682
1681
|
*/
|
1682
|
+
/*
|
1683
|
+
extern void oj_hash_sizes();
|
1684
|
+
static VALUE
|
1685
|
+
hash_test(VALUE self) {
|
1686
|
+
oj_hash_sizes();
|
1687
|
+
return Qnil;
|
1688
|
+
}
|
1689
|
+
*/
|
1683
1690
|
|
1684
1691
|
static VALUE protect_require(VALUE x) {
|
1685
1692
|
rb_require("time");
|
data/ext/oj/wab.c
CHANGED
@@ -293,7 +293,7 @@ void oj_dump_wab_val(VALUE obj, int depth, Out out) {
|
|
293
293
|
|
294
294
|
///// load functions /////
|
295
295
|
|
296
|
-
static VALUE
|
296
|
+
static VALUE calc_hash_key(ParseInfo pi, Val parent) {
|
297
297
|
volatile VALUE rkey = parent->key_val;
|
298
298
|
|
299
299
|
if (Qundef != rkey) {
|
@@ -302,6 +302,13 @@ static VALUE oj_hash_key(Val parent) {
|
|
302
302
|
|
303
303
|
return rkey;
|
304
304
|
}
|
305
|
+
if (Yes != pi->options.cache_keys) {
|
306
|
+
rkey = rb_str_new(parent->key, parent->klen);
|
307
|
+
rkey = oj_encode(rkey);
|
308
|
+
rkey = rb_str_intern(rkey);
|
309
|
+
|
310
|
+
return rkey;
|
311
|
+
}
|
305
312
|
VALUE *slot;
|
306
313
|
|
307
314
|
if (Qnil == (rkey = oj_sym_hash_get(parent->key, parent->klen, &slot))) {
|
@@ -509,7 +516,7 @@ static VALUE start_hash(ParseInfo pi) {
|
|
509
516
|
static void hash_set_cstr(ParseInfo pi, Val parent, const char *str, size_t len, const char *orig) {
|
510
517
|
volatile VALUE rval = cstr_to_rstr(pi, str, len);
|
511
518
|
|
512
|
-
rb_hash_aset(stack_peek(&pi->stack)->val,
|
519
|
+
rb_hash_aset(stack_peek(&pi->stack)->val, calc_hash_key(pi, parent), rval);
|
513
520
|
if (Yes == pi->options.trace) {
|
514
521
|
oj_trace_parse_call("set_string", pi, __FILE__, __LINE__, rval);
|
515
522
|
}
|
@@ -522,14 +529,14 @@ static void hash_set_num(ParseInfo pi, Val parent, NumInfo ni) {
|
|
522
529
|
oj_set_error_at(pi, oj_parse_error_class, __FILE__, __LINE__, "not a number or other value");
|
523
530
|
}
|
524
531
|
rval = oj_num_as_value(ni);
|
525
|
-
rb_hash_aset(stack_peek(&pi->stack)->val,
|
532
|
+
rb_hash_aset(stack_peek(&pi->stack)->val, calc_hash_key(pi, parent), rval);
|
526
533
|
if (Yes == pi->options.trace) {
|
527
534
|
oj_trace_parse_call("set_number", pi, __FILE__, __LINE__, rval);
|
528
535
|
}
|
529
536
|
}
|
530
537
|
|
531
538
|
static void hash_set_value(ParseInfo pi, Val parent, VALUE value) {
|
532
|
-
rb_hash_aset(stack_peek(&pi->stack)->val,
|
539
|
+
rb_hash_aset(stack_peek(&pi->stack)->val, calc_hash_key(pi, parent), value);
|
533
540
|
if (Yes == pi->options.trace) {
|
534
541
|
oj_trace_parse_call("set_value", pi, __FILE__, __LINE__, value);
|
535
542
|
}
|
data/lib/oj/mimic.rb
CHANGED
data/lib/oj/version.rb
CHANGED
data/test/foo.rb
CHANGED
@@ -7,14 +7,14 @@ $oj_dir = File.dirname(File.expand_path(File.dirname(__FILE__)))
|
|
7
7
|
end
|
8
8
|
|
9
9
|
require 'oj'
|
10
|
-
require 'active_support'
|
11
10
|
|
12
|
-
Oj.default_options = {
|
11
|
+
Oj.default_options = {cache_keys: false, cache_str: 0}
|
13
12
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
13
|
+
[:compat, :strict, :object].each { |mode|
|
14
|
+
GC.start
|
15
|
+
t = Time.now
|
16
|
+
Oj.load_file('pt_lemma_lookup.json', mode: mode)
|
17
|
+
puts "#{mode}: #{Time.now - t}"
|
18
|
+
}
|
19
|
+
|
20
|
+
# check saj and scp
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oj
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.12.
|
4
|
+
version: 3.12.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Ohler
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-07-
|
11
|
+
date: 2021-07-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake-compiler
|