panko_serializer 0.5.7 → 0.5.8

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: 96a545d7b57282012eb4f6b46dce52c0d83ade0e5347e209b8295a013456dfd1
4
- data.tar.gz: 3df74cf0eecd66def3ba52856de5080563f52295dd6587cbf8a0dfeada32cf74
3
+ metadata.gz: 11d34f852df4549ddac00e8b819614590029039893f34668c4c53e180fae5c0a
4
+ data.tar.gz: '059527e3089c3aae05a625c36498909d069d3c42047cd1cf02332fd07002c778'
5
5
  SHA512:
6
- metadata.gz: e8dfe71a1409eb33a2c0153251da2edd9a98f9781c4f30cfb572276c371516a2d5a672e921023c5eef1ed4778832a3f8ad87b644d042f6c883fcd17a58c7b439
7
- data.tar.gz: 0b50a663a527f5355736bd973ae38c475ee28c15b6e262f70c21399241cedd870eb665b15a2e921615b45ed2b77cecc08dd17ff6d56f3c0b91f396400d31406f
6
+ metadata.gz: 2e6b2c7cf88f00caa1d7704817b08084580b1da232582fdeb9f754f96f3ae2d3333d9162d88ce030510fdfda6b468b61022d895a32021813e72267d03116a121
7
+ data.tar.gz: f78e9ac7c556dd7693918e4937fd820d22199c807c2f44d8379eb9e2fd4f1a0b9db73fdb8d6ada606923c353c51046fd4f274799853f52b7ac6f1f9a1129af5e
@@ -1,148 +1,3 @@
1
1
  ---
2
2
  Language: Cpp
3
- # BasedOnStyle: Chromium
4
- AccessModifierOffset: -1
5
- AlignAfterOpenBracket: Align
6
- AlignConsecutiveAssignments: false
7
- AlignConsecutiveDeclarations: false
8
- AlignEscapedNewlines: Left
9
- AlignOperands: true
10
- AlignTrailingComments: true
11
- AllowAllParametersOfDeclarationOnNextLine: false
12
- AllowShortBlocksOnASingleLine: false
13
- AllowShortCaseLabelsOnASingleLine: false
14
- AllowShortFunctionsOnASingleLine: Inline
15
- AllowShortIfStatementsOnASingleLine: false
16
- AllowShortLoopsOnASingleLine: false
17
- AlwaysBreakAfterDefinitionReturnType: None
18
- AlwaysBreakAfterReturnType: None
19
- AlwaysBreakBeforeMultilineStrings: true
20
- AlwaysBreakTemplateDeclarations: Yes
21
- BinPackArguments: true
22
- BinPackParameters: false
23
- BraceWrapping:
24
- AfterClass: false
25
- AfterControlStatement: false
26
- AfterEnum: false
27
- AfterFunction: false
28
- AfterNamespace: false
29
- AfterObjCDeclaration: false
30
- AfterStruct: false
31
- AfterUnion: false
32
- AfterExternBlock: false
33
- BeforeCatch: false
34
- BeforeElse: false
35
- IndentBraces: false
36
- SplitEmptyFunction: true
37
- SplitEmptyRecord: true
38
- SplitEmptyNamespace: true
39
- BreakBeforeBinaryOperators: None
40
- BreakBeforeBraces: Attach
41
- BreakBeforeInheritanceComma: false
42
- BreakInheritanceList: BeforeColon
43
- BreakBeforeTernaryOperators: true
44
- BreakConstructorInitializersBeforeComma: false
45
- BreakConstructorInitializers: BeforeColon
46
- BreakAfterJavaFieldAnnotations: false
47
- BreakStringLiterals: true
48
- ColumnLimit: 80
49
- CommentPragmas: '^ IWYU pragma:'
50
- CompactNamespaces: false
51
- ConstructorInitializerAllOnOneLineOrOnePerLine: true
52
- ConstructorInitializerIndentWidth: 4
53
- ContinuationIndentWidth: 4
54
- Cpp11BracedListStyle: true
55
- DerivePointerAlignment: false
56
- DisableFormat: false
57
- ExperimentalAutoDetectBinPacking: false
58
- FixNamespaceComments: true
59
- ForEachMacros:
60
- - foreach
61
- - Q_FOREACH
62
- - BOOST_FOREACH
63
- IncludeBlocks: Preserve
64
- IncludeCategories:
65
- - Regex: '^<ext/.*\.h>'
66
- Priority: 2
67
- - Regex: '^<.*\.h>'
68
- Priority: 1
69
- - Regex: '^<.*'
70
- Priority: 2
71
- - Regex: '.*'
72
- Priority: 3
73
- IncludeIsMainRegex: '([-_](test|unittest))?$'
74
- IndentCaseLabels: true
75
- IndentPPDirectives: None
76
- IndentWidth: 2
77
- IndentWrappedFunctionNames: false
78
- JavaScriptQuotes: Leave
79
- JavaScriptWrapImports: true
80
- KeepEmptyLinesAtTheStartOfBlocks: false
81
- MacroBlockBegin: ''
82
- MacroBlockEnd: ''
83
- MaxEmptyLinesToKeep: 1
84
- NamespaceIndentation: None
85
- ObjCBinPackProtocolList: Never
86
- ObjCBlockIndentWidth: 2
87
- ObjCSpaceAfterProperty: false
88
- ObjCSpaceBeforeProtocolList: true
89
- PenaltyBreakAssignment: 2
90
- PenaltyBreakBeforeFirstCallParameter: 1
91
- PenaltyBreakComment: 300
92
- PenaltyBreakFirstLessLess: 120
93
- PenaltyBreakString: 1000
94
- PenaltyBreakTemplateDeclaration: 10
95
- PenaltyExcessCharacter: 1000000
96
- PenaltyReturnTypeOnItsOwnLine: 200
97
- PointerAlignment: Left
98
- RawStringFormats:
99
- - Language: Cpp
100
- Delimiters:
101
- - cc
102
- - CC
103
- - cpp
104
- - Cpp
105
- - CPP
106
- - 'c++'
107
- - 'C++'
108
- CanonicalDelimiter: ''
109
- BasedOnStyle: google
110
- - Language: TextProto
111
- Delimiters:
112
- - pb
113
- - PB
114
- - proto
115
- - PROTO
116
- EnclosingFunctions:
117
- - EqualsProto
118
- - EquivToProto
119
- - PARSE_PARTIAL_TEXT_PROTO
120
- - PARSE_TEST_PROTO
121
- - PARSE_TEXT_PROTO
122
- - ParseTextOrDie
123
- - ParseTextProtoOrDie
124
- CanonicalDelimiter: ''
125
- BasedOnStyle: google
126
- ReflowComments: true
127
- SortIncludes: true
128
- SortUsingDeclarations: true
129
- SpaceAfterCStyleCast: false
130
- SpaceAfterTemplateKeyword: true
131
- SpaceBeforeAssignmentOperators: true
132
- SpaceBeforeCpp11BracedList: false
133
- SpaceBeforeCtorInitializerColon: true
134
- SpaceBeforeInheritanceColon: true
135
- SpaceBeforeParens: ControlStatements
136
- SpaceBeforeRangeBasedForLoopColon: true
137
- SpaceInEmptyParentheses: false
138
- SpacesBeforeTrailingComments: 2
139
- SpacesInAngles: false
140
- SpacesInContainerLiterals: true
141
- SpacesInCStyleCastParentheses: false
142
- SpacesInParentheses: false
143
- SpacesInSquareBrackets: false
144
- Standard: Auto
145
- TabWidth: 8
146
- UseTab: Never
147
- ...
148
-
3
+ BasedOnStyle: Google
@@ -2,11 +2,8 @@ sudo: false
2
2
  cache: bundler
3
3
  language: ruby
4
4
  rvm:
5
- - 2.5.1
6
- - ruby-head
7
- matrix:
8
- allow_failures:
9
- - rvm: ruby-head
5
+ - 2.5.3
6
+ - 2.6.0
10
7
 
11
8
  env:
12
9
  global:
@@ -27,5 +24,4 @@ after_success:
27
24
  env:
28
25
  matrix:
29
26
  - "RAILS_VERSION=4.2.0"
30
- - "RAILS_VERSION=5.1.0"
31
27
  - "RAILS_VERSION=5.2.0"
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Panko
2
2
 
3
- [![Build Status](https://travis-ci.org/yosiat/panko_serializer.svg?branch=master)](https://travis-ci.org/yosiat/panko_serializer)
3
+ [![Build Status](https://api.travis-ci.com/yosiat/panko_serializer.svg?branch=master)](https://travis-ci.org/yosiat/panko_serializer)
4
4
 
5
5
  Panko is library which is inspired by ActiveModelSerializers 0.9 for serializing ActiveRecord/Ruby objects to JSON strings, fast.
6
6
 
data/Rakefile CHANGED
@@ -48,7 +48,7 @@ rescue PTY::ChildExited
48
48
  []
49
49
  end
50
50
 
51
- def run_benchmarks(files, items_count: 7_000)
51
+ def run_benchmarks(files, items_count: 2_300)
52
52
  headings = ["Benchmark", "ip/s", "allocs/retained"]
53
53
  files.each do |benchmark_file|
54
54
 
@@ -21,20 +21,6 @@ VALUE panko_read_lazy_attributes_hash(VALUE object) {
21
21
  return lazy_attributes_hash;
22
22
  }
23
23
 
24
- void read_attribute_from_hash(VALUE attributes_hash,
25
- VALUE member,
26
- volatile VALUE* value,
27
- volatile VALUE* type) {
28
- volatile VALUE attribute_metadata = rb_hash_aref(attributes_hash, member);
29
- if (attribute_metadata != Qnil) {
30
- *value = rb_ivar_get(attribute_metadata, value_before_type_cast_id);
31
-
32
- if (NIL_P(*type)) {
33
- *type = rb_ivar_get(attribute_metadata, type_id);
34
- }
35
- }
36
- }
37
-
38
24
  struct attributes {
39
25
  VALUE attributes_hash;
40
26
 
@@ -84,21 +70,30 @@ struct attributes init_context(VALUE obj) {
84
70
  }
85
71
 
86
72
  VALUE read_attribute(struct attributes attributes_ctx, Attribute attribute) {
87
- VALUE member = attribute->name_str;
88
- volatile VALUE value = Qundef;
73
+ volatile VALUE member, value, attribute_metadata;
74
+
75
+ member = attribute->name_str;
76
+ value = Qundef;
77
+
78
+ if (attributes_ctx.shouldReadFromHash == true) {
79
+ volatile VALUE attribute_metadata =
80
+ rb_hash_aref(attributes_ctx.attributes_hash, member);
81
+ if (attribute_metadata != Qnil) {
82
+ value = rb_ivar_get(attribute_metadata, value_before_type_cast_id);
89
83
 
90
- if (!NIL_P(attributes_ctx.values)) {
84
+ if (NIL_P(attribute->type)) {
85
+ attribute->type = rb_ivar_get(attribute_metadata, type_id);
86
+ }
87
+ }
88
+ }
89
+
90
+ if (value == Qundef && !NIL_P(attributes_ctx.values)) {
91
91
  value = rb_hash_aref(attributes_ctx.values, member);
92
92
  if (NIL_P(value)) {
93
93
  value = Qundef;
94
94
  }
95
95
  }
96
96
 
97
- if (value == Qundef && attributes_ctx.shouldReadFromHash == true) {
98
- read_attribute_from_hash(attributes_ctx.attributes_hash, member, &value,
99
- &attribute->type);
100
- }
101
-
102
97
  if (NIL_P(attribute->type) && !NIL_P(value)) {
103
98
  if (attributes_ctx.tryToReadFromAdditionalTypes == true) {
104
99
  attribute->type = rb_hash_aref(attributes_ctx.additional_types, member);
@@ -116,10 +111,8 @@ VALUE read_attribute(struct attributes attributes_ctx, Attribute attribute) {
116
111
  return value;
117
112
  }
118
113
 
119
- void active_record_attributes_writer(VALUE obj,
120
- VALUE attributes,
121
- EachAttributeFunc func,
122
- VALUE writer) {
114
+ void active_record_attributes_writer(VALUE obj, VALUE attributes,
115
+ EachAttributeFunc func, VALUE writer) {
123
116
  long i;
124
117
  struct attributes attributes_ctx = init_context(obj);
125
118
  volatile VALUE record_class = CLASS_OF(obj);
@@ -11,6 +11,6 @@
11
11
  extern void active_record_attributes_writer(VALUE object,
12
12
  VALUE attributes,
13
13
  EachAttributeFunc func,
14
- VALUE context);
14
+ VALUE writer);
15
15
 
16
16
  void init_active_record_attributes_writer(VALUE mPanko);
@@ -27,17 +27,14 @@ AttributesWriter create_attributes_writer(VALUE subject) {
27
27
  return (AttributesWriter){
28
28
  .object_type = ActiveRecord,
29
29
  .write_attributes = active_record_attributes_writer};
30
- } else {
31
- return (AttributesWriter){.object_type = Plain,
32
- .write_attributes = plain_attributes_writer};
33
30
  }
31
+ return (AttributesWriter){.object_type = Plain,
32
+ .write_attributes = plain_attributes_writer};
34
33
 
35
34
  return create_empty_attributes_writer();
36
35
  }
37
36
 
38
- void empty_write_attributes(VALUE obj,
39
- VALUE attributes,
40
- EachAttributeFunc func,
37
+ void empty_write_attributes(VALUE obj, VALUE attributes, EachAttributeFunc func,
41
38
  VALUE writer) {}
42
39
 
43
40
  AttributesWriter create_empty_attributes_writer() {
@@ -1,9 +1,7 @@
1
1
  #include "plain.h"
2
2
 
3
- void plain_attributes_writer(VALUE obj,
4
- VALUE attributes,
5
- EachAttributeFunc func,
6
- VALUE writer) {
3
+ void plain_attributes_writer(VALUE obj, VALUE attributes,
4
+ EachAttributeFunc func, VALUE writer) {
7
5
  long i;
8
6
  for (i = 0; i < RARRAY_LEN(attributes); i++) {
9
7
  volatile VALUE raw_attribute = RARRAY_AREF(attributes, i);
@@ -25,9 +25,7 @@ VALUE is_iso8601_time_string(const char* value) {
25
25
  return r >= 0 ? Qtrue : Qfalse;
26
26
  }
27
27
 
28
- void append_region_str(const char* source,
29
- char** to,
30
- int regionBegin,
28
+ void append_region_str(const char* source, char** to, int regionBegin,
31
29
  int regionEnd) {
32
30
  long iter = 0;
33
31
  for (iter = regionBegin; iter < regionEnd; iter++) {
@@ -98,19 +96,19 @@ VALUE iso_ar_iso_datetime_string(const char* value) {
98
96
 
99
97
  *cur++ = '.';
100
98
  if (value[19] == '.' && isdigit(value[20])) {
101
- if(isdigit(value[20])) {
99
+ if (isdigit(value[20])) {
102
100
  *cur++ = value[20];
103
101
  } else {
104
102
  *cur++ = '0';
105
103
  }
106
104
 
107
- if(isdigit(value[21])) {
105
+ if (isdigit(value[21])) {
108
106
  *cur++ = value[21];
109
107
  } else {
110
108
  *cur++ = '0';
111
109
  }
112
110
 
113
- if(isdigit(value[22])) {
111
+ if (isdigit(value[22])) {
114
112
  *cur++ = value[22];
115
113
  } else {
116
114
  *cur++ = '0';
@@ -212,13 +212,9 @@ bool is_json_type(VALUE type_klass) {
212
212
  (ar_json_type != Qundef && type_klass == ar_json_type));
213
213
  }
214
214
 
215
- VALUE rescue_func() {
216
- return Qnil;
217
- }
215
+ VALUE rescue_func() { return Qnil; }
218
216
 
219
- VALUE parse_json(VALUE value) {
220
- return rb_funcall(oj_type, load_id, 1, value);
221
- }
217
+ VALUE parse_json(VALUE value) { return rb_funcall(oj_type, load_id, 1, value); }
222
218
 
223
219
  VALUE cast_json_type(VALUE value) {
224
220
  if (!RB_TYPE_P(value, T_STRING)) {
@@ -230,9 +226,7 @@ VALUE cast_json_type(VALUE value) {
230
226
  return result;
231
227
  }
232
228
 
233
- bool is_boolean_type(VALUE type_klass) {
234
- return type_klass == ar_boolean_type;
235
- }
229
+ bool is_boolean_type(VALUE type_klass) { return type_klass == ar_boolean_type; }
236
230
 
237
231
  VALUE cast_boolean_type(VALUE value) {
238
232
  if (value == Qtrue || value == Qfalse) {
@@ -16,8 +16,7 @@ void write_value(VALUE str_writer, VALUE key, VALUE value) {
16
16
  rb_funcall(str_writer, push_value_id, 2, value, key);
17
17
  }
18
18
 
19
- void serialize_method_fields(VALUE subject,
20
- VALUE str_writer,
19
+ void serialize_method_fields(VALUE subject, VALUE str_writer,
21
20
  SerializationDescriptor descriptor) {
22
21
  if (RARRAY_LEN(descriptor->method_fields) == 0) {
23
22
  return;
@@ -43,8 +42,7 @@ void serialize_method_fields(VALUE subject,
43
42
  rb_ivar_set(serializer, object_id, Qnil);
44
43
  }
45
44
 
46
- void serialize_fields(VALUE subject,
47
- VALUE str_writer,
45
+ void serialize_fields(VALUE subject, VALUE str_writer,
48
46
  SerializationDescriptor descriptor) {
49
47
  descriptor->attributes_writer.write_attributes(
50
48
  subject, descriptor->attributes, write_value, str_writer);
@@ -52,9 +50,7 @@ void serialize_fields(VALUE subject,
52
50
  serialize_method_fields(subject, str_writer, descriptor);
53
51
  }
54
52
 
55
- void serialize_has_one_associations(VALUE subject,
56
- VALUE str_writer,
57
- SerializationDescriptor descriptor,
53
+ void serialize_has_one_associations(VALUE subject, VALUE str_writer,
58
54
  VALUE associations) {
59
55
  long i;
60
56
  for (i = 0; i < RARRAY_LEN(associations); i++) {
@@ -72,9 +68,7 @@ void serialize_has_one_associations(VALUE subject,
72
68
  }
73
69
  }
74
70
 
75
- void serialize_has_many_associations(VALUE subject,
76
- VALUE str_writer,
77
- SerializationDescriptor descriptor,
71
+ void serialize_has_many_associations(VALUE subject, VALUE str_writer,
78
72
  VALUE associations) {
79
73
  long i;
80
74
  for (i = 0; i < RARRAY_LEN(associations); i++) {
@@ -92,9 +86,7 @@ void serialize_has_many_associations(VALUE subject,
92
86
  }
93
87
  }
94
88
 
95
- VALUE serialize_subject(VALUE key,
96
- VALUE subject,
97
- VALUE str_writer,
89
+ VALUE serialize_subject(VALUE key, VALUE subject, VALUE str_writer,
98
90
  SerializationDescriptor descriptor) {
99
91
  sd_set_writer(descriptor, subject);
100
92
 
@@ -103,12 +95,12 @@ VALUE serialize_subject(VALUE key,
103
95
  serialize_fields(subject, str_writer, descriptor);
104
96
 
105
97
  if (RARRAY_LEN(descriptor->has_one_associations) > 0) {
106
- serialize_has_one_associations(subject, str_writer, descriptor,
98
+ serialize_has_one_associations(subject, str_writer,
107
99
  descriptor->has_one_associations);
108
100
  }
109
101
 
110
102
  if (RARRAY_LEN(descriptor->has_many_associations) > 0) {
111
- serialize_has_many_associations(subject, str_writer, descriptor,
103
+ serialize_has_many_associations(subject, str_writer,
112
104
  descriptor->has_many_associations);
113
105
  }
114
106
 
@@ -117,9 +109,7 @@ VALUE serialize_subject(VALUE key,
117
109
  return Qnil;
118
110
  }
119
111
 
120
- VALUE serialize_subjects(VALUE key,
121
- VALUE subjects,
122
- VALUE str_writer,
112
+ VALUE serialize_subjects(VALUE key, VALUE subjects, VALUE str_writer,
123
113
  SerializationDescriptor descriptor) {
124
114
  long i;
125
115
 
@@ -139,17 +129,13 @@ VALUE serialize_subjects(VALUE key,
139
129
  return Qnil;
140
130
  }
141
131
 
142
- VALUE serialize_subject_api(VALUE klass,
143
- VALUE subject,
144
- VALUE str_writer,
132
+ VALUE serialize_subject_api(VALUE klass, VALUE subject, VALUE str_writer,
145
133
  VALUE descriptor) {
146
134
  SerializationDescriptor sd = sd_read(descriptor);
147
135
  return serialize_subject(Qnil, subject, str_writer, sd);
148
136
  }
149
137
 
150
- VALUE serialize_subjects_api(VALUE klass,
151
- VALUE subjects,
152
- VALUE str_writer,
138
+ VALUE serialize_subjects_api(VALUE klass, VALUE subjects, VALUE str_writer,
153
139
  VALUE descriptor) {
154
140
  serialize_subjects(Qnil, subjects, str_writer, sd_read(descriptor));
155
141
 
@@ -19,7 +19,7 @@ typedef struct _Attribute {
19
19
  } * Attribute;
20
20
 
21
21
  Attribute attribute_read(VALUE attribute);
22
- void attribute_try_invalidate(Attribute attribute, VALUE record);
22
+ void attribute_try_invalidate(Attribute attribute, VALUE new_record_class);
23
23
  void panko_init_attribute(VALUE mPanko);
24
24
 
25
25
  #define PANKO_ATTRIBUTE_READ(attribute) (Attribute)DATA_PTR(attribute)
@@ -133,7 +133,7 @@ VALUE sd_aliases_set(VALUE self, VALUE aliases) {
133
133
  return Qnil;
134
134
  }
135
135
 
136
- VALUE sd_aliases_aref(VALUE self, VALUE aliases) {
136
+ VALUE sd_aliases_aref(VALUE self) {
137
137
  SerializationDescriptor sd = (SerializationDescriptor)DATA_PTR(self);
138
138
  return sd->aliases;
139
139
  }
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Panko
4
- VERSION = "0.5.7"
4
+ VERSION = "0.5.8"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: panko_serializer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.7
4
+ version: 0.5.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yosi Attias
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-11-16 00:00:00.000000000 Z
11
+ date: 2019-01-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oj
@@ -116,8 +116,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
116
116
  - !ruby/object:Gem::Version
117
117
  version: '0'
118
118
  requirements: []
119
- rubyforge_project:
120
- rubygems_version: 2.7.8
119
+ rubygems_version: 3.0.1
121
120
  signing_key:
122
121
  specification_version: 4
123
122
  summary: Fast serialization for ActiveModel