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 +4 -4
- data/Gemfile.lock +2 -4
- data/README.md +2 -0
- data/ext/fast_jsonparser/fast_jsonparser.cpp +48 -24
- data/fast_jsonparser.gemspec +1 -1
- data/lib/fast_jsonparser/fast_jsonparser.bundle +0 -0
- data/lib/fast_jsonparser/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 138ce4779803ae2d326bf94c069cf9028416b41a369daacea4d7bf5e0c8ae699
|
4
|
+
data.tar.gz: 4e44270dee72f657f23157df43c6303bf087880f253b9577e3f0f7a153ab8263
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 81bfa67eaf4a26b7b6b009a3f222cf7cc38399c9e8226246784badc1fd7089b2e0d38dd311ff60db0ec9fbe5b54dc04099e9826eb3d096fd95fb40a93acd7039
|
7
|
+
data.tar.gz: 1e9448cf27f4dc0da8668a9d68531a40266f19b7554c7aa6567949bf31cc48abd5f54f26609ab039fa22dcf41a83e426f4dfe7cf4e3348bff19fdaffd6ac63e2
|
data/Gemfile.lock
CHANGED
@@ -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 (
|
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 (~>
|
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
|
-
}
|
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 =
|
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
|
-
}
|
36
|
+
}
|
37
|
+
else if (t == dom::element_type::INT64)
|
38
|
+
{
|
31
39
|
return LONG2NUM(element.get<int64_t>());
|
32
|
-
}
|
40
|
+
}
|
41
|
+
else if (t == dom::element_type::UINT64)
|
42
|
+
{
|
33
43
|
return ULONG2NUM(element.get<uint64_t>());
|
34
|
-
}
|
44
|
+
}
|
45
|
+
else if (t == dom::element_type::DOUBLE)
|
46
|
+
{
|
35
47
|
return DBL2NUM(double(element));
|
36
|
-
}
|
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
|
-
}
|
53
|
+
}
|
54
|
+
else if (t == dom::element_type::BOOL)
|
55
|
+
{
|
40
56
|
return bool(element) ? Qtrue : Qfalse;
|
41
|
-
}
|
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
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
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
|
}
|
data/fast_jsonparser.gemspec
CHANGED
@@ -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", "~>
|
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'
|
Binary file
|
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.
|
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-
|
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: '
|
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: '
|
40
|
+
version: '13.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: minitest
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|