fast_jsonparser 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 40dee4f8a699cce9c3f8d8a1a2519558fc80eff3deb0ec41d12839393a58d2eb
4
- data.tar.gz: f6a9bcc5ba2edc0f2d45b0901694c37edb0a465966c4162b256d475632394978
3
+ metadata.gz: 138ce4779803ae2d326bf94c069cf9028416b41a369daacea4d7bf5e0c8ae699
4
+ data.tar.gz: 4e44270dee72f657f23157df43c6303bf087880f253b9577e3f0f7a153ab8263
5
5
  SHA512:
6
- metadata.gz: 1e96085b0c83b4aa1e28a090b24a0c9fdf470e0a57d64119a0d8b7752e7dd5a3c2e527c5de852cb5c6a295515d30b7c983170f32cc11a9ddbe83613418eaaf2a
7
- data.tar.gz: afcc635e3f3b5d6cfd68317404ec70b638ba0983d5a33361472a6c28394512fbeff9ec01a70f2317a87f078f38e4f5428330f57b7b650b98254177808ca1e85a
6
+ metadata.gz: 81bfa67eaf4a26b7b6b009a3f222cf7cc38399c9e8226246784badc1fd7089b2e0d38dd311ff60db0ec9fbe5b54dc04099e9826eb3d096fd95fb40a93acd7039
7
+ data.tar.gz: 1e9448cf27f4dc0da8668a9d68531a40266f19b7554c7aa6567949bf31cc48abd5f54f26609ab039fa22dcf41a83e426f4dfe7cf4e3348bff19fdaffd6ac63e2
@@ -6,10 +6,9 @@ PATH
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
- byebug (11.1.3)
10
9
  minitest (5.14.1)
11
10
  oj (3.10.6)
12
- rake (10.5.0)
11
+ rake (13.0.1)
13
12
  rake-compiler (1.1.0)
14
13
  rake
15
14
 
@@ -18,11 +17,10 @@ PLATFORMS
18
17
 
19
18
  DEPENDENCIES
20
19
  bundler (~> 2.0)
21
- byebug
22
20
  fast_jsonparser!
23
21
  minitest (~> 5.0)
24
22
  oj
25
- rake (~> 10.0)
23
+ rake (~> 13.0)
26
24
  rake-compiler
27
25
 
28
26
  BUNDLED WITH
data/README.md CHANGED
@@ -4,6 +4,8 @@
4
4
 
5
5
  Ruby wrapper for [simdjson](https://simdjson.org) (Parsing gigabytes of JSON per second)
6
6
 
7
+ The simdjson library uses commonly available SIMD instructions and microparallel algorithms to parse JSON 2.5 times faster than anything else out there.
8
+
7
9
  Initial code imported from [simdjson_ruby](https://github.com/saka1/simdjson_ruby)
8
10
 
9
11
  Comparison with [Oj](https://github.com/ohler55/oj) gem & JSON.parse
@@ -9,48 +9,68 @@ VALUE rb_eFastJsonparserParseError;
9
9
  using namespace simdjson;
10
10
 
11
11
  // Convert tape to Ruby's Object
12
- static VALUE make_ruby_object(dom::element element) {
12
+ static VALUE make_ruby_object(dom::element element)
13
+ {
13
14
  auto t = element.type();
14
- if (t == dom::element_type::ARRAY) {
15
+ if (t == dom::element_type::ARRAY)
16
+ {
15
17
  VALUE ary = rb_ary_new();
16
- for (dom::element x : element) {
18
+ for (dom::element x : element)
19
+ {
17
20
  VALUE e = make_ruby_object(x);
18
21
  rb_ary_push(ary, e);
19
22
  }
20
23
  return ary;
21
- } else if (t == dom::element_type::OBJECT) {
24
+ }
25
+ else if (t == dom::element_type::OBJECT)
26
+ {
22
27
  VALUE hash = rb_hash_new();
23
- for (dom::key_value_pair field : dom::object(element)) {
28
+ for (dom::key_value_pair field : dom::object(element))
29
+ {
24
30
  std::string_view view(field.key);
25
- VALUE k = rb_str_new(view.data(), view.size());
31
+ VALUE k = rb_intern(view.data());
26
32
  VALUE v = make_ruby_object(field.value);
27
- rb_hash_aset(hash, k, v);
33
+ rb_hash_aset(hash, ID2SYM(k), v);
28
34
  }
29
35
  return hash;
30
- } else if (t == dom::element_type::INT64) {
36
+ }
37
+ else if (t == dom::element_type::INT64)
38
+ {
31
39
  return LONG2NUM(element.get<int64_t>());
32
- } else if (t == dom::element_type::UINT64) {
40
+ }
41
+ else if (t == dom::element_type::UINT64)
42
+ {
33
43
  return ULONG2NUM(element.get<uint64_t>());
34
- } else if (t == dom::element_type::DOUBLE) {
44
+ }
45
+ else if (t == dom::element_type::DOUBLE)
46
+ {
35
47
  return DBL2NUM(double(element));
36
- } else if (t == dom::element_type::STRING) {
48
+ }
49
+ else if (t == dom::element_type::STRING)
50
+ {
37
51
  std::string_view view(element);
38
52
  return rb_str_new(view.data(), view.size());
39
- } else if (t == dom::element_type::BOOL) {
53
+ }
54
+ else if (t == dom::element_type::BOOL)
55
+ {
40
56
  return bool(element) ? Qtrue : Qfalse;
41
- } else if (t == dom::element_type::NULL_VALUE) {
57
+ }
58
+ else if (t == dom::element_type::NULL_VALUE)
59
+ {
42
60
  return Qnil;
43
61
  }
44
62
  // unknown case (bug)
45
63
  rb_raise(rb_eException, "[BUG] must not happen");
46
64
  }
47
65
 
48
- static VALUE rb_fast_jsonparser_parse(VALUE self, VALUE arg) {
66
+ static VALUE rb_fast_jsonparser_parse(VALUE self, VALUE arg)
67
+ {
49
68
  Check_Type(arg, T_STRING);
50
69
 
51
70
  dom::parser parser;
52
71
  auto [doc, error] = parser.parse(RSTRING_PTR(arg), RSTRING_LEN(arg));
53
- if (error == SUCCESS) {
72
+ if (error == SUCCESS)
73
+ {
54
74
  return make_ruby_object(doc);
55
75
  }
56
76
  // TODO better error handling
@@ -58,12 +78,14 @@ static VALUE rb_fast_jsonparser_parse(VALUE self, VALUE arg) {
58
78
  return Qnil;
59
79
  }
60
80
 
61
- static VALUE rb_fast_jsonparser_load(VALUE self, VALUE arg) {
81
+ static VALUE rb_fast_jsonparser_load(VALUE self, VALUE arg)
82
+ {
62
83
  Check_Type(arg, T_STRING);
63
84
 
64
85
  dom::parser parser;
65
86
  auto [doc, error] = parser.load(RSTRING_PTR(arg));
66
- if (error == SUCCESS) {
87
+ if (error == SUCCESS)
88
+ {
67
89
  return make_ruby_object(doc);
68
90
  }
69
91
  // TODO better error handling
@@ -71,12 +93,14 @@ static VALUE rb_fast_jsonparser_load(VALUE self, VALUE arg) {
71
93
  return Qnil;
72
94
  }
73
95
 
74
- extern "C" {
96
+ extern "C"
97
+ {
75
98
 
76
- void Init_fast_jsonparser(void) {
77
- rb_mFastJsonparser = rb_define_module("FastJsonparser");
78
- rb_eFastJsonparserParseError = rb_define_class_under(rb_mFastJsonparser, "ParseError", rb_eStandardError);
79
- rb_define_module_function(rb_mFastJsonparser, "parse", reinterpret_cast<VALUE (*)(...)>(rb_fast_jsonparser_parse), 1);
80
- rb_define_module_function(rb_mFastJsonparser, "load", reinterpret_cast<VALUE (*)(...)>(rb_fast_jsonparser_load), 1);
81
- }
99
+ void Init_fast_jsonparser(void)
100
+ {
101
+ rb_mFastJsonparser = rb_define_module("FastJsonparser");
102
+ rb_eFastJsonparserParseError = rb_define_class_under(rb_mFastJsonparser, "ParseError", rb_eStandardError);
103
+ rb_define_module_function(rb_mFastJsonparser, "parse", reinterpret_cast<VALUE (*)(...)>(rb_fast_jsonparser_parse), 1);
104
+ rb_define_module_function(rb_mFastJsonparser, "load", reinterpret_cast<VALUE (*)(...)>(rb_fast_jsonparser_load), 1);
105
+ }
82
106
  }
@@ -39,7 +39,7 @@ Gem::Specification.new do |spec|
39
39
  spec.extensions << "ext/fast_jsonparser/extconf.rb"
40
40
 
41
41
  spec.add_development_dependency "bundler", "~> 2.0"
42
- spec.add_development_dependency "rake", "~> 10.0"
42
+ spec.add_development_dependency "rake", "~> 13.0"
43
43
  spec.add_development_dependency "minitest", "~> 5.0"
44
44
  spec.add_development_dependency "rake-compiler"
45
45
  spec.add_development_dependency 'oj'
@@ -1,3 +1,3 @@
1
1
  module FastJsonparser
2
- VERSION = "0.1.2"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fast_jsonparser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anil Maurya
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-06-14 00:00:00.000000000 Z
11
+ date: 2020-07-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: '13.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: '13.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: minitest
43
43
  requirement: !ruby/object:Gem::Requirement