| 1 |
|
| #define PERL_NO_GET_CONTEXT |
| 2 |
|
| #include "EXTERN.h" |
| 3 |
|
| #include "perl.h" |
| 4 |
|
| #include "XSUB.h" |
| 5 |
|
| |
| 6 |
|
| #include <string.h> |
| 7 |
|
| |
| 8 |
|
| #include "json_kind.h" |
| 9 |
|
| |
| 10 |
|
| const int json_kind_to_lex_pos[JV_KIND_COUNT] = { |
| 11 |
|
| /* JV_ARRAY_BOOL */ 0, |
| 12 |
|
| /* JV_ARRAY_FLOAT64 */ 1, |
| 13 |
|
| /* JV_ARRAY_INT64 */ 2, |
| 14 |
|
| /* JV_ARRAY_STRING */ 3, |
| 15 |
|
| /* JV_BOOL */ 4, |
| 16 |
|
| /* JV_FLOAT64 */ 5, |
| 17 |
|
| /* JV_INT64 */ 6, |
| 18 |
|
| /* JV_STRING */ 8 |
| 19 |
|
| }; |
| 20 |
|
| |
| 21 |
|
| const char * const json_kind_type_name[JV_KIND_COUNT] = { |
| 22 |
|
| "Array(Bool)", "Array(Float64)", "Array(Int64)", "Array(String)", |
| 23 |
|
| "Bool", "Float64", "Int64", "String" |
| 24 |
|
| }; |
| 25 |
|
| |
| 26 |
2800 |
| int json_build_lex_table(unsigned mask, int slots[JSON_LEX_SLOTS]) { |
| 27 |
2800 |
| int n = 0, lex; |
| 28 |
28000 |
▶ | for (lex = 0; lex < JSON_LEX_SLOTS; lex++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (lex = 0; lex < JSON_LEX_SLOTS; lex++) { |
25200 |
2800 |
28000 |
|
| 29 |
25200 |
▶ | if (lex == JSON_SHAREDVARIANT_LEX_POS) { slots[n++] = -1; continue; } |
Branch: 1 branch
| Branch | True | False | Total |
| if (lex == JSON_SHAREDVARIANT_LEX_POS) { slots[n++] = -1; continue; } |
2800 |
22400 |
25200 |
|
| 30 |
|
| int k; |
| 31 |
190355 |
▶ | for (k = 0; k < JV_KIND_COUNT; k++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (k = 0; k < JV_KIND_COUNT; k++) { |
171083 |
19272 |
190355 |
|
| 32 |
171083 |
▶ | if (json_kind_to_lex_pos[k] == lex && (mask & (1u << k))) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (json_kind_to_lex_pos[k] == lex && (mask & (1u << k))) { |
22400 |
148683 |
171083 |
| if (json_kind_to_lex_pos[k] == lex && (mask & (1u << k))) { |
3128 |
19272 |
22400 |
|
| 33 |
3128 |
| slots[n++] = k; |
| 34 |
3128 |
| break; |
| 35 |
|
| } |
| 36 |
|
| } |
| 37 |
|
| } |
| 38 |
2800 |
| return n; |
| 39 |
|
| } |
| 40 |
|
| |
| 41 |
2701 |
| int json_kind_disc_in(int kind, const int slots[JSON_LEX_SLOTS], int n) { |
| 42 |
|
| int i; |
| 43 |
3824 |
▶ | for (i = 0; i < n; i++) if (slots[i] == kind) return i; |
Branch: 2 branches
| Branch | True | False | Total |
| for (i = 0; i < n; i++) if (slots[i] == kind) return i; |
2701 |
1123 |
3824 |
| for (i = 0; i < n; i++) if (slots[i] == kind) return i; |
3824 |
0 |
3824 |
|
| 44 |
0 |
| return -1; /* unreachable when kind is in mask */ |
| 45 |
|
| } |
| 46 |
|
| |
| 47 |
1044 |
| int json_kind_from_type_name(const char *ts, STRLEN tl) { |
| 48 |
1044 |
▶ | if (tl == 4 && memcmp(ts, "Bool", 4) == 0) return JV_BOOL; |
Branch: 2 branches
| Branch | True | False | Total |
| if (tl == 4 && memcmp(ts, "Bool", 4) == 0) return JV_BOOL; |
419 |
625 |
1044 |
| if (tl == 4 && memcmp(ts, "Bool", 4) == 0) return JV_BOOL; |
419 |
0 |
419 |
|
| 49 |
625 |
▶ | if (tl == 7 && memcmp(ts, "Float64", 7) == 0) return JV_FLOAT64; |
Branch: 2 branches
| Branch | True | False | Total |
| if (tl == 7 && memcmp(ts, "Float64", 7) == 0) return JV_FLOAT64; |
70 |
555 |
625 |
| if (tl == 7 && memcmp(ts, "Float64", 7) == 0) return JV_FLOAT64; |
70 |
0 |
70 |
|
| 50 |
555 |
▶ | if (tl == 5 && memcmp(ts, "Int64", 5) == 0) return JV_INT64; |
Branch: 2 branches
| Branch | True | False | Total |
| if (tl == 5 && memcmp(ts, "Int64", 5) == 0) return JV_INT64; |
174 |
381 |
555 |
| if (tl == 5 && memcmp(ts, "Int64", 5) == 0) return JV_INT64; |
174 |
0 |
174 |
|
| 51 |
381 |
▶ | if (tl == 6 && memcmp(ts, "String", 6) == 0) return JV_STRING; |
Branch: 2 branches
| Branch | True | False | Total |
| if (tl == 6 && memcmp(ts, "String", 6) == 0) return JV_STRING; |
90 |
291 |
381 |
| if (tl == 6 && memcmp(ts, "String", 6) == 0) return JV_STRING; |
90 |
0 |
90 |
|
| 52 |
291 |
▶ | if (tl == 11 && memcmp(ts, "Array(Bool)", 11) == 0) return JV_ARRAY_BOOL; |
Branch: 2 branches
| Branch | True | False | Total |
| if (tl == 11 && memcmp(ts, "Array(Bool)", 11) == 0) return JV_ARRAY_BOOL; |
58 |
233 |
291 |
| if (tl == 11 && memcmp(ts, "Array(Bool)", 11) == 0) return JV_ARRAY_BOOL; |
58 |
0 |
58 |
|
| 53 |
233 |
▶ | if (tl == 14 && memcmp(ts, "Array(Float64)", 14) == 0) return JV_ARRAY_FLOAT64; |
Branch: 2 branches
| Branch | True | False | Total |
| if (tl == 14 && memcmp(ts, "Array(Float64)", 14) == 0) return JV_ARRAY_FLOAT64; |
61 |
172 |
233 |
| if (tl == 14 && memcmp(ts, "Array(Float64)", 14) == 0) return JV_ARRAY_FLOAT64; |
61 |
0 |
61 |
|
| 54 |
172 |
▶ | if (tl == 12 && memcmp(ts, "Array(Int64)", 12) == 0) return JV_ARRAY_INT64; |
Branch: 2 branches
| Branch | True | False | Total |
| if (tl == 12 && memcmp(ts, "Array(Int64)", 12) == 0) return JV_ARRAY_INT64; |
119 |
53 |
172 |
| if (tl == 12 && memcmp(ts, "Array(Int64)", 12) == 0) return JV_ARRAY_INT64; |
119 |
0 |
119 |
|
| 55 |
53 |
▶ | if (tl == 13 && memcmp(ts, "Array(String)", 13) == 0) return JV_ARRAY_STRING; |
Branch: 2 branches
| Branch | True | False | Total |
| if (tl == 13 && memcmp(ts, "Array(String)", 13) == 0) return JV_ARRAY_STRING; |
53 |
0 |
53 |
| if (tl == 13 && memcmp(ts, "Array(String)", 13) == 0) return JV_ARRAY_STRING; |
53 |
0 |
53 |
|
| 56 |
0 |
| return -1; |
| 57 |
|
| } |