oj 3.13.2 → 3.13.3

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.
data/ext/oj/wab.c CHANGED
@@ -305,11 +305,14 @@ static VALUE calc_hash_key(ParseInfo pi, Val parent) {
305
305
  if (Yes == pi->options.cache_keys) {
306
306
  rkey = oj_sym_intern(parent->key, parent->klen);
307
307
  } else {
308
- rkey = rb_str_new(parent->key, parent->klen);
309
- rkey = oj_encode(rkey);
308
+ #if HAVE_RB_ENC_INTERNED_STR
309
+ rkey = rb_enc_interned_str(parent->key, parent->klen, oj_utf8_encoding);
310
+ #else
311
+ rkey = rb_utf8_str_new(parent->key, parent->klen);
310
312
  rkey = rb_str_intern(rkey);
313
+ OBJ_FREEZE(rkey);
314
+ #endif
311
315
  }
312
- OBJ_FREEZE(rkey);
313
316
  return rkey;
314
317
  }
315
318
 
data/lib/oj/state.rb CHANGED
@@ -1,7 +1,7 @@
1
1
 
2
2
  module JSON
3
3
  module Ext
4
- module Generator
4
+ module Generator
5
5
  unless defined?(::JSON::Ext::Generator::State)
6
6
  # This class exists for json gem compatibility only. While it can be
7
7
  # used as the options for other than compatibility a simple Hash is
@@ -44,11 +44,11 @@ module JSON
44
44
  def to_h()
45
45
  return @attrs.dup
46
46
  end
47
-
47
+
48
48
  def to_hash()
49
49
  return @attrs.dup
50
50
  end
51
-
51
+
52
52
  def allow_nan?()
53
53
  @attrs[:allow_nan]
54
54
  end
@@ -104,7 +104,7 @@ module JSON
104
104
  def has_key?(k)
105
105
  @attrs.has_key?(key.to_sym)
106
106
  end
107
-
107
+
108
108
  # Handles requests for Hash values. Others cause an Exception to be raised.
109
109
  # @param [Symbol|String] m method symbol
110
110
  # @return [Boolean] the value of the specified instance variable.
@@ -116,11 +116,12 @@ module JSON
116
116
  m = m.to_s[0..-2]
117
117
  m = m.to_sym
118
118
  return @attrs.store(m, args[0])
119
- else
119
+ end
120
+ if @attrs.has_key?(m.to_sym)
120
121
  raise ArgumentError.new("wrong number of arguments (#{args.size} for 0 with #{m}) to method #{m}") unless args.nil? or args.empty?
121
122
  return @attrs[m.to_sym]
122
- end
123
- raise NoMethodError.new("undefined method #{m}", m)
123
+ end
124
+ return @attrs.send(m, *args, &block)
124
125
  end
125
126
 
126
127
  end # State
data/lib/oj/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
 
2
2
  module Oj
3
3
  # Current version of the module.
4
- VERSION = '3.13.2'
4
+ VERSION = '3.13.3'
5
5
  end
data/test/mem.rb ADDED
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ $: << '.'
5
+ $: << File.join(File.dirname(__FILE__), "../lib")
6
+ $: << File.join(File.dirname(__FILE__), "../ext")
7
+
8
+ require 'oj'
9
+
10
+ Oj.default_options = { mode: :rails, cache_keys: false, cache_str: -1 }
11
+
12
+ def mem
13
+ `ps -o rss= -p #{$$}`.to_i
14
+ end
15
+
16
+ ('a'..'z').each { |a|
17
+ ('a'..'z').each { |b|
18
+ ('a'..'z').each { |c|
19
+ ('a'..'z').each { |d|
20
+ ('a'..'z').each { |e|
21
+ ('a'..'z').each { |f|
22
+ key = "#{a}#{b}#{c}#{d}#{e}#{f}"
23
+ x = Oj.load(%|{ "#{key}": 101}|)
24
+ #Oj.dump(x)
25
+ }
26
+ }
27
+ }
28
+ }
29
+ puts "#{a}#{b} #{mem}"
30
+ }
31
+ }
32
+
33
+ Oj::Parser.new(:usual)
data/test/perf_once.rb ADDED
@@ -0,0 +1,58 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ $: << '.'
5
+ $: << File.join(File.dirname(__FILE__), "../lib")
6
+ $: << File.join(File.dirname(__FILE__), "../ext")
7
+
8
+ require 'oj'
9
+
10
+ filename = 'tmp.json'
11
+ File.open(filename, "w") { |f|
12
+ cnt = 0
13
+ f.puts('{')
14
+ ('a'..'z').each { |a|
15
+ ('a'..'z').each { |b|
16
+ ('a'..'z').each { |c|
17
+ ('a'..'z').each { |d|
18
+ f.puts(%|"#{a}#{b}#{c}#{d}":#{cnt},|)
19
+ cnt += 1
20
+ }
21
+ }
22
+ }
23
+ }
24
+ f.puts('"_last":0}')
25
+ }
26
+
27
+ def mem
28
+ `ps -o rss= -p #{$$}`.to_i
29
+ end
30
+
31
+ Oj.default_options = { mode: :strict, cache_keys: false, cache_str: -1 }
32
+ start = Time.now
33
+ Oj.load_file('tmp.json')
34
+ dur = Time.now - start
35
+ GC.start
36
+ puts "no cache duration: #{dur} @ #{mem}"
37
+
38
+ Oj.default_options = { cache_keys: true }
39
+ start = Time.now
40
+ Oj.load_file('tmp.json')
41
+ dur = Time.now - start
42
+ GC.start
43
+ puts "initial cache duration: #{dur} @ #{mem}"
44
+
45
+ start = Time.now
46
+ Oj.load_file('tmp.json')
47
+ dur = Time.now - start
48
+ GC.start
49
+ puts "second cache duration: #{dur} @ #{mem}"
50
+
51
+ 10.times{ GC.start }
52
+ start = Time.now
53
+ Oj.load_file('tmp.json')
54
+ dur = Time.now - start
55
+ GC.start
56
+ puts "after several GCs cache duration: #{dur} @ #{mem}"
57
+
58
+ # TBD check memory use
data/test/perf_parser.rb CHANGED
@@ -53,7 +53,7 @@ Oj.default_options = {create_id: '^', create_additions: true, class_cache: true}
53
53
  if $cache_keys
54
54
  Oj.default_options = {cache_keys: true, cache_str: 6, symbol_keys: $symbol_keys}
55
55
  else
56
- Oj.default_options = {cache_keys: false, cache_str: 0, symbol_keys: $symbol_keys}
56
+ Oj.default_options = {cache_keys: false, cache_str: -1, symbol_keys: $symbol_keys}
57
57
  end
58
58
  JSON.parser = JSON::Ext::Parser
59
59
 
@@ -164,6 +164,11 @@ $obj_json = %|{
164
164
  "juliet": "junk"
165
165
  }|
166
166
 
167
+
168
+ p_usual = Oj::Parser.new(:usual)
169
+ p_usual.cache_keys = $cache_keys
170
+ p_usual.cache_strings = ($cache_keys ? 6 : 0)
171
+ p_usual.symbol_keys = $symbol_keys
167
172
  p_usual.create_id = '^'
168
173
  p_usual.class_cache = true
169
174
  p_usual.ignore_json_create = true
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.13.2
4
+ version: 3.13.3
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-08-16 00:00:00.000000000 Z
11
+ date: 2021-08-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake-compiler
@@ -218,11 +218,13 @@ files:
218
218
  - test/json_gem/json_parser_test.rb
219
219
  - test/json_gem/json_string_matching_test.rb
220
220
  - test/json_gem/test_helper.rb
221
+ - test/mem.rb
221
222
  - test/perf.rb
222
223
  - test/perf_compat.rb
223
224
  - test/perf_fast.rb
224
225
  - test/perf_file.rb
225
226
  - test/perf_object.rb
227
+ - test/perf_once.rb
226
228
  - test/perf_parser.rb
227
229
  - test/perf_saj.rb
228
230
  - test/perf_scp.rb
@@ -347,11 +349,13 @@ test_files:
347
349
  - test/json_gem/json_parser_test.rb
348
350
  - test/json_gem/json_string_matching_test.rb
349
351
  - test/json_gem/test_helper.rb
352
+ - test/mem.rb
350
353
  - test/perf.rb
351
354
  - test/perf_compat.rb
352
355
  - test/perf_fast.rb
353
356
  - test/perf_file.rb
354
357
  - test/perf_object.rb
358
+ - test/perf_once.rb
355
359
  - test/perf_parser.rb
356
360
  - test/perf_saj.rb
357
361
  - test/perf_scp.rb