panko_serializer 0.4.2 → 0.4.3

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: 392d44930b3cd861d45c08e3f8092b55c84550525ced57fcd59d0425827ab177
4
- data.tar.gz: bd30319fd499a26b1a44943e443f2f145b1969632fb1aa51472ace7f2d7e21a9
3
+ metadata.gz: fe095c4ba577a1757ae1cfde90e6847bb6064753dd34e68aaa0c16d6bb9cc844
4
+ data.tar.gz: 5b3d50d6dc2191240069fa36733248197a96555a1b130c405d799d9ca982e9ce
5
5
  SHA512:
6
- metadata.gz: 811ed00b96b5a2dbc527b912c77f1f44576586b04de6366fd5c9a8d2a80f9f411a0ab22a5db87a9a3fa3129596cd94bfc6ac5fd2f7ac66725819612e97aa373f
7
- data.tar.gz: dd894089a01e61a25da591725ac9cbb6be5e8de188a17a100f8d18bdedf787161d3c4e16263b91e5b1cbcd9eadb09f50576fe53aa3ffa0e544e5fa325c0ee565
6
+ metadata.gz: c7e73c88806d3195cf9c63aeed87ff67739cc4ff31a6f0121ebe59612627c8f4b020e64eba2aaa55d56242a616e4de177996263c7c18cb5416124e7364f32977
7
+ data.tar.gz: 91505d9d99eddab0e81e05340ea324c0350507ff9fcc6db77fc9c4efc34c84bd28f9ee69d3b3e876ee23e0258ad785971c1a85893af35307c3882948eb7996b2
data/.clang-format CHANGED
@@ -59,6 +59,7 @@ ForEachMacros:
59
59
  - foreach
60
60
  - Q_FOREACH
61
61
  - BOOST_FOREACH
62
+ IncludeBlocks: Preserve
62
63
  IncludeCategories:
63
64
  - Regex: '^<ext/.*\.h>'
64
65
  Priority: 2
@@ -80,9 +81,10 @@ MacroBlockBegin: ''
80
81
  MacroBlockEnd: ''
81
82
  MaxEmptyLinesToKeep: 1
82
83
  NamespaceIndentation: None
84
+ ObjCBinPackProtocolList: Never
83
85
  ObjCBlockIndentWidth: 2
84
86
  ObjCSpaceAfterProperty: false
85
- ObjCSpaceBeforeProtocolList: false
87
+ ObjCSpaceBeforeProtocolList: true
86
88
  PenaltyBreakAssignment: 2
87
89
  PenaltyBreakBeforeFirstCallParameter: 1
88
90
  PenaltyBreakComment: 300
@@ -92,8 +94,13 @@ PenaltyExcessCharacter: 1000000
92
94
  PenaltyReturnTypeOnItsOwnLine: 200
93
95
  PointerAlignment: Left
94
96
  RawStringFormats:
95
- - Delimiter: pb
96
- Language: TextProto
97
+ - Language: TextProto
98
+ Delimiters:
99
+ - pb
100
+ - PB
101
+ - proto
102
+ - PROTO
103
+ CanonicalDelimiter: ''
97
104
  BasedOnStyle: google
98
105
  ReflowComments: true
99
106
  SortIncludes: true
@@ -101,7 +108,10 @@ SortUsingDeclarations: true
101
108
  SpaceAfterCStyleCast: false
102
109
  SpaceAfterTemplateKeyword: true
103
110
  SpaceBeforeAssignmentOperators: true
111
+ SpaceBeforeCtorInitializerColon: true
112
+ SpaceBeforeInheritanceColon: true
104
113
  SpaceBeforeParens: ControlStatements
114
+ SpaceBeforeRangeBasedForLoopColon: true
105
115
  SpaceInEmptyParentheses: false
106
116
  SpacesBeforeTrailingComments: 2
107
117
  SpacesInAngles: false
data/.travis.yml CHANGED
@@ -3,13 +3,17 @@ cache: bundler
3
3
  language: ruby
4
4
  rvm:
5
5
  - 2.5.1
6
+ - ruby-head
7
+ matrix:
8
+ allow_failures:
9
+ - rvm: ruby-head
6
10
 
7
11
  env:
8
12
  global:
9
13
  - GIT_NAME: Travis CI
10
14
  - GIT_EMAIL: nobody@nobody.org
11
15
 
12
- install: bundle install --path=vendor/bundle --retry=3 --jobs=3
16
+ install: bundle install --path=vendor/bundle --retry=3
13
17
 
14
18
  before_install:
15
19
  - gem install bundler
data/Rakefile CHANGED
@@ -54,7 +54,13 @@ def run_benchmarks(files, items_count: 7_000)
54
54
 
55
55
  lines = run_process "ITEMS_COUNT=#{items_count} RAILS_ENV=production ruby #{benchmark_file}"
56
56
  rows = lines.map do |line|
57
- row = JSON.parse(line)
57
+ begin
58
+ row = JSON.parse(line)
59
+ rescue JSON::ParserError
60
+ puts "> Failed parsing json"
61
+ puts lines.join
62
+ exit
63
+ end
58
64
  row.values
59
65
  end
60
66
 
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
  require_relative "./benchmarking_support"
3
- require "rails"
4
3
  require "active_support"
5
4
 
6
5
  require "panko_serializer"
@@ -70,7 +70,6 @@ ar_type_convert ActiveRecord::Type::String, 1, "1"
70
70
  ar_type_convert ActiveRecord::Type::Text, 1, "1"
71
71
  ar_type_convert ActiveRecord::Type::Integer, "1", 1
72
72
  ar_type_convert ActiveRecord::Type::Float, "1.23", 1.23
73
- ar_type_convert ActiveRecord::Type::Float, "Infinity", 0.0
74
73
  ar_type_convert ActiveRecord::Type::Boolean, "true", true
75
74
  ar_type_convert ActiveRecord::Type::Boolean, "t", true
76
75
 
@@ -49,7 +49,6 @@ panko_type_convert ActiveRecord::Type::String, 1, "1"
49
49
  panko_type_convert ActiveRecord::Type::Text, 1, "1"
50
50
  panko_type_convert ActiveRecord::Type::Integer, "1", 1
51
51
  panko_type_convert ActiveRecord::Type::Float, "1.23", 1.23
52
- panko_type_convert ActiveRecord::Type::Float, "Infinity", ::Float::INFINITY
53
52
  panko_type_convert ActiveRecord::Type::Boolean, "true", true
54
53
  panko_type_convert ActiveRecord::Type::Boolean, "t", true
55
54
 
@@ -3,9 +3,9 @@
3
3
  #include <ruby.h>
4
4
  #include <stdbool.h>
5
5
 
6
+ #include "common.h"
6
7
  #include "serialization_descriptor/attribute.h"
7
8
  #include "type_cast/type_cast.h"
8
- #include "common.h"
9
9
 
10
10
  extern VALUE active_record_attributes_writer(VALUE object,
11
11
  VALUE attributes,
@@ -25,22 +25,38 @@ VALUE is_iso8601_time_string(const char* value) {
25
25
  return r >= 0 ? Qtrue : Qfalse;
26
26
  }
27
27
 
28
- void append_region(const char* source,
29
- char** to,
30
- const OnigRegion* region,
31
- int region_number) {
28
+ void append_region_str(const char* source,
29
+ char** to,
30
+ int regionBegin,
31
+ int regionEnd) {
32
32
  long iter = 0;
33
- long regionEnd = region->end[region_number];
34
- for (iter = region->beg[region_number]; iter < regionEnd; iter++) {
33
+ for (iter = regionBegin; iter < regionEnd; iter++) {
35
34
  *(*to)++ = source[iter];
36
35
  }
37
36
  }
38
37
 
39
- VALUE iso_ar_iso_datetime_string(const char* value) {
38
+ bool is_iso_ar_iso_datetime_string_fast_case(const char* value) {
39
+ return (
40
+ // year
41
+ isdigit(value[0]) && isdigit(value[1]) && isdigit(value[2]) &&
42
+ isdigit(value[3]) && value[4] == '-' &&
43
+ // month
44
+ isdigit(value[5]) && isdigit(value[6]) && value[7] == '-' &&
45
+ // mday
46
+ isdigit(value[8]) && isdigit(value[9]) && value[10] == ' ' &&
47
+
48
+ // hour
49
+ isdigit(value[11]) && isdigit(value[12]) && value[13] == ':' &&
50
+ // minute
51
+ isdigit(value[14]) && isdigit(value[15]) && value[16] == ':' &&
52
+ // seconds
53
+ isdigit(value[17]) && isdigit(value[18]));
54
+ }
55
+
56
+ bool is_iso_ar_iso_datetime_string_slow_case(const char* value) {
40
57
  const UChar *start, *range, *end;
41
58
  OnigPosition r;
42
59
  OnigRegion* region = onig_region_new();
43
- volatile VALUE output;
44
60
 
45
61
  const UChar* str = (const UChar*)(value);
46
62
 
@@ -50,34 +66,42 @@ VALUE iso_ar_iso_datetime_string(const char* value) {
50
66
  r = onig_search(ar_iso_datetime_regex, str, end, start, range, region,
51
67
  ONIG_OPTION_NONE);
52
68
 
53
- output = Qnil;
54
- if (r >= 0) {
69
+ onig_region_free(region, 1);
70
+
71
+ return (r >= 0);
72
+ }
73
+
74
+ VALUE iso_ar_iso_datetime_string(const char* value) {
75
+ if (is_iso_ar_iso_datetime_string_fast_case(value) == true ||
76
+ is_iso_ar_iso_datetime_string_slow_case(value) == true) {
77
+ volatile VALUE output;
78
+
55
79
  char buf[21] = "";
56
80
  char* cur = buf;
57
81
 
58
- append_region(value, &cur, region, YEAR_REGION);
82
+ append_region_str(value, &cur, 0, 4);
59
83
  *cur++ = '-';
60
84
 
61
- append_region(value, &cur, region, MONTH_REGION);
85
+ append_region_str(value, &cur, 5, 7);
62
86
  *cur++ = '-';
63
87
 
64
- append_region(value, &cur, region, DAY_REGION);
88
+ append_region_str(value, &cur, 8, 10);
65
89
  *cur++ = 'T';
66
90
 
67
- append_region(value, &cur, region, HOUR_REGION);
91
+ append_region_str(value, &cur, 11, 13);
68
92
  *cur++ = ':';
69
93
 
70
- append_region(value, &cur, region, MINUTE_REGION);
94
+ append_region_str(value, &cur, 14, 16);
71
95
  *cur++ = ':';
72
96
 
73
- append_region(value, &cur, region, SECOND_REGION);
97
+ append_region_str(value, &cur, 17, 19);
74
98
  *cur++ = 'Z';
75
99
 
76
100
  output = rb_str_new(buf, cur - buf);
101
+ return output;
77
102
  }
78
103
 
79
- onig_region_free(region, 1);
80
- return output;
104
+ return Qnil;
81
105
  }
82
106
 
83
107
  void build_regex(OnigRegex* reg, const UChar* pattern) {
@@ -1,7 +1,9 @@
1
1
  #pragma once
2
2
 
3
+ #include <ctype.h>
3
4
  #include <ruby.h>
4
5
  #include <ruby/oniguruma.h>
6
+ #include <stdbool.h>
5
7
 
6
8
  VALUE is_iso8601_time_string(const char* value);
7
9
  VALUE iso_ar_iso_datetime_string(const char* value);
@@ -243,8 +243,8 @@ VALUE cast_boolean_type(VALUE value) {
243
243
  return Qnil;
244
244
  }
245
245
 
246
- if(RB_TYPE_P(value, T_STRING)) {
247
- if(RSTRING_LEN(value) == 0) {
246
+ if (RB_TYPE_P(value, T_STRING)) {
247
+ if (RSTRING_LEN(value) == 0) {
248
248
  return Qnil;
249
249
  }
250
250
 
@@ -262,7 +262,7 @@ VALUE cast_boolean_type(VALUE value) {
262
262
  return value == INT2NUM(1) ? Qtrue : Qfalse;
263
263
  }
264
264
 
265
- return Qnil;
265
+ return Qundef;
266
266
  }
267
267
 
268
268
  bool is_date_time_type(VALUE type_klass) {
@@ -2,8 +2,8 @@
2
2
 
3
3
  #include <ruby.h>
4
4
 
5
- #include "common.h"
6
5
  #include "active_record.h"
6
+ #include "common.h"
7
7
  #include "plain.h"
8
8
 
9
9
  enum ObjectType { Unknown = 0, ActiveRecord = 1, Plain = 2 };
@@ -1,9 +1,9 @@
1
1
  #include <ruby.h>
2
2
 
3
3
  #include "attributes_writer/writer.h"
4
- #include "serialization_descriptor/serialization_descriptor.h"
5
4
  #include "serialization_descriptor/association.h"
6
5
  #include "serialization_descriptor/attribute.h"
6
+ #include "serialization_descriptor/serialization_descriptor.h"
7
7
 
8
8
  VALUE serialize_subject(VALUE key,
9
9
  VALUE subject,
@@ -6,7 +6,6 @@ static ID context_id;
6
6
  static ID scope_id;
7
7
  static ID object_id;
8
8
 
9
-
10
9
  static void sd_free(SerializationDescriptor sd) {
11
10
  if (!sd) {
12
11
  return;
@@ -59,7 +58,6 @@ SerializationDescriptor sd_read(VALUE descriptor) {
59
58
  return (SerializationDescriptor)DATA_PTR(descriptor);
60
59
  }
61
60
 
62
-
63
61
  void sd_set_writer(SerializationDescriptor sd, VALUE subject) {
64
62
  if (sd->attributes_writer.object_type != Unknown) {
65
63
  return;
@@ -90,7 +88,9 @@ VALUE sd_serializer_ref(VALUE self) {
90
88
  return sd->serializer;
91
89
  }
92
90
 
93
- void sd_apply_serializer_config(SerializationDescriptor descriptor, VALUE serializer, VALUE object) {
91
+ void sd_apply_serializer_config(SerializationDescriptor descriptor,
92
+ VALUE serializer,
93
+ VALUE object) {
94
94
  rb_ivar_set(serializer, object_id, object);
95
95
  if (descriptor->context != Qnil && descriptor->context != Qundef) {
96
96
  rb_ivar_set(serializer, context_id, descriptor->context);
@@ -99,7 +99,6 @@ void sd_apply_serializer_config(SerializationDescriptor descriptor, VALUE serial
99
99
  if (descriptor->scope != Qnil && descriptor->scope != Qundef) {
100
100
  rb_ivar_set(serializer, scope_id, descriptor->scope);
101
101
  }
102
-
103
102
  }
104
103
  VALUE sd_attributes_set(VALUE self, VALUE attributes) {
105
104
  SerializationDescriptor sd = (SerializationDescriptor)DATA_PTR(self);
@@ -28,7 +28,9 @@ SerializationDescriptor sd_read(VALUE descriptor);
28
28
  void sd_mark(SerializationDescriptor data);
29
29
 
30
30
  VALUE sd_build_serializer(SerializationDescriptor descriptor);
31
- void sd_apply_serializer_config(SerializationDescriptor descriptor, VALUE serializer, VALUE object);
31
+ void sd_apply_serializer_config(SerializationDescriptor descriptor,
32
+ VALUE serializer,
33
+ VALUE object);
32
34
  void sd_set_writer(SerializationDescriptor sd, VALUE subject);
33
35
 
34
36
  void panko_init_serialization_descriptor(VALUE mPanko);
data/lib/panko/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Panko
3
- VERSION = "0.4.2"
3
+ VERSION = "0.4.3"
4
4
  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.4.2
4
+ version: 0.4.3
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-06-02 00:00:00.000000000 Z
11
+ date: 2018-06-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oj