oj 3.7.10 → 3.7.12

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 19c25560b508ae039d9d517cb5eacb44b658e1359e11e95317b51ff94581ea6d
4
- data.tar.gz: 2ea2c2a50e8cf6d14a7c19427def90fefc460fbb626226c6299a91c8890fbeaf
3
+ metadata.gz: 596316b0a9a9e4fa7a82486f0589182f15a1c0c679d2d58f50357a291720cbfa
4
+ data.tar.gz: 3d58bd1344943d671222f1a7412c77731ecce70ddd3469a03ad15263374c243e
5
5
  SHA512:
6
- metadata.gz: 91ee09165357ad4955030f2d395f61578375c70672245483831d1c291fe76b50c1166c4d6d75435d4961a6aac394d03069320cb8e15e6b352cf6c634d5ab0b5d
7
- data.tar.gz: ea098163b5b4297777de3dcdfc1468673114ba264fd7f2733620ffe14d3ef784384ac0b8fa8c0482f5303b5c4f47164943462266af91d1662ed4eeee5d893656
6
+ metadata.gz: 4273557f2d93c634e3a9ffc789a503f80ee5ca80a8031c1406a63a3e926648dd15294faa8820d6f6c63a625b9be4a34dd36bbde954ba8f68fe418f7182a84f55
7
+ data.tar.gz: ad6468ca75db3d8ebc792fcabbf417490c2cfe2927ab4859ef1c059fe36b8bad1c311fa03608a878350dd8324d3ab75887728a6ec4af1ffb1ea8739027642c69
@@ -8,7 +8,7 @@
8
8
  #include "dump.h"
9
9
  #include "parse.h"
10
10
 
11
- static VALUE symbolize_names_sym;
11
+ static VALUE symbolize_names_sym = Qundef;
12
12
 
13
13
  extern const char oj_json_class[];
14
14
 
@@ -26,30 +26,30 @@ static VALUE state_class;
26
26
  // mimic JSON documentation
27
27
 
28
28
  /* Document-module: JSON::Ext
29
- *
29
+ *
30
30
  * The Ext module is a placeholder in the mimic JSON module used for
31
31
  * compatibility only.
32
32
  */
33
33
  /* Document-class: JSON::Ext::Parser
34
- *
34
+ *
35
35
  * The JSON::Ext::Parser is a placeholder in the mimic JSON module used for
36
36
  * compatibility only.
37
37
  */
38
38
  /* Document-class: JSON::Ext::Generator
39
- *
39
+ *
40
40
  * The JSON::Ext::Generator is a placeholder in the mimic JSON module used for
41
41
  * compatibility only.
42
42
  */
43
43
 
44
44
  /* Document-method: parser=
45
45
  * call-seq: parser=(parser)
46
- *
46
+ *
47
47
  * Does nothing other than provide compatibility.
48
48
  * - *parser* [_Object_] ignored
49
49
  */
50
50
  /* Document-method: generator=
51
51
  * call-seq: generator=(generator)
52
- *
52
+ *
53
53
  * Does nothing other than provide compatibility.
54
54
  * - *generator* [_Object_] ignored
55
55
  */
@@ -184,9 +184,9 @@ mimic_limit_arg(VALUE a) {
184
184
 
185
185
  /* Document-method: dump
186
186
  * call-seq: dump(obj, anIO=nil, limit=nil)
187
- *
187
+ *
188
188
  * Encodes an object as a JSON String.
189
- *
189
+ *
190
190
  * - *obj* [_Object_] object to convert to encode as JSON
191
191
  * - *anIO* [_IO_] an IO that allows writing
192
192
  * - *limit* [_Fixnum_] ignored
@@ -218,7 +218,7 @@ mimic_dump(int argc, VALUE *argv, VALUE self) {
218
218
  out.omit_nil = copts.dump_opts.omit_nil;
219
219
  if (2 <= argc) {
220
220
  int limit;
221
-
221
+
222
222
  // The json gem take a more liberal approach to optional
223
223
  // arguments. Expected are (obj, anIO=nil, limit=nil) yet the io
224
224
  // argument can be left off completely and the 2nd argument is then
@@ -285,11 +285,11 @@ mimic_walk(VALUE key, VALUE obj, VALUE proc) {
285
285
 
286
286
  /* Document-method: restore
287
287
  * call-seq: restore(source, proc=nil)
288
- *
288
+ *
289
289
  * Loads a Ruby Object from a JSON source that can be either a String or an
290
290
  * IO. If Proc is given or a block is providedit is called with each nested
291
291
  * element of the loaded Object.
292
- *
292
+ *
293
293
  * - *source* [_String_|IO] JSON source
294
294
  * - *proc* [_Proc_] to yield to on each element or nil
295
295
  *
@@ -298,11 +298,11 @@ mimic_walk(VALUE key, VALUE obj, VALUE proc) {
298
298
 
299
299
  /* Document-method: load
300
300
  * call-seq: load(source, proc=nil)
301
- *
301
+ *
302
302
  * Loads a Ruby Object from a JSON source that can be either a String or an
303
303
  * IO. If Proc is given or a block is providedit is called with each nested
304
304
  * element of the loaded Object.
305
- *
305
+ *
306
306
  * - *source* [_String_|IO] JSON source
307
307
  * - *proc* [_Proc_] to yield to on each element or nil
308
308
  *
@@ -330,10 +330,10 @@ mimic_load(int argc, VALUE *argv, VALUE self) {
330
330
 
331
331
  /* Document-method: []
332
332
  * call-seq: [](obj, opts={})
333
- *
333
+ *
334
334
  * If the obj argument is a String then it is assumed to be a JSON String and
335
335
  * parsed otherwise the obj is encoded as a JSON String.
336
- *
336
+ *
337
337
  * - *obj* [_String_|Hash|Array] object to convert
338
338
  * - *opts* [_Hash_] same options as either generate or parse
339
339
  *
@@ -396,11 +396,11 @@ mimic_generate_core(int argc, VALUE *argv, Options copts) {
396
396
 
397
397
  /* Document-method: generate
398
398
  * call-seq: generate(obj, opts=nil)
399
- *
399
+ *
400
400
  * Encode obj as a JSON String. The obj argument must be a Hash, Array, or
401
401
  * respond to to_h or to_json. Options other than those listed such as
402
402
  * +:allow_nan+ or +:max_nesting+ are ignored.
403
- *
403
+ *
404
404
  * - *obj* [_Object_|Hash|Array] object to convert to a JSON String
405
405
  * - *opts* [_Hash_] options
406
406
  * - - *:indent* [_String_] String to use for indentation.
@@ -461,7 +461,7 @@ oj_mimic_pretty_generate(int argc, VALUE *argv, VALUE self) {
461
461
  rb_hash_aset(h, oj_array_nl_sym, rb_str_new2("\n"));
462
462
  }
463
463
  rargs[1] = rb_funcall(state_class, oj_new_id, 1, h);
464
-
464
+
465
465
  copts.str_rx.head = NULL;
466
466
  copts.str_rx.tail = NULL;
467
467
  strcpy(copts.dump_opts.indent_str, " ");
@@ -510,6 +510,9 @@ mimic_parse_core(int argc, VALUE *argv, VALUE self, bool bang) {
510
510
  if (T_HASH != rb_type(ropts)) {
511
511
  rb_raise(rb_eArgError, "options must be a hash.");
512
512
  }
513
+ if (Qundef == symbolize_names_sym) {
514
+ symbolize_names_sym = ID2SYM(rb_intern("symbolize_names")); rb_gc_register_address(&symbolize_names_sym);
515
+ }
513
516
  if (Qnil != (v = rb_hash_lookup(ropts, symbolize_names_sym))) {
514
517
  pi.options.sym_key = (Qtrue == v) ? Yes : No;
515
518
  }
@@ -602,9 +605,9 @@ mimic_parse_bang(int argc, VALUE *argv, VALUE self) {
602
605
 
603
606
  /* Document-method: recurse_proc
604
607
  * call-seq: recurse_proc(obj, &proc)
605
- *
608
+ *
606
609
  * Yields to the proc for every element in the obj recursively.
607
- *
610
+ *
608
611
  * - *obj* [_Hash_|Array] object to walk
609
612
  * - *proc* [_Proc_] to yield to on each element
610
613
  */
@@ -834,7 +837,7 @@ oj_define_mimic_json(int argc, VALUE *argv, VALUE self) {
834
837
  VALUE dummy;
835
838
  VALUE verbose;
836
839
  VALUE json;
837
-
840
+
838
841
  // Either set the paths to indicate JSON has been loaded or replaces the
839
842
  // methods if it has been loaded.
840
843
  if (rb_const_defined_at(rb_cObject, rb_intern("JSON"))) {
@@ -117,7 +117,7 @@ dump_attr_cb(ID key, VALUE value, Out out) {
117
117
  dump_rails_val(value, depth, out, true);
118
118
  out->depth = depth;
119
119
  *out->cur++ = ',';
120
-
120
+
121
121
  return ST_CONTINUE;
122
122
  }
123
123
 
@@ -230,7 +230,7 @@ dump_sec_nano(VALUE obj, int64_t sec, long nsec, Out out) {
230
230
  int tzhour, tzmin;
231
231
  char tzsign = '+';
232
232
  int len;
233
-
233
+
234
234
  if (out->end - out->cur <= 36) {
235
235
  assure_size(out, 36);
236
236
  }
@@ -353,7 +353,7 @@ columns_array(VALUE rcols, int *ccnt) {
353
353
  StrLen cols;
354
354
  int i;
355
355
  int cnt = (int)RARRAY_LEN(rcols);
356
-
356
+
357
357
  *ccnt = cnt;
358
358
  cols = ALLOC_N(struct _strLen, cnt);
359
359
  for (i = 0, cp = cols; i < cnt; i++, cp++) {
@@ -372,7 +372,7 @@ dump_row(VALUE row, StrLen cols, int ccnt, int depth, Out out) {
372
372
  size_t size;
373
373
  int d2 = depth + 1;
374
374
  int i;
375
-
375
+
376
376
  assure_size(out, 2);
377
377
  *out->cur++ = '{';
378
378
  size = depth * out->indent + 3;
@@ -432,7 +432,7 @@ dump_activerecord_result(VALUE obj, int depth, Out out, bool as_ok) {
432
432
  int i, rcnt;
433
433
  size_t size;
434
434
  int d2 = depth + 1;
435
-
435
+
436
436
  if (0 == rows_id) {
437
437
  rows_id = rb_intern("@rows");
438
438
  columns_id = rb_intern("@columns");
@@ -597,7 +597,7 @@ create_opt(ROptTable rot, VALUE clas) {
597
597
  ro = &rot->table[olen];
598
598
  } else {
599
599
  int i;
600
-
600
+
601
601
  for (i = 0, ro = rot->table; i < olen; i++, ro++) {
602
602
  if (clas < ro->clas) {
603
603
  memmove(ro + 1, ro, sizeof(struct _rOpt) * (olen - i));
@@ -672,7 +672,7 @@ encoder_new(int argc, VALUE *argv, VALUE self) {
672
672
  e->opts = oj_default_options;
673
673
  e->arg = Qnil;
674
674
  copy_opts(&ropts, &e->ropts);
675
-
675
+
676
676
  if (1 <= argc && Qnil != *argv) {
677
677
  oj_parse_options(*argv, &e->opts);
678
678
  e->arg = *argv;
@@ -727,7 +727,7 @@ optimize(int argc, VALUE *argv, ROptTable rot, bool on) {
727
727
  int i;
728
728
  NamedFunc nf;
729
729
  VALUE clas;
730
-
730
+
731
731
  oj_rails_hash_opt = on;
732
732
  oj_rails_array_opt = on;
733
733
  oj_rails_float_opt = on;
@@ -759,14 +759,14 @@ optimize(int argc, VALUE *argv, ROptTable rot, bool on) {
759
759
 
760
760
  /* Document-method optimize
761
761
  * call-seq: optimize(*classes)
762
- *
762
+ *
763
763
  * Use Oj rails optimized routines to encode the specified classes. This
764
764
  * ignores the as_json() method on the class and uses an internal encoding
765
765
  * instead. Passing in no classes indicates all should use the optimized
766
766
  * version of encoding for all previously optimized classes. Passing in the
767
767
  * Object class set a global switch that will then use the optimized behavior
768
768
  * for all classes.
769
- *
769
+ *
770
770
  * - *classes* [_Class_] a list of classes to optimize
771
771
  */
772
772
  static VALUE
@@ -780,14 +780,14 @@ encoder_optimize(int argc, VALUE *argv, VALUE self) {
780
780
 
781
781
  /* Document-method: optimize
782
782
  * call-seq: optimize(*classes)
783
- *
783
+ *
784
784
  * Use Oj rails optimized routines to encode the specified classes. This
785
785
  * ignores the as_json() method on the class and uses an internal encoding
786
786
  * instead. Passing in no classes indicates all should use the optimized
787
787
  * version of encoding for all previously optimized classes. Passing in the
788
788
  * Object class set a global switch that will then use the optimized behavior
789
789
  * for all classes.
790
- *
790
+ *
791
791
  * - *classes* [_Class_] a list of classes to optimize
792
792
  */
793
793
  static VALUE
@@ -806,7 +806,7 @@ rails_optimize(int argc, VALUE *argv, VALUE self) {
806
806
  VALUE
807
807
  rails_mimic_json(VALUE self) {
808
808
  VALUE json;
809
-
809
+
810
810
  if (rb_const_defined_at(rb_cObject, rb_intern("JSON"))) {
811
811
  json = rb_const_get_at(rb_cObject, rb_intern("JSON"));
812
812
  } else {
@@ -820,7 +820,7 @@ rails_mimic_json(VALUE self) {
820
820
 
821
821
  /* Document-method: deoptimize
822
822
  * call-seq: deoptimize(*classes)
823
- *
823
+ *
824
824
  * Turn off Oj rails optimization on the specified classes.
825
825
  *
826
826
  * - *classes* [_Class_] a list of classes to deoptimize
@@ -836,7 +836,7 @@ encoder_deoptimize(int argc, VALUE *argv, VALUE self) {
836
836
 
837
837
  /* Document-method: deoptimize
838
838
  * call-seq: deoptimize(*classes)
839
- *
839
+ *
840
840
  * Turn off Oj rails optimization on the specified classes.
841
841
  *
842
842
  * - *classes* [_Class_] a list of classes to deoptimize
@@ -850,7 +850,7 @@ rails_deoptimize(int argc, VALUE *argv, VALUE self) {
850
850
 
851
851
  /* Document-method:optimized?
852
852
  * call-seq: optimized?(clas)
853
- *
853
+ *
854
854
  * - *clas* [_Class_] Class to check
855
855
  *
856
856
  * @return true if the class is being optimized for rails and false otherwise
@@ -868,7 +868,7 @@ encoder_optimized(VALUE self, VALUE clas) {
868
868
 
869
869
  /* Document-method: optimized?
870
870
  * call-seq: optimized?(clas)
871
- *
871
+ *
872
872
  * Returns true if the specified Class is being optimized.
873
873
  */
874
874
  static VALUE
@@ -966,7 +966,7 @@ encode(VALUE obj, ROptTable ropts, Options opts, int argc, VALUE *argv) {
966
966
 
967
967
  /* Document-method: encode
968
968
  * call-seq: encode(obj)
969
- *
969
+ *
970
970
  * - *obj* [_Object_] object to encode
971
971
  *
972
972
  * Returns encoded object as a JSON string.
@@ -977,7 +977,7 @@ encoder_encode(VALUE self, VALUE obj) {
977
977
 
978
978
  if (Qnil != e->arg) {
979
979
  VALUE argv[1] = { e->arg };
980
-
980
+
981
981
  return encode(obj, &e->ropts, &e->opts, 1, argv);
982
982
  }
983
983
  return encode(obj, &e->ropts, &e->opts, 0, NULL);
@@ -985,9 +985,9 @@ encoder_encode(VALUE self, VALUE obj) {
985
985
 
986
986
  /* Document-method: encode
987
987
  * call-seq: encode(obj, opts=nil)
988
- *
988
+ *
989
989
  * Encode obj as a JSON String.
990
- *
990
+ *
991
991
  * - *obj* [_Object_|Hash|Array] object to convert to a JSON String
992
992
  * - *opts* [_Hash_] options
993
993
  *
@@ -1037,7 +1037,7 @@ rails_time_precision(VALUE self, VALUE prec) {
1037
1037
 
1038
1038
  /* Document-method: set_encoder
1039
1039
  * call-seq: set_encoder()
1040
- *
1040
+ *
1041
1041
  * Sets the ActiveSupport.encoder to Oj::Rails::Encoder and wraps some of the
1042
1042
  * formatting globals used by ActiveSupport to allow the use of those globals
1043
1043
  * in the Oj::Rails optimizations.
@@ -1049,7 +1049,7 @@ rails_set_encoder(VALUE self) {
1049
1049
  VALUE encoding;
1050
1050
  VALUE pv;
1051
1051
  VALUE verbose;
1052
-
1052
+
1053
1053
  if (rb_const_defined_at(rb_cObject, rb_intern("ActiveSupport"))) {
1054
1054
  active = rb_const_get_at(rb_cObject, rb_intern("ActiveSupport"));
1055
1055
  } else {
@@ -1090,7 +1090,7 @@ rails_set_decoder(VALUE self) {
1090
1090
  VALUE json;
1091
1091
  VALUE json_error;
1092
1092
  VALUE verbose;
1093
-
1093
+
1094
1094
  if (rb_const_defined_at(rb_cObject, rb_intern("JSON"))) {
1095
1095
  json = rb_const_get_at(rb_cObject, rb_intern("JSON"));
1096
1096
  } else {
@@ -1113,7 +1113,7 @@ rails_set_decoder(VALUE self) {
1113
1113
  rb_undef_method(json, "parse");
1114
1114
  rb_define_module_function(json, "parse", oj_mimic_parse, -1);
1115
1115
  rb_gv_set("$VERBOSE", verbose);
1116
-
1116
+
1117
1117
  return Qnil;
1118
1118
  }
1119
1119
 
@@ -1133,7 +1133,7 @@ oj_optimize_rails(VALUE self) {
1133
1133
  }
1134
1134
 
1135
1135
  /* Document-module: Oj::Rails
1136
- *
1136
+ *
1137
1137
  * Module that provides rails and active support compatibility.
1138
1138
  */
1139
1139
  /* Document-class: Oj::Rails::Encoder
@@ -1143,7 +1143,7 @@ oj_optimize_rails(VALUE self) {
1143
1143
  void
1144
1144
  oj_mimic_rails_init() {
1145
1145
  VALUE rails = rb_define_module_under(Oj, "Rails");
1146
-
1146
+
1147
1147
  rb_define_module_function(rails, "encode", rails_encode, -1);
1148
1148
 
1149
1149
  encoder_class = rb_define_class_under(rails, "Encoder", rb_cObject);
@@ -1283,7 +1283,10 @@ hash_cb(VALUE key, VALUE value, Out out) {
1283
1283
  int depth = out->depth;
1284
1284
  long size;
1285
1285
  int rtype = rb_type(key);
1286
-
1286
+
1287
+ if (out->omit_nil && Qnil == value) {
1288
+ return ST_CONTINUE;
1289
+ }
1287
1290
  if (rtype != T_STRING && rtype != T_SYMBOL) {
1288
1291
  key = rb_funcall(key, oj_to_s_id, 0);
1289
1292
  rtype = rb_type(key);
@@ -31,7 +31,7 @@ module Oj
31
31
  end
32
32
 
33
33
  # Loads mimic-ed JSON paths. Used by Oj.mimic_JSON().
34
- # @param mimic_path [Array] additional paths to add to the Ruby loaded features.
34
+ # @param mimic_paths [Array] additional paths to add to the Ruby loaded features.
35
35
  def self.mimic_loaded(mimic_paths=[])
36
36
  $LOAD_PATH.each do |d|
37
37
  next unless File.exist?(d)
@@ -1,5 +1,5 @@
1
1
 
2
2
  module Oj
3
3
  # Current version of the module.
4
- VERSION = '3.7.10'
4
+ VERSION = '3.7.12'
5
5
  end
@@ -1,22 +1,15 @@
1
- #!/usr/bin/env ruby
2
- # encoding: UTF-8
3
-
4
- #$VERBOSE = true
5
-
6
- %w(lib ext test).each do |dir|
7
- $LOAD_PATH.unshift File.expand_path("../../#{dir}", __FILE__)
8
- end
9
-
10
- require 'active_support'
11
- require 'active_support/core_ext'
12
- require 'active_support/json'
1
+ #require 'active_support'
2
+ #require 'active_support/core_ext'
3
+ #require 'active_support/json'
13
4
  require 'oj'
14
5
 
15
- Oj.optimize_rails
6
+ #Oj.optimize_rails
7
+ Oj.mimic_JSON
16
8
 
17
9
  h = {:type=>:record, :name=>:group, :namespace=>"com.salsify.identity", :fields=>[{:name=>"id", :type=>{:name=>:salsify_uuid, :type=>:fixed, :namespace=>"com.salsify", :size=>38}}, {:name=>"type", :type=>"string", :default=>"groups"}, {:name=>"external_id", :type=>[:null, "string"], :default=>nil}, {:name=>"created_at", :type=>{:type=>"long", :logicalType=>"timestamp-micros"}}, {:name=>"updated_at", :type=>{:type=>"long", :logicalType=>"timestamp-micros"}}, {:name=>"name", :type=>"string"}, {:name=>"policy", :type=>[:null, {:type=>:record, :name=>:policy, :namespace=>"com.salsify.security", :fields=>[{:name=>"created_at", :type=>{:type=>"long", :logicalType=>"timestamp-micros"}}, {:name=>"updated_at", :type=>{:type=>"long", :logicalType=>"timestamp-micros"}}, {:name=>"id", :type=>"com.salsify.salsify_uuid"}, {:name=>"type", :type=>"string", :default=>"policies"}, {:name=>"external_id", :type=>[:null, "string"], :default=>nil}, {:name=>"name", :type=>"string"}, {:name=>"statements", :type=>{:type=>:array, :items=>{:type=>:record, :name=>:statement, :namespace=>"com.salsify.security", :fields=>[{:name=>"created_at", :type=>{:type=>"long", :logicalType=>"timestamp-micros"}}, {:name=>"updated_at", :type=>{:type=>"long", :logicalType=>"timestamp-micros"}}, {:name=>"id", :type=>"com.salsify.salsify_uuid"}, {:name=>"type", :type=>"string", :default=>"statements"}, {:name=>"external_id", :type=>[:null, "string"], :default=>nil}, {:name=>"action", :type=>{:name=>"__statement_action_enum", :type=>:enum, :namespace=>"com.salsify.security", :symbols=>[:manage, :read]}}, {:name=>"resource", :type=>{:name=>"__statement_resource_enum", :type=>:enum, :namespace=>"com.salsify.security", :symbols=>[:product, :digital_asset]}}, {:name=>"conditions", :type=>{:type=>:array, :items=>{:type=>:record, :name=>:condition, :namespace=>"com.salsify.security", :fields=>[{:name=>"created_at", :type=>{:type=>"long", :logicalType=>"timestamp-micros"}}, {:name=>"updated_at", :type=>{:type=>"long", :logicalType=>"timestamp-micros"}}, {:name=>"id", :type=>"com.salsify.salsify_uuid"}, {:name=>"type", :type=>"string", :default=>"conditions"}, {:name=>"external_id", :type=>[:null, "string"], :default=>nil}, {:name=>"operator", :type=>{:name=>"__condition_operator_enum", :type=>:enum, :namespace=>"com.salsify.security", :symbols=>[:equals]}}, {:name=>"attribute_type", :type=>{:name=>"__condition_attribute_type_enum", :type=>:enum, :namespace=>"com.salsify.security", :symbols=>[:resource]}}, {:name=>"value", :type=>"string"}, {:name=>"attribute", :type=>[:null, {:type=>:record, :name=>:reference, :namespace=>"com.salsify", :fields=>[{:name=>"id", :type=>"com.salsify.salsify_uuid"}, {:name=>"type", :type=>"string", :doc=>"snake_case, plural name for the resource type"}, {:name=>"external_id", :type=>[:null, "string"], :default=>nil}]}], :default=>nil}, {:name=>"broken", :type=>[:null, "boolean"], :default=>nil}]}}}]}}}]}], :default=>nil}]}
18
10
 
19
- 100000.times {
20
- JSON.pretty_generate(h)
21
- }
11
+ #Oj.dump(h)
12
+ puts JSON.pretty_generate(h)
13
+ #puts JSON.fast_generate(h)
22
14
  #puts JSON.generate(h)
15
+
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $: << '.'
4
+ $: << '../lib'
5
+ $: << '../ext'
6
+
7
+ require 'oj'
8
+
9
+ f = File.open("foo.json", "w")
10
+ 100_000.times do
11
+ obj = { created_at: DateTime.new(2001,2,3,4,5,6) }
12
+ Oj.to_stream(f, obj)
13
+ f.puts
14
+ f.flush
15
+ end
16
+ f.close
17
+
18
+ def run_test_thread
19
+ threads = Array.new(3) do
20
+ Thread.new do
21
+ counter = 0
22
+ File.open("foo.json", "r") { |f| Oj.enum_for(:load, f).lazy.each { counter += 1 } }
23
+ #File.open("odd_file.jsonl", "r") { |f| Oj.enum_for(:load, f).lazy.each { counter += 1 } }
24
+ puts counter
25
+ end
26
+ end
27
+ threads.each(&:join)
28
+ end
29
+
30
+ 100.times do |i|
31
+ puts i
32
+ run_test_thread
33
+ end
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $: << '.'
4
+ $: << '../lib'
5
+ $: << '../ext'
6
+
7
+ require 'objspace'
8
+ require 'oj'
9
+ require 'json'
10
+ require 'get_process_mem'
11
+
12
+ def record_allocation
13
+ GC.start
14
+ GC.start
15
+
16
+ mem = GetProcessMem.new
17
+ puts "Before - Process Memory: #{mem.mb} mb"
18
+ puts "Before - Objects count: #{ObjectSpace.each_object.count}"
19
+ puts "Before - Symbols count: #{Symbol.all_symbols.size}"
20
+
21
+ yield
22
+
23
+ GC.start
24
+ GC.start
25
+ GC.start
26
+
27
+ puts "After - Process Memory: #{mem.mb} mb"
28
+ puts "After - Objects count: #{ObjectSpace.each_object.count}"
29
+ puts "After - Symbols count: #{Symbol.all_symbols.size}"
30
+ end
31
+
32
+ record_allocation do
33
+ data = 1_000_000.times.map { |i| "string_number_#{i}".to_sym } # array of symbols
34
+ Oj.dump(data, mode: :rails)
35
+ end
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.7.10
4
+ version: 3.7.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Ohler
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-03-14 00:00:00.000000000 Z
11
+ date: 2019-04-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake-compiler
@@ -79,16 +79,16 @@ extensions:
79
79
  - ext/oj/extconf.rb
80
80
  extra_rdoc_files:
81
81
  - README.md
82
+ - pages/Modes.md
82
83
  - pages/Advanced.md
83
- - pages/Compatibility.md
84
+ - pages/Options.md
84
85
  - pages/Custom.md
86
+ - pages/Compatibility.md
87
+ - pages/WAB.md
88
+ - pages/Security.md
85
89
  - pages/Encoding.md
86
90
  - pages/JsonGem.md
87
- - pages/Modes.md
88
- - pages/Options.md
89
91
  - pages/Rails.md
90
- - pages/Security.md
91
- - pages/WAB.md
92
92
  files:
93
93
  - LICENSE
94
94
  - README.md
@@ -177,9 +177,9 @@ files:
177
177
  - test/activesupport5/encoding_test_cases.rb
178
178
  - test/activesupport5/test_helper.rb
179
179
  - test/activesupport5/time_zone_test_helpers.rb
180
- - test/bug.rb
181
- - test/crash.rb
180
+ - test/big.rb
182
181
  - test/files.rb
182
+ - test/foo.rb
183
183
  - test/helper.rb
184
184
  - test/isolated/shared.rb
185
185
  - test/isolated/test_mimic_after.rb
@@ -200,6 +200,7 @@ files:
200
200
  - test/json_gem/json_parser_test.rb
201
201
  - test/json_gem/json_string_matching_test.rb
202
202
  - test/json_gem/test_helper.rb
203
+ - test/mem.rb
203
204
  - test/perf.rb
204
205
  - test/perf_compat.rb
205
206
  - test/perf_fast.rb
@@ -272,86 +273,87 @@ required_rubygems_version: !ruby/object:Gem::Requirement
272
273
  - !ruby/object:Gem::Version
273
274
  version: '0'
274
275
  requirements: []
275
- rubygems_version: 3.0.1
276
+ rubygems_version: 3.0.3
276
277
  signing_key:
277
278
  specification_version: 4
278
279
  summary: A fast JSON parser and serializer.
279
280
  test_files:
280
- - test/_test_active.rb
281
- - test/_test_active_mimic.rb
282
- - test/_test_mimic_rails.rb
283
- - test/activerecord/result_test.rb
281
+ - test/perf_file.rb
282
+ - test/test_hash.rb
283
+ - test/perf.rb
284
+ - test/test_object.rb
285
+ - test/test_null.rb
286
+ - test/test_compat.rb
287
+ - test/test_custom.rb
288
+ - test/perf_scp.rb
289
+ - test/test_integer_range.rb
290
+ - test/test_gc.rb
291
+ - test/sample.rb
292
+ - test/json_gem/json_string_matching_test.rb
293
+ - test/json_gem/json_addition_test.rb
294
+ - test/json_gem/test_helper.rb
295
+ - test/json_gem/json_generator_test.rb
296
+ - test/json_gem/json_parser_test.rb
297
+ - test/json_gem/json_encoding_test.rb
298
+ - test/json_gem/json_common_interface_test.rb
299
+ - test/json_gem/json_generic_object_test.rb
300
+ - test/json_gem/json_ext_parser_test.rb
301
+ - test/json_gem/json_fixtures_test.rb
302
+ - test/tests_mimic_addition.rb
303
+ - test/test_wab.rb
304
+ - test/activesupport4/test_helper.rb
284
305
  - test/activesupport4/decoding_test.rb
285
306
  - test/activesupport4/encoding_test.rb
286
- - test/activesupport4/test_helper.rb
287
- - test/activesupport5/decoding_test.rb
288
- - test/activesupport5/encoding_test.rb
307
+ - test/activerecord/result_test.rb
308
+ - test/_test_active.rb
309
+ - test/test_file.rb
289
310
  - test/activesupport5/encoding_test_cases.rb
290
- - test/activesupport5/test_helper.rb
291
311
  - test/activesupport5/time_zone_test_helpers.rb
292
- - test/bug.rb
293
- - test/crash.rb
294
- - test/files.rb
312
+ - test/activesupport5/test_helper.rb
313
+ - test/activesupport5/decoding_test.rb
314
+ - test/activesupport5/encoding_test.rb
315
+ - test/tests.rb
316
+ - test/_test_active_mimic.rb
317
+ - test/perf_object.rb
318
+ - test/test_strict.rb
319
+ - test/test_scp.rb
320
+ - test/perf_wab.rb
321
+ - test/test_saj.rb
322
+ - test/mem.rb
323
+ - test/perf_compat.rb
295
324
  - test/helper.rb
296
- - test/isolated/shared.rb
297
- - test/isolated/test_mimic_after.rb
298
325
  - test/isolated/test_mimic_alone.rb
299
- - test/isolated/test_mimic_as_json.rb
300
- - test/isolated/test_mimic_before.rb
301
326
  - test/isolated/test_mimic_define.rb
302
327
  - test/isolated/test_mimic_rails_after.rb
328
+ - test/isolated/test_mimic_after.rb
303
329
  - test/isolated/test_mimic_rails_before.rb
330
+ - test/isolated/test_mimic_as_json.rb
304
331
  - test/isolated/test_mimic_redefine.rb
305
- - test/json_gem/json_addition_test.rb
306
- - test/json_gem/json_common_interface_test.rb
307
- - test/json_gem/json_encoding_test.rb
308
- - test/json_gem/json_ext_parser_test.rb
309
- - test/json_gem/json_fixtures_test.rb
310
- - test/json_gem/json_generator_test.rb
311
- - test/json_gem/json_generic_object_test.rb
312
- - test/json_gem/json_parser_test.rb
313
- - test/json_gem/json_string_matching_test.rb
314
- - test/json_gem/test_helper.rb
315
- - test/perf.rb
316
- - test/perf_compat.rb
332
+ - test/isolated/shared.rb
333
+ - test/isolated/test_mimic_before.rb
334
+ - test/sample_json.rb
335
+ - test/test_debian.rb
317
336
  - test/perf_fast.rb
318
- - test/perf_file.rb
319
- - test/perf_object.rb
320
- - test/perf_saj.rb
321
- - test/perf_scp.rb
322
- - test/perf_simple.rb
323
- - test/perf_strict.rb
324
- - test/perf_wab.rb
337
+ - test/test_writer.rb
338
+ - test/test_fast.rb
339
+ - test/sample/line.rb
325
340
  - test/sample/change.rb
326
341
  - test/sample/dir.rb
327
- - test/sample/doc.rb
328
- - test/sample/file.rb
329
- - test/sample/group.rb
330
- - test/sample/hasprops.rb
342
+ - test/sample/text.rb
331
343
  - test/sample/layer.rb
332
- - test/sample/line.rb
333
- - test/sample/oval.rb
334
344
  - test/sample/rect.rb
345
+ - test/sample/group.rb
346
+ - test/sample/oval.rb
347
+ - test/sample/doc.rb
348
+ - test/sample/hasprops.rb
335
349
  - test/sample/shape.rb
336
- - test/sample/text.rb
337
- - test/sample.rb
338
- - test/sample_json.rb
339
- - test/test_compat.rb
340
- - test/test_custom.rb
341
- - test/test_debian.rb
342
- - test/test_fast.rb
343
- - test/test_file.rb
344
- - test/test_gc.rb
345
- - test/test_hash.rb
346
- - test/test_integer_range.rb
347
- - test/test_null.rb
348
- - test/test_object.rb
349
- - test/test_saj.rb
350
- - test/test_scp.rb
351
- - test/test_strict.rb
352
- - test/test_various.rb
353
- - test/test_wab.rb
354
- - test/test_writer.rb
355
- - test/tests.rb
350
+ - test/sample/file.rb
351
+ - test/files.rb
352
+ - test/big.rb
353
+ - test/perf_saj.rb
354
+ - test/foo.rb
356
355
  - test/tests_mimic.rb
357
- - test/tests_mimic_addition.rb
356
+ - test/perf_strict.rb
357
+ - test/test_various.rb
358
+ - test/_test_mimic_rails.rb
359
+ - test/perf_simple.rb
@@ -1,25 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # encoding: UTF-8
3
-
4
- %w(lib ext test).each do |dir|
5
- $LOAD_PATH.unshift File.expand_path("../../#{dir}", __FILE__)
6
- end
7
-
8
- require 'rails'
9
- require 'active_support'
10
- require 'active_support/json'
11
- require 'oj'
12
-
13
- x = {"a": BigDecimal("1.1"), "t": Time.now}
14
-
15
- #ActiveSupport.encode_big_decimal_as_string = false
16
-
17
- Oj.optimize_rails
18
-
19
- puts "to_json #{x.to_json}"
20
-
21
- Oj.default_options = { bigdecimal_as_decimal: true}
22
- #puts Oj.default_options
23
-
24
- puts "to_json #{x.to_json}"
25
-