| 1 |
|
| #define PERL_NO_GET_CONTEXT |
| 2 |
|
| #include "EXTERN.h" |
| 3 |
|
| #include "perl.h" |
| 4 |
|
| #include "XSUB.h" |
| 5 |
|
| |
| 6 |
|
| #include "XSParseKeyword.h" |
| 7 |
|
| |
| 8 |
|
| /* Use stronger inline hint */ |
| 9 |
|
| #ifndef PERL_STATIC_INLINE |
| 10 |
|
| #define PERL_STATIC_INLINE static inline |
| 11 |
|
| #endif |
| 12 |
|
| |
| 13 |
|
| /* Magic signature for fast type checking (avoids sv_derived_from) */ |
| 14 |
|
| #define COMPILED_PATH_MAGIC 0x44505853 /* "DPXS" */ |
| 15 |
|
| |
| 16 |
|
| /* Branch prediction hints */ |
| 17 |
|
| #ifndef LIKELY |
| 18 |
|
| # if defined(__GNUC__) || defined(__clang__) |
| 19 |
|
| # define LIKELY(x) __builtin_expect(!!(x), 1) |
| 20 |
|
| # define UNLIKELY(x) __builtin_expect(!!(x), 0) |
| 21 |
|
| # else |
| 22 |
|
| # define LIKELY(x) (x) |
| 23 |
|
| # define UNLIKELY(x) (x) |
| 24 |
|
| # endif |
| 25 |
|
| #endif |
| 26 |
|
| |
| 27 |
|
| /* Max safe index digits to avoid IV overflow |
| 28 |
|
| * 64-bit IV: max ~9e18 (19 digits), safe limit 18 |
| 29 |
|
| * 32-bit IV: max ~2e9 (10 digits), safe limit 9 |
| 30 |
|
| */ |
| 31 |
|
| #if IVSIZE >= 8 |
| 32 |
|
| # define MAX_INDEX_DIGITS 18 |
| 33 |
|
| #else |
| 34 |
|
| # define MAX_INDEX_DIGITS 9 |
| 35 |
|
| #endif |
| 36 |
|
| |
| 37 |
|
| /* Path component - pre-parsed */ |
| 38 |
|
| typedef struct { |
| 39 |
|
| const char *str; |
| 40 |
|
| STRLEN len; |
| 41 |
|
| IV idx; /* Pre-parsed array index (valid only if is_numeric) */ |
| 42 |
|
| U32 hash; |
| 43 |
|
| U8 is_numeric; /* 1 if component is a valid array index, 0 for hash key */ |
| 44 |
|
| U8 next_is_array; /* 1 if next component is numeric (create array), 0 for hash */ |
| 45 |
|
| } PathComponent; |
| 46 |
|
| |
| 47 |
|
| /* Compiled path object - flexible array member for cache locality */ |
| 48 |
|
| typedef struct { |
| 49 |
|
| U32 magic; /* COMPILED_PATH_MAGIC for fast type check */ |
| 50 |
|
| I32 utf8_flag; /* +1 for byte path, -1 for UTF-8 path (signed klen factor) */ |
| 51 |
|
| SSize_t count; |
| 52 |
|
| SV *path_sv; /* Owned copy of path string buffer */ |
| 53 |
|
| PathComponent components[1]; /* Flexible array member (C89 style) */ |
| 54 |
|
| } CompiledPath; |
| 55 |
|
| |
| 56 |
|
| /* Fast compiled path validation - check ref, payload type, and magic. |
| 57 |
|
| * sv_setref_pv produces an RV whose target is an IV-bearing SV; if not IOK, |
| 58 |
|
| * input is not a compiled path. Checking SvIOK avoids "isn't numeric" warnings |
| 59 |
|
| * from SvIV on bless'd hashes/arrays/garbage. */ |
| 60 |
|
| #define VALIDATE_COMPILED_PATH(sv, cp) do { \ |
| 61 |
|
| SV *_inner; \ |
| 62 |
|
| if (UNLIKELY(!SvROK(sv) || !SvIOK(_inner = SvRV(sv)))) croak("Not a compiled path"); \ |
| 63 |
|
| cp = INT2PTR(CompiledPath*, SvIVX(_inner)); \ |
| 64 |
|
| if (UNLIKELY(!cp || cp->magic != COMPILED_PATH_MAGIC)) croak("Not a compiled path"); \ |
| 65 |
|
| } while(0) |
| 66 |
|
| |
| 67 |
|
| /* Check if string is a valid array index, parse it |
| 68 |
|
| * Returns 0 for: empty, leading zeros, non-digits, overflow |
| 69 |
|
| * Accepts negative indices (e.g., "-1" for last element) |
| 70 |
|
| * Note: "-0" parses as 0 (single zero after minus is allowed) |
| 71 |
|
| * Max safe index: we limit to MAX_INDEX_DIGITS digits to avoid IV overflow |
| 72 |
|
| */ |
| 73 |
60010 |
| PERL_STATIC_INLINE int is_array_index(const char *s, STRLEN len, IV *idx) { |
| 74 |
60010 |
| IV val = 0; |
| 75 |
60010 |
| const char *end = s + len; |
| 76 |
60010 |
| int negative = 0; |
| 77 |
|
| |
| 78 |
|
| /* Length cap includes the optional leading minus sign. */ |
| 79 |
60010 |
▶ | if (UNLIKELY(len == 0 || len > (MAX_INDEX_DIGITS + 1))) return 0; |
Branch: 2 branches
| Branch | True | False | Total |
| if (UNLIKELY(len == 0 || len > (MAX_INDEX_DIGITS + 1))) return 0; |
60010 |
0 |
60010 |
| if (UNLIKELY(len == 0 || len > (MAX_INDEX_DIGITS + 1))) return 0; |
1 |
60009 |
60010 |
|
| 80 |
|
| |
| 81 |
60009 |
▶ | if (*s == '-') { |
Branch: 1 branch
| Branch | True | False | Total |
| if (*s == '-') { |
19 |
59990 |
60009 |
|
| 82 |
19 |
| negative = 1; |
| 83 |
19 |
| s++; |
| 84 |
19 |
| len--; |
| 85 |
19 |
▶ | if (UNLIKELY(len == 0)) return 0; |
Branch: 1 branch
| Branch | True | False | Total |
| if (UNLIKELY(len == 0)) return 0; |
0 |
19 |
19 |
|
| 86 |
|
| } |
| 87 |
|
| |
| 88 |
60009 |
▶ | if (UNLIKELY(len > MAX_INDEX_DIGITS)) return 0; |
Branch: 1 branch
| Branch | True | False | Total |
| if (UNLIKELY(len > MAX_INDEX_DIGITS)) return 0; |
1 |
60008 |
60009 |
|
| 89 |
60008 |
▶ | if (len > 1 && *s == '0') return 0; /* leading zeros => hash key */ |
Branch: 2 branches
| Branch | True | False | Total |
| if (len > 1 && *s == '0') return 0; /* leading zeros => hash key */ |
566 |
59442 |
60008 |
| if (len > 1 && *s == '0') return 0; /* leading zeros => hash key */ |
12 |
554 |
566 |
|
| 90 |
|
| |
| 91 |
102519 |
▶ | while (s < end) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (s < end) { |
60023 |
42496 |
102519 |
|
| 92 |
60023 |
▶ | if (UNLIKELY(*s < '0' || *s > '9')) return 0; |
Branch: 2 branches
| Branch | True | False | Total |
| if (UNLIKELY(*s < '0' || *s > '9')) return 0; |
60017 |
6 |
60023 |
| if (UNLIKELY(*s < '0' || *s > '9')) return 0; |
17494 |
42523 |
60017 |
|
| 93 |
42523 |
| val = val * 10 + (*s - '0'); |
| 94 |
42523 |
| s++; |
| 95 |
|
| } |
| 96 |
|
| |
| 97 |
42496 |
▶ | *idx = negative ? -val : val; |
Branch: 1 branch
| Branch | True | False | Total |
| *idx = negative ? -val : val; |
19 |
42477 |
42496 |
|
| 98 |
42496 |
| return 1; |
| 99 |
|
| } |
| 100 |
|
| |
| 101 |
|
| /* SvPV + SvUTF8 → signed klen (negative encodes UTF-8 to hv_*). */ |
| 102 |
40220 |
| PERL_STATIC_INLINE I32 sv_to_klen(pTHX_ SV *sv, const char **kstr_out) { |
| 103 |
|
| STRLEN klen; |
| 104 |
40220 |
| *kstr_out = SvPV(sv, klen); |
| 105 |
40220 |
▶ | return SvUTF8(sv) ? -(I32)klen : (I32)klen; |
Branch: 1 branch
| Branch | True | False | Total |
| return SvUTF8(sv) ? -(I32)klen : (I32)klen; |
8 |
40212 |
40220 |
|
| 106 |
|
| } |
| 107 |
|
| |
| 108 |
|
| /* Snapshot magical values once; plain values need no copy. */ |
| 109 |
365947 |
| PERL_STATIC_INLINE SV *path_value(pTHX_ SV *sv) { |
| 110 |
365947 |
▶ | return UNLIKELY(SvGMAGICAL(sv)) ? sv_2mortal(newSVsv(sv)) : sv; |
Branch: 1 branch
| Branch | True | False | Total |
| return UNLIKELY(SvGMAGICAL(sv)) ? sv_2mortal(newSVsv(sv)) : sv; |
410 |
365537 |
365947 |
|
| 111 |
|
| } |
| 112 |
|
| |
| 113 |
218721 |
| PERL_STATIC_INLINE SV *path_fetch(pTHX_ SV **svp) { |
| 114 |
218721 |
▶ | return svp && *svp ? path_value(aTHX_ *svp) : NULL; |
Branch: 2 branches
| Branch | True | False | Total |
| return svp && *svp ? path_value(aTHX_ *svp) : NULL; |
193794 |
24927 |
218721 |
| return svp && *svp ? path_value(aTHX_ *svp) : NULL; |
193794 |
0 |
193794 |
|
| 115 |
|
| } |
| 116 |
|
| |
| 117 |
145476 |
| PERL_STATIC_INLINE SV *path_fetch_retained(pTHX_ SV **svp, const char *path) { |
| 118 |
145476 |
▶ | if (svp && *svp && SvPOK(*svp) && SvPVX(*svp) == path) |
Branch: 4 branches
| Branch | True | False | Total |
| if (svp && *svp && SvPOK(*svp) && SvPVX(*svp) == path) |
126594 |
18882 |
145476 |
| if (svp && *svp && SvPOK(*svp) && SvPVX(*svp) == path) |
126594 |
0 |
126594 |
| if (svp && *svp && SvPOK(*svp) && SvPVX(*svp) == path) |
412 |
126182 |
126594 |
| if (svp && *svp && SvPOK(*svp) && SvPVX(*svp) == path) |
402 |
10 |
412 |
|
| 119 |
402 |
| sv_2mortal(SvREFCNT_inc(*svp)); |
| 120 |
145476 |
| return path_fetch(aTHX_ svp); |
| 121 |
|
| } |
| 122 |
|
| |
| 123 |
316 |
| PERL_STATIC_INLINE SV *path_container(pTHX_ SV *sv) { |
| 124 |
316 |
▶ | if (LIKELY((SvFLAGS(sv) & (SVf_ROK | SVs_GMG)) == SVf_ROK)) return sv; |
Branch: 1 branch
| Branch | True | False | Total |
| if (LIKELY((SvFLAGS(sv) & (SVf_ROK | SVs_GMG)) == SVf_ROK)) return sv; |
314 |
2 |
316 |
|
| 125 |
2 |
| sv = path_value(aTHX_ sv); |
| 126 |
2 |
▶ | return SvROK(sv) ? sv : NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| return SvROK(sv) ? sv : NULL; |
0 |
2 |
2 |
|
| 127 |
|
| } |
| 128 |
|
| |
| 129 |
706 |
| PERL_STATIC_INLINE SV *compiled_fetch(pTHX_ HV *hv, const PathComponent *c, I32 utf8_flag) { |
| 130 |
706 |
| return path_fetch(aTHX_ (SV**)hv_common_key_len(hv, c->str, |
| 131 |
|
| (I32)c->len * utf8_flag, HV_FETCH_JUST_SV, NULL, c->hash)); |
| 132 |
|
| } |
| 133 |
|
| |
| 134 |
45379 |
| PERL_STATIC_INLINE SV *path_source(pTHX_ SV *sv) { |
| 135 |
45379 |
| sv = path_value(aTHX_ sv); |
| 136 |
45379 |
▶ | return sv_2mortal(SvWEAKREF(sv) ? newSVsv(sv) : SvREFCNT_inc(sv)); |
Branch: 1 branch
| Branch | True | False | Total |
| return sv_2mortal(SvWEAKREF(sv) ? newSVsv(sv) : SvREFCNT_inc(sv)); |
8 |
45371 |
45379 |
|
| 137 |
|
| } |
| 138 |
|
| |
| 139 |
23274 |
| PERL_STATIC_INLINE SV *path_store_hash(pTHX_ HV *hv, const char *key, I32 len, |
| 140 |
|
| U32 hash, SV *value, const char *api) { |
| 141 |
23274 |
▶ | if (UNLIKELY(SvRMAGICAL((SV*)hv))) |
Branch: 1 branch
| Branch | True | False | Total |
| if (UNLIKELY(SvRMAGICAL((SV*)hv))) |
12 |
23262 |
23274 |
|
| 142 |
12 |
| croak("Cannot %s on tied/magical hash", api); |
| 143 |
23262 |
| SV **slot = (SV**)hv_common_key_len(hv, key, len, |
| 144 |
|
| HV_FETCH_JUST_SV | HV_FETCH_LVALUE, NULL, hash); |
| 145 |
23254 |
▶ | if (UNLIKELY(!slot || !*slot)) croak("Failed to store value"); |
Branch: 2 branches
| Branch | True | False | Total |
| if (UNLIKELY(!slot || !*slot)) croak("Failed to store value"); |
23254 |
0 |
23254 |
| if (UNLIKELY(!slot || !*slot)) croak("Failed to store value"); |
0 |
23254 |
23254 |
|
| 146 |
23254 |
| SV *target = *slot; |
| 147 |
23254 |
▶ | if (UNLIKELY(SvMAGICAL(target))) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (UNLIKELY(SvMAGICAL(target))) { |
0 |
23254 |
23254 |
|
| 148 |
0 |
| SV *copy = sv_2mortal(newSVsv(value)); |
| 149 |
0 |
▶ | if (!hv_store(hv, key, len, copy, hash)) croak("Failed to store value"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!hv_store(hv, key, len, copy, hash)) croak("Failed to store value"); |
0 |
0 |
0 |
|
| 150 |
0 |
| SvREFCNT_inc_simple_void_NN(copy); |
| 151 |
0 |
| return copy; |
| 152 |
|
| } |
| 153 |
23254 |
▶ | if (SvROK(target) && SvROK(value) && SvRV(target) == SvRV(value) |
Branch: 3 branches
| Branch | True | False | Total |
| if (SvROK(target) && SvROK(value) && SvRV(target) == SvRV(value) |
17 |
23237 |
23254 |
| if (SvROK(target) && SvROK(value) && SvRV(target) == SvRV(value) |
13 |
4 |
17 |
| if (SvROK(target) && SvROK(value) && SvRV(target) == SvRV(value) |
8 |
5 |
13 |
|
| 154 |
8 |
▶ | && !SvWEAKREF(target) && !SvREADONLY(target) && !SvMAGICAL(value)) |
Branch: 3 branches
| Branch | True | False | Total |
| && !SvWEAKREF(target) && !SvREADONLY(target) && !SvMAGICAL(value)) |
4 |
4 |
8 |
| && !SvWEAKREF(target) && !SvREADONLY(target) && !SvMAGICAL(value)) |
0 |
4 |
4 |
| && !SvWEAKREF(target) && !SvREADONLY(target) && !SvMAGICAL(value)) |
0 |
0 |
0 |
|
| 155 |
0 |
| return target; |
| 156 |
23254 |
| sv_setsv_nomg(target, value); |
| 157 |
23242 |
| return target; |
| 158 |
|
| } |
| 159 |
|
| |
| 160 |
20067 |
| PERL_STATIC_INLINE SV *path_store_array(pTHX_ AV *av, IV idx, SV *value, const char *api) { |
| 161 |
20067 |
▶ | if (UNLIKELY(SvRMAGICAL((SV*)av))) |
Branch: 1 branch
| Branch | True | False | Total |
| if (UNLIKELY(SvRMAGICAL((SV*)av))) |
1 |
20066 |
20067 |
|
| 162 |
1 |
| croak("Cannot %s on tied/magical array", api); |
| 163 |
20066 |
▶ | if (UNLIKELY(SvREADONLY((SV*)av))) |
Branch: 1 branch
| Branch | True | False | Total |
| if (UNLIKELY(SvREADONLY((SV*)av))) |
0 |
20066 |
20066 |
|
| 164 |
0 |
| croak("Modification of a read-only value attempted"); |
| 165 |
20066 |
| SV **slot = av_fetch(av, idx, 1); |
| 166 |
20066 |
▶ | if (UNLIKELY(!slot || !*slot)) croak("Failed to store value"); |
Branch: 2 branches
| Branch | True | False | Total |
| if (UNLIKELY(!slot || !*slot)) croak("Failed to store value"); |
20062 |
4 |
20066 |
| if (UNLIKELY(!slot || !*slot)) croak("Failed to store value"); |
0 |
20062 |
20062 |
|
| 167 |
20062 |
| SV *target = *slot; |
| 168 |
20062 |
▶ | if (UNLIKELY(SvMAGICAL(target))) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (UNLIKELY(SvMAGICAL(target))) { |
0 |
20062 |
20062 |
|
| 169 |
0 |
| SV *copy = sv_2mortal(newSVsv(value)); |
| 170 |
0 |
▶ | if (!av_store(av, idx, copy)) croak("Failed to store value"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!av_store(av, idx, copy)) croak("Failed to store value"); |
0 |
0 |
0 |
|
| 171 |
0 |
| SvREFCNT_inc_simple_void_NN(copy); |
| 172 |
0 |
| return copy; |
| 173 |
|
| } |
| 174 |
20062 |
▶ | if (SvROK(target) && SvROK(value) && SvRV(target) == SvRV(value) |
Branch: 3 branches
| Branch | True | False | Total |
| if (SvROK(target) && SvROK(value) && SvRV(target) == SvRV(value) |
16 |
20046 |
20062 |
| if (SvROK(target) && SvROK(value) && SvRV(target) == SvRV(value) |
8 |
8 |
16 |
| if (SvROK(target) && SvROK(value) && SvRV(target) == SvRV(value) |
4 |
4 |
8 |
|
| 175 |
4 |
▶ | && !SvWEAKREF(target) && !SvREADONLY(target) && !SvMAGICAL(value)) |
Branch: 3 branches
| Branch | True | False | Total |
| && !SvWEAKREF(target) && !SvREADONLY(target) && !SvMAGICAL(value)) |
0 |
4 |
4 |
| && !SvWEAKREF(target) && !SvREADONLY(target) && !SvMAGICAL(value)) |
0 |
0 |
0 |
| && !SvWEAKREF(target) && !SvREADONLY(target) && !SvMAGICAL(value)) |
0 |
0 |
0 |
|
| 176 |
0 |
| return target; |
| 177 |
20062 |
| sv_setsv_nomg(target, value); |
| 178 |
20062 |
| return target; |
| 179 |
|
| } |
| 180 |
|
| |
| 181 |
|
| /* True iff p..end (after slash-skipping) has no further non-empty components. */ |
| 182 |
744 |
| PERL_STATIC_INLINE int kw_at_last_component(const char *p, const char *end) { |
| 183 |
1142 |
▶ | while (p < end && *p == '/') p++; |
Branch: 2 branches
| Branch | True | False | Total |
| while (p < end && *p == '/') p++; |
784 |
358 |
1142 |
| while (p < end && *p == '/') p++; |
398 |
386 |
784 |
|
| 184 |
744 |
| return p >= end; |
| 185 |
|
| } |
| 186 |
|
| |
| 187 |
|
| /* Fast SV to index - check IOK first, accept negative for Perl-style access */ |
| 188 |
4115 |
| PERL_STATIC_INLINE int sv_to_index(pTHX_ SV *sv, IV *idx) { |
| 189 |
4115 |
| sv = path_value(aTHX_ sv); |
| 190 |
4115 |
▶ | if (SvIOK(sv) && !SvPOK(sv)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (SvIOK(sv) && !SvPOK(sv)) { |
80 |
4035 |
4115 |
| if (SvIOK(sv) && !SvPOK(sv)) { |
75 |
5 |
80 |
|
| 191 |
75 |
| *idx = SvIVX(sv); |
| 192 |
75 |
| return 1; |
| 193 |
|
| } |
| 194 |
|
| STRLEN len; |
| 195 |
4040 |
| const char *s = SvPV(sv, len); |
| 196 |
4040 |
| return is_array_index(s, len, idx); |
| 197 |
|
| } |
| 198 |
|
| |
| 199 |
|
| /* Navigate using raw char* path components. |
| 200 |
|
| * utf8_flag is +1 for byte keys, -1 for UTF-8 keys (signed klen convention). */ |
| 201 |
109537 |
| PERL_STATIC_INLINE SV* navigate_to_parent(pTHX_ SV *data, const char *path, STRLEN path_len, |
| 202 |
|
| const char **final_key_ptr, STRLEN *final_key_len, |
| 203 |
|
| int create, I32 utf8_flag) { |
| 204 |
109537 |
| const char *p = path; |
| 205 |
109537 |
| const char *end = path + path_len; |
| 206 |
109537 |
| SV *current = path_value(aTHX_ data); |
| 207 |
|
| |
| 208 |
109537 |
▶ | if (UNLIKELY(path_len == 0)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (UNLIKELY(path_len == 0)) { |
0 |
109537 |
109537 |
|
| 209 |
0 |
| *final_key_ptr = NULL; |
| 210 |
0 |
| *final_key_len = 0; |
| 211 |
0 |
| return data; |
| 212 |
|
| } |
| 213 |
|
| |
| 214 |
|
| /* Skip leading slash if present (optional for consistency with keyword API) */ |
| 215 |
109537 |
▶ | if (*p == '/') p++; |
Branch: 1 branch
| Branch | True | False | Total |
| if (*p == '/') p++; |
107336 |
2201 |
109537 |
|
| 216 |
|
| |
| 217 |
246722 |
▶ | while (p < end) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (p < end) { |
246718 |
4 |
246722 |
|
| 218 |
246718 |
| const char *tok_start = p; |
| 219 |
882514 |
▶ | while (p < end && *p != '/') p++; |
Branch: 2 branches
| Branch | True | False | Total |
| while (p < end && *p != '/') p++; |
780998 |
101516 |
882514 |
| while (p < end && *p != '/') p++; |
635796 |
145202 |
780998 |
|
| 220 |
246718 |
| STRLEN tok_len = p - tok_start; |
| 221 |
|
| |
| 222 |
|
| /* Skip empty components (e.g., double slashes, trailing slashes) */ |
| 223 |
246718 |
▶ | if (UNLIKELY(tok_len == 0)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (UNLIKELY(tok_len == 0)) { |
13 |
246705 |
246718 |
|
| 224 |
13 |
| p++; /* Always advance to avoid infinite loop */ |
| 225 |
13 |
| continue; |
| 226 |
|
| } |
| 227 |
|
| |
| 228 |
|
| /* Skip trailing slashes to check if this is the last real component */ |
| 229 |
246705 |
| const char *check = p; |
| 230 |
391909 |
▶ | while (check < end && *check == '/') check++; |
Branch: 2 branches
| Branch | True | False | Total |
| while (check < end && *check == '/') check++; |
290387 |
101522 |
391909 |
| while (check < end && *check == '/') check++; |
145204 |
145183 |
290387 |
|
| 231 |
|
| |
| 232 |
|
| /* Last non-empty token - return parent */ |
| 233 |
246705 |
▶ | if (check >= end) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (check >= end) { |
101522 |
145183 |
246705 |
|
| 234 |
101522 |
| *final_key_ptr = tok_start; |
| 235 |
101522 |
| *final_key_len = tok_len; |
| 236 |
101522 |
| return current; |
| 237 |
|
| } |
| 238 |
|
| |
| 239 |
|
| /* Navigate deeper */ |
| 240 |
145183 |
▶ | if (UNLIKELY(!SvROK(current))) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (UNLIKELY(!SvROK(current))) { |
0 |
145183 |
145183 |
|
| 241 |
0 |
| *final_key_ptr = NULL; |
| 242 |
0 |
| return NULL; |
| 243 |
|
| } |
| 244 |
|
| |
| 245 |
145183 |
| SV *inner = SvRV(current); |
| 246 |
145183 |
| svtype t = SvTYPE(inner); |
| 247 |
|
| |
| 248 |
145183 |
▶ | if (LIKELY(t == SVt_PVHV)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (LIKELY(t == SVt_PVHV)) { |
143056 |
2127 |
145183 |
|
| 249 |
143056 |
| HV *hv = (HV*)inner; |
| 250 |
143056 |
| SV *val = path_fetch_retained(aTHX_ hv_fetch(hv, tok_start, (I32)tok_len * utf8_flag, 0), path); |
| 251 |
143054 |
▶ | if (UNLIKELY(!val || !SvROK(val))) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (UNLIKELY(!val || !SvROK(val))) { |
124222 |
18832 |
143054 |
| if (UNLIKELY(!val || !SvROK(val))) { |
2109 |
122113 |
124222 |
|
| 252 |
20941 |
▶ | if (create) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (create) { |
12935 |
8006 |
20941 |
|
| 253 |
|
| /* Tied/magical containers can't autovivify — hv_store |
| 254 |
|
| * returns NULL without invoking STORE. Croak with a |
| 255 |
|
| * useful message rather than the generic one above. */ |
| 256 |
12935 |
▶ | if (UNLIKELY(SvRMAGICAL((SV*)hv))) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (UNLIKELY(SvRMAGICAL((SV*)hv))) { |
0 |
12935 |
12935 |
|
| 257 |
0 |
| croak("Cannot path_set on tied/magical hash"); |
| 258 |
|
| } |
| 259 |
|
| /* check already points at next real component start */ |
| 260 |
12935 |
| const char *next_end = check; |
| 261 |
26302 |
▶ | while (next_end < end && *next_end != '/') next_end++; |
Branch: 2 branches
| Branch | True | False | Total |
| while (next_end < end && *next_end != '/') next_end++; |
21986 |
4316 |
26302 |
| while (next_end < end && *next_end != '/') next_end++; |
13367 |
8619 |
21986 |
|
| 262 |
|
| IV dummy; |
| 263 |
12935 |
▶ | SV *new_ref = sv_2mortal(is_array_index(check, next_end - check, &dummy) |
Branch: 1 branch
| Branch | True | False | Total |
| SV *new_ref = sv_2mortal(is_array_index(check, next_end - check, &dummy) |
9 |
12926 |
12935 |
|
| 264 |
|
| ? newRV_noinc((SV*)newAV()) |
| 265 |
|
| : newRV_noinc((SV*)newHV())); |
| 266 |
12935 |
▶ | if (UNLIKELY(!hv_store(hv, tok_start, (I32)tok_len * utf8_flag, new_ref, 0))) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (UNLIKELY(!hv_store(hv, tok_start, (I32)tok_len * utf8_flag, new_ref, 0))) { |
0 |
12935 |
12935 |
|
| 267 |
0 |
| *final_key_ptr = NULL; |
| 268 |
0 |
| return NULL; |
| 269 |
|
| } |
| 270 |
12935 |
| SvREFCNT_inc_simple_void_NN(new_ref); |
| 271 |
12935 |
| current = new_ref; |
| 272 |
|
| } else { |
| 273 |
8006 |
| *final_key_ptr = NULL; |
| 274 |
8006 |
| return NULL; |
| 275 |
|
| } |
| 276 |
|
| } else { |
| 277 |
122113 |
| current = val; |
| 278 |
|
| } |
| 279 |
2127 |
▶ | } else if (t == SVt_PVAV) { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if (t == SVt_PVAV) { |
2127 |
0 |
2127 |
|
| 280 |
|
| IV idx; |
| 281 |
2127 |
▶ | if (UNLIKELY(!is_array_index(tok_start, tok_len, &idx))) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (UNLIKELY(!is_array_index(tok_start, tok_len, &idx))) { |
1 |
2126 |
2127 |
|
| 282 |
1 |
| *final_key_ptr = NULL; |
| 283 |
2 |
| return NULL; |
| 284 |
|
| } |
| 285 |
2126 |
| SV *val = path_fetch_retained(aTHX_ av_fetch((AV*)inner, idx, 0), path); |
| 286 |
2126 |
▶ | if (UNLIKELY(!val || !SvROK(val))) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (UNLIKELY(!val || !SvROK(val))) { |
2118 |
8 |
2126 |
| if (UNLIKELY(!val || !SvROK(val))) { |
101 |
2017 |
2118 |
|
| 287 |
109 |
▶ | if (create) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (create) { |
108 |
1 |
109 |
|
| 288 |
108 |
▶ | if (UNLIKELY(SvRMAGICAL((SV*)inner))) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (UNLIKELY(SvRMAGICAL((SV*)inner))) { |
1 |
107 |
108 |
|
| 289 |
1 |
| croak("Cannot path_set on tied/magical array"); |
| 290 |
|
| } |
| 291 |
107 |
| const char *next_end = check; |
| 292 |
619 |
▶ | while (next_end < end && *next_end != '/') next_end++; |
Branch: 2 branches
| Branch | True | False | Total |
| while (next_end < end && *next_end != '/') next_end++; |
514 |
105 |
619 |
| while (next_end < end && *next_end != '/') next_end++; |
512 |
2 |
514 |
|
| 293 |
|
| IV dummy; |
| 294 |
107 |
▶ | SV *new_ref = sv_2mortal(is_array_index(check, next_end - check, &dummy) |
Branch: 1 branch
| Branch | True | False | Total |
| SV *new_ref = sv_2mortal(is_array_index(check, next_end - check, &dummy) |
4 |
103 |
107 |
|
| 295 |
|
| ? newRV_noinc((SV*)newAV()) |
| 296 |
|
| : newRV_noinc((SV*)newHV())); |
| 297 |
107 |
▶ | if (UNLIKELY(!av_store((AV*)inner, idx, new_ref))) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (UNLIKELY(!av_store((AV*)inner, idx, new_ref))) { |
0 |
107 |
107 |
|
| 298 |
0 |
| *final_key_ptr = NULL; |
| 299 |
0 |
| return NULL; |
| 300 |
|
| } |
| 301 |
107 |
| SvREFCNT_inc_simple_void_NN(new_ref); |
| 302 |
107 |
| current = new_ref; |
| 303 |
|
| } else { |
| 304 |
1 |
| *final_key_ptr = NULL; |
| 305 |
1 |
| return NULL; |
| 306 |
|
| } |
| 307 |
|
| } else { |
| 308 |
2017 |
| current = val; |
| 309 |
|
| } |
| 310 |
|
| } else { |
| 311 |
0 |
| *final_key_ptr = NULL; |
| 312 |
0 |
| return NULL; |
| 313 |
|
| } |
| 314 |
|
| |
| 315 |
137172 |
| p++; |
| 316 |
|
| } |
| 317 |
|
| |
| 318 |
4 |
| *final_key_ptr = NULL; |
| 319 |
4 |
| return current; |
| 320 |
|
| } |
| 321 |
|
| |
| 322 |
|
| /* Compile a path string into reusable components */ |
| 323 |
101 |
| static CompiledPath* compile_path(pTHX_ SV *path_sv) { |
| 324 |
|
| STRLEN path_len; |
| 325 |
101 |
| const char *path = SvPV(path_sv, path_len); |
| 326 |
|
| CompiledPath *cp; |
| 327 |
101 |
| SSize_t count = 0; |
| 328 |
|
| const char *p; |
| 329 |
101 |
| const char *path_end = path + path_len; |
| 330 |
|
| |
| 331 |
|
| /* Skip leading slash */ |
| 332 |
101 |
| const char *start = path; |
| 333 |
101 |
▶ | if (path_len > 0 && *start == '/') start++; |
Branch: 2 branches
| Branch | True | False | Total |
| if (path_len > 0 && *start == '/') start++; |
94 |
7 |
101 |
| if (path_len > 0 && *start == '/') start++; |
93 |
1 |
94 |
|
| 334 |
|
| |
| 335 |
|
| /* Count non-empty components (skip double slashes) */ |
| 336 |
101 |
| p = start; |
| 337 |
271 |
▶ | while (p < path_end) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (p < path_end) { |
170 |
101 |
271 |
|
| 338 |
170 |
| const char *tok_start = p; |
| 339 |
558 |
▶ | while (p < path_end && *p != '/') p++; |
Branch: 2 branches
| Branch | True | False | Total |
| while (p < path_end && *p != '/') p++; |
464 |
94 |
558 |
| while (p < path_end && *p != '/') p++; |
388 |
76 |
464 |
|
| 340 |
170 |
▶ | if (p > tok_start) count++; |
Branch: 1 branch
| Branch | True | False | Total |
| if (p > tok_start) count++; |
170 |
0 |
170 |
|
| 341 |
170 |
▶ | if (p < path_end) p++; |
Branch: 1 branch
| Branch | True | False | Total |
| if (p < path_end) p++; |
76 |
94 |
170 |
|
| 342 |
|
| } |
| 343 |
|
| |
| 344 |
|
| /* Empty path, root path ("/"), or all-slashes ("///") */ |
| 345 |
101 |
▶ | if (count == 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (count == 0) { |
7 |
94 |
101 |
|
| 346 |
7 |
| Newxz(cp, 1, CompiledPath); |
| 347 |
7 |
| cp->magic = COMPILED_PATH_MAGIC; |
| 348 |
7 |
▶ | cp->utf8_flag = SvUTF8(path_sv) ? -1 : 1; |
Branch: 1 branch
| Branch | True | False | Total |
| cp->utf8_flag = SvUTF8(path_sv) ? -1 : 1; |
0 |
7 |
7 |
|
| 349 |
7 |
| cp->count = 0; |
| 350 |
7 |
| cp->path_sv = newSVpvn_flags(path, path_len, SvUTF8(path_sv) ? SVf_UTF8 : 0); |
| 351 |
7 |
| return cp; |
| 352 |
|
| } |
| 353 |
|
| |
| 354 |
|
| /* Single alloc: base struct already has 1 inline component slot. */ |
| 355 |
94 |
| Size_t alloc_size = sizeof(CompiledPath) + (count - 1) * sizeof(PathComponent); |
| 356 |
94 |
| Newxc(cp, alloc_size, char, CompiledPath); |
| 357 |
|
| |
| 358 |
94 |
| cp->magic = COMPILED_PATH_MAGIC; |
| 359 |
94 |
▶ | cp->utf8_flag = SvUTF8(path_sv) ? -1 : 1; |
Branch: 1 branch
| Branch | True | False | Total |
| cp->utf8_flag = SvUTF8(path_sv) ? -1 : 1; |
3 |
91 |
94 |
|
| 360 |
94 |
| cp->count = count; |
| 361 |
|
| /* Create independent copy of path string so PathComponent pointers |
| 362 |
|
| * remain valid even if the original SV's buffer is modified/freed */ |
| 363 |
94 |
| cp->path_sv = newSVpvn_flags(path, path_len, SvUTF8(path_sv) ? SVf_UTF8 : 0); |
| 364 |
|
| |
| 365 |
|
| /* Re-derive pointers into our own copy's buffer */ |
| 366 |
94 |
| const char *copy_buf = SvPVX(cp->path_sv); |
| 367 |
94 |
| const char *copy_start = copy_buf + (start - path); |
| 368 |
94 |
| const char *copy_end = copy_buf + path_len; |
| 369 |
|
| |
| 370 |
|
| /* Parse components directly into inline array, skipping empty ones */ |
| 371 |
94 |
| p = copy_start; |
| 372 |
94 |
| SSize_t i = 0; |
| 373 |
264 |
▶ | while (p < copy_end && i < count) { |
Branch: 2 branches
| Branch | True | False | Total |
| while (p < copy_end && i < count) { |
170 |
94 |
264 |
| while (p < copy_end && i < count) { |
170 |
0 |
170 |
|
| 374 |
170 |
| const char *tok_start = p; |
| 375 |
558 |
▶ | while (p < copy_end && *p != '/') p++; |
Branch: 2 branches
| Branch | True | False | Total |
| while (p < copy_end && *p != '/') p++; |
464 |
94 |
558 |
| while (p < copy_end && *p != '/') p++; |
388 |
76 |
464 |
|
| 376 |
170 |
| STRLEN tok_len = p - tok_start; |
| 377 |
170 |
▶ | if (tok_len > 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (tok_len > 0) { |
170 |
0 |
170 |
|
| 378 |
170 |
| cp->components[i].str = tok_start; |
| 379 |
170 |
| cp->components[i].len = tok_len; |
| 380 |
170 |
| cp->components[i].hash = 0; |
| 381 |
170 |
▶ | if (cp->utf8_flag > 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if (cp->utf8_flag > 0) |
165 |
5 |
170 |
|
| 382 |
165 |
▶ | PERL_HASH(cp->components[i].hash, tok_start, tok_len); |
Branch: 1 branch
| Branch | True | False | Total |
| PERL_HASH(cp->components[i].hash, tok_start, tok_len); |
165 |
0 |
165 |
|
| 383 |
170 |
| cp->components[i].is_numeric = is_array_index(tok_start, tok_len, &cp->components[i].idx); |
| 384 |
170 |
| cp->components[i].next_is_array = 0; /* Will set below */ |
| 385 |
170 |
| i++; |
| 386 |
|
| } |
| 387 |
170 |
▶ | if (p < copy_end) p++; /* Skip slash */ |
Branch: 1 branch
| Branch | True | False | Total |
| if (p < copy_end) p++; /* Skip slash */ |
76 |
94 |
170 |
|
| 388 |
|
| } |
| 389 |
|
| |
| 390 |
|
| /* Pre-compute next_is_array flag for faster creation */ |
| 391 |
170 |
▶ | for (SSize_t j = 0; j < count - 1; j++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (SSize_t j = 0; j < count - 1; j++) { |
76 |
94 |
170 |
|
| 392 |
76 |
| cp->components[j].next_is_array = cp->components[j + 1].is_numeric; |
| 393 |
|
| } |
| 394 |
94 |
| cp->components[count - 1].next_is_array = 0; /* Last element */ |
| 395 |
|
| |
| 396 |
94 |
| return cp; |
| 397 |
|
| } |
| 398 |
|
| |
| 399 |
101 |
| static void free_compiled_path(pTHX_ CompiledPath *cp) { |
| 400 |
101 |
▶ | if (cp) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (cp) { |
101 |
0 |
101 |
|
| 401 |
101 |
| SvREFCNT_dec(cp->path_sv); |
| 402 |
101 |
| Safefree(cp); |
| 403 |
|
| } |
| 404 |
101 |
| } |
| 405 |
|
| |
| 406 |
|
| /* ========== KEYWORD SUPPORT ========== */ |
| 407 |
|
| |
| 408 |
|
| /* Custom ops for dynamic path access - runs directly in runloop */ |
| 409 |
|
| static XOP xop_pathget; |
| 410 |
|
| static XOP xop_pathset; |
| 411 |
|
| static XOP xop_pathdelete; |
| 412 |
|
| static XOP xop_pathexists; |
| 413 |
|
| |
| 414 |
|
| #define KW_RETURN(value) STMT_START { \ |
| 415 |
|
| SV *result = (value); \ |
| 416 |
|
| SPAGAIN; \ |
| 417 |
|
| PUSHs(result); \ |
| 418 |
|
| RETURN; \ |
| 419 |
|
| } STMT_END |
| 420 |
|
| |
| 421 |
108 |
| static OP* pp_pathget_dynamic(pTHX) |
| 422 |
|
| { |
| 423 |
108 |
| dSP; |
| 424 |
108 |
| SV *path_sv = POPs; |
| 425 |
108 |
| SV *data_sv = POPs; |
| 426 |
108 |
| PUTBACK; |
| 427 |
|
| |
| 428 |
|
| STRLEN path_len; |
| 429 |
108 |
| const char *path = SvPV(path_sv, path_len); |
| 430 |
108 |
| const char *p = path; |
| 431 |
108 |
| const char *end = path + path_len; |
| 432 |
108 |
▶ | const I32 utf8_flag = SvUTF8(path_sv) ? -1 : 1; |
Branch: 1 branch
| Branch | True | False | Total |
| const I32 utf8_flag = SvUTF8(path_sv) ? -1 : 1; |
3 |
105 |
108 |
|
| 433 |
|
| |
| 434 |
108 |
| SV *current = data_sv; |
| 435 |
|
| |
| 436 |
|
| /* Skip leading slashes */ |
| 437 |
214 |
▶ | while (p < end && *p == '/') p++; |
Branch: 2 branches
| Branch | True | False | Total |
| while (p < end && *p == '/') p++; |
211 |
3 |
214 |
| while (p < end && *p == '/') p++; |
106 |
105 |
211 |
|
| 438 |
|
| |
| 439 |
335 |
▶ | while (p < end) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (p < end) { |
229 |
106 |
335 |
|
| 440 |
229 |
| const char *start = p; |
| 441 |
1945 |
▶ | while (p < end && *p != '/') p++; |
Branch: 2 branches
| Branch | True | False | Total |
| while (p < end && *p != '/') p++; |
1842 |
103 |
1945 |
| while (p < end && *p != '/') p++; |
1716 |
126 |
1842 |
|
| 442 |
229 |
| STRLEN comp_len = p - start; |
| 443 |
|
| |
| 444 |
229 |
▶ | if (UNLIKELY(comp_len == 0)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (UNLIKELY(comp_len == 0)) { |
5 |
224 |
229 |
|
| 445 |
5 |
▶ | if (p < end) p++; |
Branch: 1 branch
| Branch | True | False | Total |
| if (p < end) p++; |
5 |
0 |
5 |
|
| 446 |
5 |
| continue; |
| 447 |
|
| } |
| 448 |
|
| |
| 449 |
224 |
▶ | if (UNLIKELY(!(current = path_container(aTHX_ current)))) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (UNLIKELY(!(current = path_container(aTHX_ current)))) { |
2 |
222 |
224 |
|
| 450 |
2 |
| current = &PL_sv_undef; |
| 451 |
2 |
| break; |
| 452 |
|
| } |
| 453 |
|
| |
| 454 |
222 |
| SV *inner = SvRV(current); |
| 455 |
222 |
| svtype t = SvTYPE(inner); |
| 456 |
|
| |
| 457 |
|
| /* Dispatch by parent container type, like path_get/patha_get/pathc_get. |
| 458 |
|
| * Hash keys that look numeric are still hash keys. */ |
| 459 |
222 |
▶ | if (LIKELY(t == SVt_PVHV)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (LIKELY(t == SVt_PVHV)) { |
171 |
51 |
222 |
|
| 460 |
171 |
| SV **svp = hv_fetch((HV*)inner, start, (I32)comp_len * utf8_flag, 0); |
| 461 |
171 |
▶ | current = svp && *svp ? *svp : &PL_sv_undef; |
Branch: 2 branches
| Branch | True | False | Total |
| current = svp && *svp ? *svp : &PL_sv_undef; |
164 |
7 |
171 |
| current = svp && *svp ? *svp : &PL_sv_undef; |
164 |
0 |
164 |
|
| 462 |
51 |
▶ | } else if (t == SVt_PVAV) { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if (t == SVt_PVAV) { |
51 |
0 |
51 |
|
| 463 |
|
| IV idx; |
| 464 |
51 |
▶ | if (UNLIKELY(!is_array_index(start, comp_len, &idx))) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (UNLIKELY(!is_array_index(start, comp_len, &idx))) { |
0 |
51 |
51 |
|
| 465 |
0 |
| current = &PL_sv_undef; |
| 466 |
0 |
| break; |
| 467 |
|
| } |
| 468 |
51 |
| SV **elem = av_fetch((AV*)inner, idx, 0); |
| 469 |
51 |
▶ | current = elem && *elem ? *elem : &PL_sv_undef; |
Branch: 2 branches
| Branch | True | False | Total |
| current = elem && *elem ? *elem : &PL_sv_undef; |
49 |
2 |
51 |
| current = elem && *elem ? *elem : &PL_sv_undef; |
49 |
0 |
49 |
|
| 470 |
|
| } else { |
| 471 |
0 |
| current = &PL_sv_undef; |
| 472 |
0 |
| break; |
| 473 |
|
| } |
| 474 |
|
| |
| 475 |
222 |
▶ | if (p < end && *p == '/') p++; |
Branch: 2 branches
| Branch | True | False | Total |
| if (p < end && *p == '/') p++; |
120 |
102 |
222 |
| if (p < end && *p == '/') p++; |
120 |
0 |
120 |
|
| 476 |
|
| } |
| 477 |
|
| |
| 478 |
108 |
| current = path_value(aTHX_ current); |
| 479 |
108 |
| KW_RETURN(sv_2mortal(SvREFCNT_inc(current))); |
| 480 |
|
| } |
| 481 |
|
| |
| 482 |
|
| /* Check if the next non-empty component (after p) parses as an array index. */ |
| 483 |
248 |
| PERL_STATIC_INLINE int kw_next_component_is_numeric(const char *p, const char *end) |
| 484 |
|
| { |
| 485 |
500 |
▶ | while (p < end && *p == '/') p++; |
Branch: 2 branches
| Branch | True | False | Total |
| while (p < end && *p == '/') p++; |
500 |
0 |
500 |
| while (p < end && *p == '/') p++; |
252 |
248 |
500 |
|
| 486 |
248 |
▶ | if (p >= end) return 0; |
Branch: 1 branch
| Branch | True | False | Total |
| if (p >= end) return 0; |
0 |
248 |
248 |
|
| 487 |
248 |
| const char *q = p; |
| 488 |
1367 |
▶ | while (q < end && *q != '/') q++; |
Branch: 2 branches
| Branch | True | False | Total |
| while (q < end && *q != '/') q++; |
1135 |
232 |
1367 |
| while (q < end && *q != '/') q++; |
1119 |
16 |
1135 |
|
| 489 |
|
| IV dummy; |
| 490 |
248 |
| return is_array_index(p, q - p, &dummy); |
| 491 |
|
| } |
| 492 |
|
| |
| 493 |
|
| /* Custom op for dynamic path set with autovivification. |
| 494 |
|
| * Dispatches by parent container type (consistent with path_set/patha_set/pathc_set): |
| 495 |
|
| * hash parent -> use component as hash key (even if numeric-looking); |
| 496 |
|
| * array parent -> require numeric component. */ |
| 497 |
290 |
| static OP* pp_pathset_dynamic(pTHX) |
| 498 |
|
| { |
| 499 |
290 |
| dSP; dMARK; dORIGMARK; |
| 500 |
290 |
| SV *data_sv = *++MARK; |
| 501 |
290 |
| SV *path_sv = *++MARK; |
| 502 |
290 |
| SV *value_sv = *++MARK; |
| 503 |
290 |
| SP = ORIGMARK; /* Reset stack to before our args */ |
| 504 |
290 |
| PUTBACK; |
| 505 |
290 |
| value_sv = path_source(aTHX_ value_sv); |
| 506 |
290 |
| SV *stored = NULL; |
| 507 |
|
| |
| 508 |
|
| STRLEN path_len; |
| 509 |
290 |
| const char *path = SvPV(path_sv, path_len); |
| 510 |
290 |
| const char *p = path; |
| 511 |
290 |
| const char *end = path + path_len; |
| 512 |
290 |
▶ | const I32 utf8_flag = SvUTF8(path_sv) ? -1 : 1; |
Branch: 1 branch
| Branch | True | False | Total |
| const I32 utf8_flag = SvUTF8(path_sv) ? -1 : 1; |
3 |
287 |
290 |
|
| 513 |
|
| |
| 514 |
|
| /* Skip leading slashes */ |
| 515 |
381 |
▶ | while (p < end && *p == '/') p++; |
Branch: 2 branches
| Branch | True | False | Total |
| while (p < end && *p == '/') p++; |
376 |
5 |
381 |
| while (p < end && *p == '/') p++; |
91 |
285 |
376 |
|
| 516 |
|
| |
| 517 |
290 |
▶ | if (UNLIKELY(p >= end)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (UNLIKELY(p >= end)) { |
5 |
285 |
290 |
|
| 518 |
|
| /* Empty path (or all slashes) - can't set root */ |
| 519 |
5 |
| croak("Cannot set root"); |
| 520 |
|
| } |
| 521 |
|
| |
| 522 |
285 |
| SV *current = path_value(aTHX_ data_sv); |
| 523 |
|
| |
| 524 |
583 |
▶ | while (p < end) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (p < end) { |
583 |
0 |
583 |
|
| 525 |
583 |
| const char *start = p; |
| 526 |
3850 |
▶ | while (p < end && *p != '/') p++; |
Branch: 2 branches
| Branch | True | False | Total |
| while (p < end && *p != '/') p++; |
3571 |
279 |
3850 |
| while (p < end && *p != '/') p++; |
3267 |
304 |
3571 |
|
| 527 |
583 |
| STRLEN comp_len = p - start; |
| 528 |
|
| |
| 529 |
583 |
▶ | if (UNLIKELY(comp_len == 0)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (UNLIKELY(comp_len == 0)) { |
4 |
579 |
583 |
|
| 530 |
4 |
▶ | if (p < end) p++; |
Branch: 1 branch
| Branch | True | False | Total |
| if (p < end) p++; |
4 |
0 |
4 |
|
| 531 |
4 |
| continue; |
| 532 |
|
| } |
| 533 |
|
| |
| 534 |
579 |
| int is_last = kw_at_last_component(p, end); |
| 535 |
|
| |
| 536 |
579 |
▶ | if (UNLIKELY(!SvROK(current))) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (UNLIKELY(!SvROK(current))) { |
1 |
578 |
579 |
|
| 537 |
1 |
| croak("Cannot navigate to path"); |
| 538 |
|
| } |
| 539 |
|
| |
| 540 |
578 |
| SV *inner = SvRV(current); |
| 541 |
578 |
| svtype t = SvTYPE(inner); |
| 542 |
|
| |
| 543 |
578 |
▶ | if (LIKELY(t == SVt_PVHV)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (LIKELY(t == SVt_PVHV)) { |
431 |
147 |
578 |
|
| 544 |
431 |
| HV *hv = (HV*)inner; |
| 545 |
431 |
| I32 klen = (I32)comp_len * utf8_flag; |
| 546 |
|
| |
| 547 |
431 |
▶ | if (is_last) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (is_last) { |
260 |
171 |
431 |
|
| 548 |
260 |
| stored = path_store_hash(aTHX_ hv, start, klen, 0, value_sv, "pathset"); |
| 549 |
252 |
| break; |
| 550 |
|
| } else { |
| 551 |
171 |
| SV *elem = path_fetch_retained(aTHX_ hv_fetch(hv, start, klen, 0), path); |
| 552 |
169 |
▶ | if (!elem || !SvROK(elem)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (!elem || !SvROK(elem)) { |
140 |
29 |
169 |
| if (!elem || !SvROK(elem)) { |
107 |
33 |
140 |
|
| 553 |
136 |
▶ | if (UNLIKELY(SvRMAGICAL((SV*)hv))) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (UNLIKELY(SvRMAGICAL((SV*)hv))) { |
1 |
135 |
136 |
|
| 554 |
1 |
| croak("Cannot pathset on tied/magical hash"); |
| 555 |
|
| } |
| 556 |
135 |
▶ | SV *new_ref = sv_2mortal(kw_next_component_is_numeric(p, end) |
Branch: 1 branch
| Branch | True | False | Total |
| SV *new_ref = sv_2mortal(kw_next_component_is_numeric(p, end) |
16 |
119 |
135 |
|
| 557 |
|
| ? newRV_noinc((SV*)newAV()) |
| 558 |
|
| : newRV_noinc((SV*)newHV())); |
| 559 |
135 |
▶ | if (UNLIKELY(!hv_store(hv, start, klen, new_ref, 0))) |
Branch: 1 branch
| Branch | True | False | Total |
| if (UNLIKELY(!hv_store(hv, start, klen, new_ref, 0))) |
0 |
135 |
135 |
|
| 560 |
0 |
| croak("Cannot navigate to path"); |
| 561 |
135 |
| SvREFCNT_inc_simple_void_NN(new_ref); |
| 562 |
135 |
| current = new_ref; |
| 563 |
|
| } else { |
| 564 |
33 |
| current = elem; |
| 565 |
|
| } |
| 566 |
|
| } |
| 567 |
147 |
▶ | } else if (t == SVt_PVAV) { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if (t == SVt_PVAV) { |
147 |
0 |
147 |
|
| 568 |
|
| IV idx; |
| 569 |
147 |
▶ | if (UNLIKELY(!is_array_index(start, comp_len, &idx))) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (UNLIKELY(!is_array_index(start, comp_len, &idx))) { |
1 |
146 |
147 |
|
| 570 |
1 |
| croak("Cannot navigate to path"); |
| 571 |
|
| } |
| 572 |
146 |
| AV *av = (AV*)inner; |
| 573 |
|
| |
| 574 |
146 |
▶ | if (is_last) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (is_last) { |
19 |
127 |
146 |
|
| 575 |
19 |
| stored = path_store_array(aTHX_ av, idx, value_sv, "pathset"); |
| 576 |
18 |
| break; |
| 577 |
|
| } else { |
| 578 |
127 |
| SV *elem = path_fetch_retained(aTHX_ av_fetch(av, idx, 0), path); |
| 579 |
127 |
▶ | if (!elem || !SvROK(elem)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (!elem || !SvROK(elem)) { |
114 |
13 |
127 |
| if (!elem || !SvROK(elem)) { |
101 |
13 |
114 |
|
| 580 |
114 |
▶ | if (UNLIKELY(SvRMAGICAL((SV*)av))) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (UNLIKELY(SvRMAGICAL((SV*)av))) { |
1 |
113 |
114 |
|
| 581 |
1 |
| croak("Cannot pathset on tied/magical array"); |
| 582 |
|
| } |
| 583 |
113 |
▶ | SV *new_ref = sv_2mortal(kw_next_component_is_numeric(p, end) |
Branch: 1 branch
| Branch | True | False | Total |
| SV *new_ref = sv_2mortal(kw_next_component_is_numeric(p, end) |
0 |
113 |
113 |
|
| 584 |
|
| ? newRV_noinc((SV*)newAV()) |
| 585 |
|
| : newRV_noinc((SV*)newHV())); |
| 586 |
113 |
▶ | if (UNLIKELY(!av_store(av, idx, new_ref))) |
Branch: 1 branch
| Branch | True | False | Total |
| if (UNLIKELY(!av_store(av, idx, new_ref))) |
0 |
113 |
113 |
|
| 587 |
0 |
| croak("Cannot navigate to path"); |
| 588 |
113 |
| SvREFCNT_inc_simple_void_NN(new_ref); |
| 589 |
113 |
| current = new_ref; |
| 590 |
|
| } else { |
| 591 |
13 |
| current = elem; |
| 592 |
|
| } |
| 593 |
|
| } |
| 594 |
|
| } else { |
| 595 |
0 |
| croak("Cannot navigate to path"); |
| 596 |
|
| } |
| 597 |
|
| |
| 598 |
294 |
▶ | if (p < end && *p == '/') p++; |
Branch: 2 branches
| Branch | True | False | Total |
| if (p < end && *p == '/') p++; |
294 |
0 |
294 |
| if (p < end && *p == '/') p++; |
294 |
0 |
294 |
|
| 599 |
|
| } |
| 600 |
|
| |
| 601 |
270 |
| SPAGAIN; |
| 602 |
270 |
▶ | if (GIMME_V != G_VOID) |
Branch: 1 branch
| Branch | True | False | Total |
| if (GIMME_V != G_VOID) |
9 |
261 |
270 |
|
| 603 |
9 |
| PUSHs(sv_2mortal(SvREFCNT_inc(stored))); |
| 604 |
270 |
| RETURN; |
| 605 |
|
| } |
| 606 |
|
| |
| 607 |
|
| /* Custom op for dynamic path delete. |
| 608 |
|
| * Dispatches the final delete by parent container type. */ |
| 609 |
39 |
| static OP* pp_pathdelete_dynamic(pTHX) |
| 610 |
|
| { |
| 611 |
39 |
| dSP; |
| 612 |
39 |
| SV *path_sv = POPs; |
| 613 |
39 |
| SV *data_sv = POPs; |
| 614 |
39 |
| PUTBACK; |
| 615 |
|
| |
| 616 |
|
| STRLEN path_len; |
| 617 |
39 |
| const char *path = SvPV(path_sv, path_len); |
| 618 |
39 |
| const char *p = path; |
| 619 |
39 |
| const char *end = path + path_len; |
| 620 |
39 |
▶ | const I32 utf8_flag = SvUTF8(path_sv) ? -1 : 1; |
Branch: 1 branch
| Branch | True | False | Total |
| const I32 utf8_flag = SvUTF8(path_sv) ? -1 : 1; |
2 |
37 |
39 |
|
| 621 |
|
| |
| 622 |
|
| /* Skip leading slashes */ |
| 623 |
79 |
▶ | while (p < end && *p == '/') p++; |
Branch: 2 branches
| Branch | True | False | Total |
| while (p < end && *p == '/') p++; |
75 |
4 |
79 |
| while (p < end && *p == '/') p++; |
40 |
35 |
75 |
|
| 624 |
|
| |
| 625 |
39 |
▶ | if (p >= end) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (p >= end) { |
4 |
35 |
39 |
|
| 626 |
|
| /* Empty path (or all slashes) - can't delete root */ |
| 627 |
4 |
| croak("Cannot delete root"); |
| 628 |
|
| } |
| 629 |
|
| |
| 630 |
35 |
| SV *current = path_value(aTHX_ data_sv); |
| 631 |
35 |
| SV *parent = NULL; |
| 632 |
35 |
| const char *last_key_start = NULL; |
| 633 |
35 |
| STRLEN last_key_len = 0; |
| 634 |
|
| |
| 635 |
73 |
▶ | while (p < end) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (p < end) { |
73 |
0 |
73 |
|
| 636 |
73 |
| const char *start = p; |
| 637 |
260 |
▶ | while (p < end && *p != '/') p++; |
Branch: 2 branches
| Branch | True | False | Total |
| while (p < end && *p != '/') p++; |
228 |
32 |
260 |
| while (p < end && *p != '/') p++; |
187 |
41 |
228 |
|
| 638 |
73 |
| STRLEN comp_len = p - start; |
| 639 |
|
| |
| 640 |
73 |
▶ | if (UNLIKELY(comp_len == 0)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (UNLIKELY(comp_len == 0)) { |
0 |
73 |
73 |
|
| 641 |
0 |
▶ | if (p < end) p++; |
Branch: 1 branch
| Branch | True | False | Total |
| if (p < end) p++; |
0 |
0 |
0 |
|
| 642 |
0 |
| continue; |
| 643 |
|
| } |
| 644 |
|
| |
| 645 |
73 |
| int is_last = kw_at_last_component(p, end); |
| 646 |
|
| |
| 647 |
73 |
▶ | if (is_last) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (is_last) { |
33 |
40 |
73 |
|
| 648 |
33 |
| parent = current; |
| 649 |
33 |
| last_key_start = start; |
| 650 |
33 |
| last_key_len = comp_len; |
| 651 |
33 |
| break; |
| 652 |
|
| } |
| 653 |
|
| |
| 654 |
40 |
▶ | if (UNLIKELY(!SvROK(current))) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (UNLIKELY(!SvROK(current))) { |
2 |
38 |
40 |
|
| 655 |
2 |
| KW_RETURN(&PL_sv_undef); |
| 656 |
|
| } |
| 657 |
|
| |
| 658 |
38 |
| SV *inner = SvRV(current); |
| 659 |
38 |
| svtype t = SvTYPE(inner); |
| 660 |
|
| |
| 661 |
38 |
▶ | if (LIKELY(t == SVt_PVHV)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (LIKELY(t == SVt_PVHV)) { |
36 |
2 |
38 |
|
| 662 |
36 |
| SV *svp = path_fetch(aTHX_ hv_fetch((HV*)inner, start, (I32)comp_len * utf8_flag, 0)); |
| 663 |
36 |
▶ | current = svp ? svp : &PL_sv_undef; |
Branch: 1 branch
| Branch | True | False | Total |
| current = svp ? svp : &PL_sv_undef; |
36 |
0 |
36 |
|
| 664 |
2 |
▶ | } else if (t == SVt_PVAV) { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if (t == SVt_PVAV) { |
2 |
0 |
2 |
|
| 665 |
|
| IV idx; |
| 666 |
2 |
▶ | if (UNLIKELY(!is_array_index(start, comp_len, &idx))) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (UNLIKELY(!is_array_index(start, comp_len, &idx))) { |
0 |
2 |
2 |
|
| 667 |
0 |
| KW_RETURN(&PL_sv_undef); |
| 668 |
|
| } |
| 669 |
2 |
| SV *elem = path_fetch(aTHX_ av_fetch((AV*)inner, idx, 0)); |
| 670 |
2 |
▶ | current = elem ? elem : &PL_sv_undef; |
Branch: 1 branch
| Branch | True | False | Total |
| current = elem ? elem : &PL_sv_undef; |
2 |
0 |
2 |
|
| 671 |
|
| } else { |
| 672 |
0 |
| KW_RETURN(&PL_sv_undef); |
| 673 |
|
| } |
| 674 |
|
| |
| 675 |
38 |
▶ | if (p < end && *p == '/') p++; |
Branch: 2 branches
| Branch | True | False | Total |
| if (p < end && *p == '/') p++; |
38 |
0 |
38 |
| if (p < end && *p == '/') p++; |
38 |
0 |
38 |
|
| 676 |
|
| } |
| 677 |
|
| |
| 678 |
|
| /* Perform the delete by parent container type */ |
| 679 |
33 |
| SV *deleted = NULL; |
| 680 |
33 |
▶ | if (parent && SvROK(parent)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (parent && SvROK(parent)) { |
33 |
0 |
33 |
| if (parent && SvROK(parent)) { |
33 |
0 |
33 |
|
| 681 |
33 |
| SV *inner = SvRV(parent); |
| 682 |
33 |
| svtype t = SvTYPE(inner); |
| 683 |
33 |
▶ | if (LIKELY(t == SVt_PVHV)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (LIKELY(t == SVt_PVHV)) { |
27 |
6 |
33 |
|
| 684 |
27 |
| deleted = hv_delete((HV*)inner, last_key_start, |
| 685 |
|
| (I32)last_key_len * utf8_flag, 0); |
| 686 |
6 |
▶ | } else if (t == SVt_PVAV) { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if (t == SVt_PVAV) { |
6 |
0 |
6 |
|
| 687 |
|
| IV idx; |
| 688 |
6 |
▶ | if (is_array_index(last_key_start, last_key_len, &idx)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (is_array_index(last_key_start, last_key_len, &idx)) |
6 |
0 |
6 |
|
| 689 |
6 |
| deleted = av_delete((AV*)inner, idx, 0); |
| 690 |
|
| } |
| 691 |
|
| } |
| 692 |
|
| |
| 693 |
|
| /* hv_delete/av_delete with flags=0 already mortalize the returned SV. */ |
| 694 |
33 |
▶ | KW_RETURN(deleted ? deleted : &PL_sv_undef); |
Branch: 1 branch
| Branch | True | False | Total |
| KW_RETURN(deleted ? deleted : &PL_sv_undef); |
31 |
2 |
33 |
|
| 695 |
|
| } |
| 696 |
|
| |
| 697 |
|
| /* Custom op for dynamic path exists check. |
| 698 |
|
| * Dispatches by parent container type. */ |
| 699 |
50 |
| static OP* pp_pathexists_dynamic(pTHX) |
| 700 |
|
| { |
| 701 |
50 |
| dSP; |
| 702 |
50 |
| SV *path_sv = POPs; |
| 703 |
50 |
| SV *data_sv = POPs; |
| 704 |
50 |
| PUTBACK; |
| 705 |
|
| |
| 706 |
|
| STRLEN path_len; |
| 707 |
50 |
| const char *path = SvPV(path_sv, path_len); |
| 708 |
50 |
| const char *p = path; |
| 709 |
50 |
| const char *end = path + path_len; |
| 710 |
50 |
▶ | const I32 utf8_flag = SvUTF8(path_sv) ? -1 : 1; |
Branch: 1 branch
| Branch | True | False | Total |
| const I32 utf8_flag = SvUTF8(path_sv) ? -1 : 1; |
1 |
49 |
50 |
|
| 711 |
|
| |
| 712 |
|
| /* Skip leading slashes */ |
| 713 |
99 |
▶ | while (p < end && *p == '/') p++; |
Branch: 2 branches
| Branch | True | False | Total |
| while (p < end && *p == '/') p++; |
95 |
4 |
99 |
| while (p < end && *p == '/') p++; |
49 |
46 |
95 |
|
| 714 |
|
| |
| 715 |
50 |
▶ | if (p >= end) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (p >= end) { |
4 |
46 |
50 |
|
| 716 |
|
| /* Empty path - root always exists (consistent with path_exists) */ |
| 717 |
4 |
| KW_RETURN(&PL_sv_yes); |
| 718 |
|
| } |
| 719 |
|
| |
| 720 |
46 |
| SV *current = data_sv; |
| 721 |
|
| |
| 722 |
92 |
▶ | while (p < end) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (p < end) { |
92 |
0 |
92 |
|
| 723 |
92 |
| const char *start = p; |
| 724 |
319 |
▶ | while (p < end && *p != '/') p++; |
Branch: 2 branches
| Branch | True | False | Total |
| while (p < end && *p != '/') p++; |
276 |
43 |
319 |
| while (p < end && *p != '/') p++; |
227 |
49 |
276 |
|
| 725 |
92 |
| STRLEN comp_len = p - start; |
| 726 |
|
| |
| 727 |
92 |
▶ | if (UNLIKELY(comp_len == 0)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (UNLIKELY(comp_len == 0)) { |
0 |
92 |
92 |
|
| 728 |
0 |
▶ | if (p < end) p++; |
Branch: 1 branch
| Branch | True | False | Total |
| if (p < end) p++; |
0 |
0 |
0 |
|
| 729 |
0 |
| continue; |
| 730 |
|
| } |
| 731 |
|
| |
| 732 |
92 |
| int is_last = kw_at_last_component(p, end); |
| 733 |
|
| |
| 734 |
92 |
▶ | if (UNLIKELY(!(current = path_container(aTHX_ current)))) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (UNLIKELY(!(current = path_container(aTHX_ current)))) { |
0 |
92 |
92 |
|
| 735 |
0 |
| KW_RETURN(&PL_sv_no); |
| 736 |
|
| } |
| 737 |
|
| |
| 738 |
92 |
| SV *inner = SvRV(current); |
| 739 |
92 |
| svtype t = SvTYPE(inner); |
| 740 |
|
| |
| 741 |
92 |
▶ | if (LIKELY(t == SVt_PVHV)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (LIKELY(t == SVt_PVHV)) { |
79 |
13 |
92 |
|
| 742 |
79 |
| HV *hv = (HV*)inner; |
| 743 |
79 |
| I32 klen = (I32)comp_len * utf8_flag; |
| 744 |
79 |
▶ | if (is_last) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (is_last) { |
35 |
44 |
79 |
|
| 745 |
35 |
▶ | KW_RETURN(hv_exists(hv, start, klen) ? &PL_sv_yes : &PL_sv_no); |
Branch: 1 branch
| Branch | True | False | Total |
| KW_RETURN(hv_exists(hv, start, klen) ? &PL_sv_yes : &PL_sv_no); |
27 |
8 |
35 |
|
| 746 |
|
| } |
| 747 |
44 |
| SV **svp = hv_fetch(hv, start, klen, 0); |
| 748 |
44 |
▶ | if (!svp || !*svp) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (!svp || !*svp) { |
43 |
1 |
44 |
| if (!svp || !*svp) { |
0 |
43 |
43 |
|
| 749 |
1 |
| KW_RETURN(&PL_sv_no); |
| 750 |
|
| } |
| 751 |
43 |
| current = *svp; |
| 752 |
13 |
▶ | } else if (t == SVt_PVAV) { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if (t == SVt_PVAV) { |
13 |
0 |
13 |
|
| 753 |
|
| IV idx; |
| 754 |
13 |
▶ | if (UNLIKELY(!is_array_index(start, comp_len, &idx))) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (UNLIKELY(!is_array_index(start, comp_len, &idx))) { |
0 |
13 |
13 |
|
| 755 |
10 |
| KW_RETURN(&PL_sv_no); |
| 756 |
|
| } |
| 757 |
13 |
| AV *av = (AV*)inner; |
| 758 |
13 |
▶ | if (is_last) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (is_last) { |
9 |
4 |
13 |
|
| 759 |
9 |
▶ | KW_RETURN(av_exists(av, idx) ? &PL_sv_yes : &PL_sv_no); |
Branch: 1 branch
| Branch | True | False | Total |
| KW_RETURN(av_exists(av, idx) ? &PL_sv_yes : &PL_sv_no); |
5 |
4 |
9 |
|
| 760 |
|
| } |
| 761 |
4 |
| SV **elem = av_fetch(av, idx, 0); |
| 762 |
4 |
▶ | if (!elem || !*elem) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (!elem || !*elem) { |
3 |
1 |
4 |
| if (!elem || !*elem) { |
0 |
3 |
3 |
|
| 763 |
1 |
| KW_RETURN(&PL_sv_no); |
| 764 |
|
| } |
| 765 |
3 |
| current = *elem; |
| 766 |
|
| } else { |
| 767 |
0 |
| KW_RETURN(&PL_sv_no); |
| 768 |
|
| } |
| 769 |
|
| |
| 770 |
46 |
▶ | if (p < end && *p == '/') p++; |
Branch: 2 branches
| Branch | True | False | Total |
| if (p < end && *p == '/') p++; |
46 |
0 |
46 |
| if (p < end && *p == '/') p++; |
46 |
0 |
46 |
|
| 771 |
|
| } |
| 772 |
|
| |
| 773 |
|
| /* All components consumed (or path was all slashes) - root/value exists */ |
| 774 |
0 |
| KW_RETURN(&PL_sv_yes); |
| 775 |
|
| } |
| 776 |
|
| |
| 777 |
|
| /* Wrap a (data, path) pair as a custom binop dispatched to ppaddr. */ |
| 778 |
169 |
| PERL_STATIC_INLINE OP* kw_make_binop(pTHX_ OP *data_op, OP *path_op, |
| 779 |
|
| OP *(*ppaddr)(pTHX)) |
| 780 |
|
| { |
| 781 |
169 |
| OP *binop = newBINOP(OP_NULL, 0, data_op, path_op); |
| 782 |
169 |
| binop->op_type = OP_CUSTOM; |
| 783 |
169 |
| binop->op_ppaddr = ppaddr; |
| 784 |
169 |
| return binop; |
| 785 |
|
| } |
| 786 |
|
| |
| 787 |
|
| /* Build a chain of HELEM accesses for constant-path assignment (lvalue). |
| 788 |
|
| * Only entered when build_kw_pathset has verified all components are |
| 789 |
|
| * non-numeric strings, so no AELEM branch is needed. */ |
| 790 |
23 |
| static OP* kw_build_deref_chain_lvalue(pTHX_ OP *data_op, const char *path, STRLEN path_len) |
| 791 |
|
| { |
| 792 |
23 |
| OP *current = data_op; |
| 793 |
23 |
| const char *p = path; |
| 794 |
23 |
| const char *end = path + path_len; |
| 795 |
|
| |
| 796 |
23 |
▶ | if (p < end && *p == '/') p++; |
Branch: 2 branches
| Branch | True | False | Total |
| if (p < end && *p == '/') p++; |
23 |
0 |
23 |
| if (p < end && *p == '/') p++; |
22 |
1 |
23 |
|
| 797 |
|
| |
| 798 |
74 |
▶ | while (p < end) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (p < end) { |
51 |
23 |
74 |
|
| 799 |
51 |
| const char *start = p; |
| 800 |
139 |
▶ | while (p < end && *p != '/') p++; |
Branch: 2 branches
| Branch | True | False | Total |
| while (p < end && *p != '/') p++; |
117 |
22 |
139 |
| while (p < end && *p != '/') p++; |
88 |
29 |
117 |
|
| 801 |
51 |
| STRLEN comp_len = p - start; |
| 802 |
|
| |
| 803 |
51 |
▶ | if (comp_len == 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (comp_len == 0) { |
3 |
48 |
51 |
|
| 804 |
3 |
▶ | if (p < end) p++; |
Branch: 1 branch
| Branch | True | False | Total |
| if (p < end) p++; |
3 |
0 |
3 |
|
| 805 |
3 |
| continue; |
| 806 |
|
| } |
| 807 |
|
| |
| 808 |
48 |
| current = newBINOP(OP_HELEM, OPf_MOD, |
| 809 |
|
| newUNOP(OP_RV2HV, OPf_REF | OPf_MOD, current), |
| 810 |
|
| newSVOP(OP_CONST, 0, newSVpvn(start, comp_len))); |
| 811 |
|
| |
| 812 |
48 |
▶ | if (p < end && *p == '/') p++; |
Branch: 2 branches
| Branch | True | False | Total |
| if (p < end && *p == '/') p++; |
26 |
22 |
48 |
| if (p < end && *p == '/') p++; |
26 |
0 |
26 |
|
| 813 |
|
| } |
| 814 |
|
| |
| 815 |
23 |
| return current; |
| 816 |
|
| } |
| 817 |
|
| |
| 818 |
|
| /* Build a LISTOP-style custom op carrying (pushmark, data, path, value). */ |
| 819 |
67 |
| static OP* kw_build_dynamic_pathset(pTHX_ OP *data_op, OP *path_op, OP *value_op) |
| 820 |
|
| { |
| 821 |
67 |
| OP *list = op_append_elem(OP_LIST, newOP(OP_PUSHMARK, 0), data_op); |
| 822 |
67 |
| list = op_append_elem(OP_LIST, list, path_op); |
| 823 |
67 |
| list = op_append_elem(OP_LIST, list, value_op); |
| 824 |
|
| |
| 825 |
67 |
| OP *custom = op_convert_list(OP_NULL, 0, list); |
| 826 |
67 |
| custom->op_type = OP_CUSTOM; |
| 827 |
67 |
| custom->op_ppaddr = pp_pathset_dynamic; |
| 828 |
67 |
| return custom; |
| 829 |
|
| } |
| 830 |
|
| |
| 831 |
|
| /* The build callback for 'pathget' keyword */ |
| 832 |
90 |
| static int build_kw_pathget(pTHX_ OP **out, XSParseKeywordPiece *args[], |
| 833 |
|
| size_t nargs, void *hookdata) |
| 834 |
|
| { |
| 835 |
|
| PERL_UNUSED_ARG(nargs); |
| 836 |
|
| PERL_UNUSED_ARG(hookdata); |
| 837 |
|
| |
| 838 |
90 |
| OP *data_op = args[0]->op; |
| 839 |
90 |
| OP *path_op = args[1]->op; |
| 840 |
|
| |
| 841 |
|
| /* Always use custom op to avoid autovivification of intermediate levels */ |
| 842 |
90 |
| *out = kw_make_binop(aTHX_ data_op, path_op, pp_pathget_dynamic); |
| 843 |
90 |
| return KEYWORD_PLUGIN_EXPR; |
| 844 |
|
| } |
| 845 |
|
| |
| 846 |
|
| /* Keyword hooks structure for pathget */ |
| 847 |
|
| static const struct XSParseKeywordHooks hooks_pathget = { |
| 848 |
|
| .permit_hintkey = "Data::Path::XS/pathget", |
| 849 |
|
| .pieces = (const struct XSParseKeywordPieceType []) { |
| 850 |
|
| XPK_TERMEXPR_SCALARCTX, /* data structure */ |
| 851 |
|
| XPK_COMMA, /* , */ |
| 852 |
|
| XPK_TERMEXPR_SCALARCTX, /* path */ |
| 853 |
|
| {0} |
| 854 |
|
| }, |
| 855 |
|
| .build = &build_kw_pathget, |
| 856 |
|
| }; |
| 857 |
|
| |
| 858 |
|
| /* The build callback for 'pathset' keyword */ |
| 859 |
93 |
| static int build_kw_pathset(pTHX_ OP **out, XSParseKeywordPiece *args[], |
| 860 |
|
| size_t nargs, void *hookdata) |
| 861 |
|
| { |
| 862 |
|
| PERL_UNUSED_ARG(nargs); |
| 863 |
|
| PERL_UNUSED_ARG(hookdata); |
| 864 |
|
| |
| 865 |
93 |
| OP *data_op = args[0]->op; |
| 866 |
93 |
| OP *path_op = args[1]->op; |
| 867 |
93 |
| OP *value_op = args[2]->op; |
| 868 |
|
| |
| 869 |
|
| /* Check if path is a compile-time constant string */ |
| 870 |
93 |
▶ | if (path_op->op_type == OP_CONST && |
Branch: 1 branch
| Branch | True | False | Total |
| if (path_op->op_type == OP_CONST && |
51 |
42 |
93 |
|
| 871 |
51 |
▶ | (path_op->op_private & OPpCONST_BARE) == 0) |
Branch: 1 branch
| Branch | True | False | Total |
| (path_op->op_private & OPpCONST_BARE) == 0) |
51 |
0 |
51 |
|
| 872 |
|
| { |
| 873 |
51 |
| SV *path_sv = cSVOPx(path_op)->op_sv; |
| 874 |
51 |
▶ | if (SvPOK(path_sv) && !SvUTF8(path_sv)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (SvPOK(path_sv) && !SvUTF8(path_sv)) { |
51 |
0 |
51 |
| if (SvPOK(path_sv) && !SvUTF8(path_sv)) { |
49 |
2 |
51 |
|
| 875 |
|
| STRLEN path_len; |
| 876 |
49 |
| const char *path = SvPV(path_sv, path_len); |
| 877 |
49 |
| const char *path_end = path + path_len; |
| 878 |
|
| |
| 879 |
|
| /* Validate: non-empty path with at least one component */ |
| 880 |
49 |
| const char *p = path; |
| 881 |
98 |
▶ | while (p < path_end && *p == '/') p++; |
Branch: 2 branches
| Branch | True | False | Total |
| while (p < path_end && *p == '/') p++; |
95 |
3 |
98 |
| while (p < path_end && *p == '/') p++; |
49 |
46 |
95 |
|
| 882 |
49 |
▶ | if (p >= path_end) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (p >= path_end) { |
3 |
46 |
49 |
|
| 883 |
3 |
| croak("Cannot set root"); |
| 884 |
|
| } |
| 885 |
|
| |
| 886 |
|
| /* Scan for numeric components. The const-path optimization compiles |
| 887 |
|
| * to native HELEM/AELEM ops, which forces a fixed hash-vs-array |
| 888 |
|
| * choice per component. Numeric-looking components would force AELEM, |
| 889 |
|
| * but the actual parent at runtime might be a hash with stringy |
| 890 |
|
| * numeric keys (path_set treats those as hash keys). Fall through |
| 891 |
|
| * to the dynamic op for consistent semantics in that case. */ |
| 892 |
46 |
| int has_numeric = 0; |
| 893 |
46 |
| const char *q = p; |
| 894 |
126 |
▶ | while (q < path_end) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (q < path_end) { |
103 |
23 |
126 |
|
| 895 |
103 |
| const char *tok = q; |
| 896 |
426 |
▶ | while (q < path_end && *q != '/') q++; |
Branch: 2 branches
| Branch | True | False | Total |
| while (q < path_end && *q != '/') q++; |
399 |
27 |
426 |
| while (q < path_end && *q != '/') q++; |
323 |
76 |
399 |
|
| 897 |
103 |
| STRLEN tok_len = q - tok; |
| 898 |
|
| IV dummy; |
| 899 |
103 |
▶ | if (tok_len > 0 && is_array_index(tok, tok_len, &dummy)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (tok_len > 0 && is_array_index(tok, tok_len, &dummy)) { |
101 |
2 |
103 |
| if (tok_len > 0 && is_array_index(tok, tok_len, &dummy)) { |
23 |
78 |
101 |
|
| 900 |
23 |
| has_numeric = 1; |
| 901 |
23 |
| break; |
| 902 |
|
| } |
| 903 |
80 |
▶ | if (q < path_end) q++; |
Branch: 1 branch
| Branch | True | False | Total |
| if (q < path_end) q++; |
58 |
22 |
80 |
|
| 904 |
|
| } |
| 905 |
|
| |
| 906 |
46 |
▶ | if (!has_numeric) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!has_numeric) { |
23 |
23 |
46 |
|
| 907 |
|
| /* All components are string keys: build $data->{a}{b}{c} = $value */ |
| 908 |
23 |
| OP *lvalue = kw_build_deref_chain_lvalue(aTHX_ data_op, path, path_len); |
| 909 |
|
| |
| 910 |
|
| /* Mark as lvalue for proper autovivification */ |
| 911 |
23 |
| lvalue = op_lvalue(lvalue, OP_SASSIGN); |
| 912 |
|
| |
| 913 |
23 |
| *out = newBINOP(OP_SASSIGN, 0, value_op, lvalue); |
| 914 |
|
| |
| 915 |
|
| /* Free the constant path op */ |
| 916 |
23 |
| op_free(path_op); |
| 917 |
|
| |
| 918 |
23 |
| return KEYWORD_PLUGIN_EXPR; |
| 919 |
|
| } |
| 920 |
|
| /* fallthrough to dynamic op for paths with numeric components */ |
| 921 |
|
| } |
| 922 |
|
| } |
| 923 |
|
| |
| 924 |
|
| /* Dynamic path - use custom op */ |
| 925 |
67 |
| *out = kw_build_dynamic_pathset(aTHX_ data_op, path_op, value_op); |
| 926 |
67 |
| return KEYWORD_PLUGIN_EXPR; |
| 927 |
|
| } |
| 928 |
|
| |
| 929 |
|
| /* Keyword hooks structure for pathset */ |
| 930 |
|
| static const struct XSParseKeywordHooks hooks_pathset = { |
| 931 |
|
| .permit_hintkey = "Data::Path::XS/pathset", |
| 932 |
|
| .pieces = (const struct XSParseKeywordPieceType []) { |
| 933 |
|
| XPK_TERMEXPR_SCALARCTX, /* data structure */ |
| 934 |
|
| XPK_COMMA, /* , */ |
| 935 |
|
| XPK_TERMEXPR_SCALARCTX, /* path */ |
| 936 |
|
| XPK_COMMA, /* , */ |
| 937 |
|
| XPK_TERMEXPR_SCALARCTX, /* value */ |
| 938 |
|
| {0} |
| 939 |
|
| }, |
| 940 |
|
| .build = &build_kw_pathset, |
| 941 |
|
| }; |
| 942 |
|
| |
| 943 |
|
| /* The build callback for 'pathdelete' keyword */ |
| 944 |
36 |
| static int build_kw_pathdelete(pTHX_ OP **out, XSParseKeywordPiece *args[], |
| 945 |
|
| size_t nargs, void *hookdata) |
| 946 |
|
| { |
| 947 |
|
| PERL_UNUSED_ARG(nargs); |
| 948 |
|
| PERL_UNUSED_ARG(hookdata); |
| 949 |
|
| |
| 950 |
36 |
| OP *data_op = args[0]->op; |
| 951 |
36 |
| OP *path_op = args[1]->op; |
| 952 |
|
| |
| 953 |
|
| /* Always use custom op to avoid autovivification of intermediate levels */ |
| 954 |
36 |
| *out = kw_make_binop(aTHX_ data_op, path_op, pp_pathdelete_dynamic); |
| 955 |
36 |
| return KEYWORD_PLUGIN_EXPR; |
| 956 |
|
| } |
| 957 |
|
| |
| 958 |
|
| /* Keyword hooks structure for pathdelete */ |
| 959 |
|
| static const struct XSParseKeywordHooks hooks_pathdelete = { |
| 960 |
|
| .permit_hintkey = "Data::Path::XS/pathdelete", |
| 961 |
|
| .pieces = (const struct XSParseKeywordPieceType []) { |
| 962 |
|
| XPK_TERMEXPR_SCALARCTX, /* data structure */ |
| 963 |
|
| XPK_COMMA, /* , */ |
| 964 |
|
| XPK_TERMEXPR_SCALARCTX, /* path */ |
| 965 |
|
| {0} |
| 966 |
|
| }, |
| 967 |
|
| .build = &build_kw_pathdelete, |
| 968 |
|
| }; |
| 969 |
|
| |
| 970 |
|
| /* The build callback for 'pathexists' keyword */ |
| 971 |
43 |
| static int build_kw_pathexists(pTHX_ OP **out, XSParseKeywordPiece *args[], |
| 972 |
|
| size_t nargs, void *hookdata) |
| 973 |
|
| { |
| 974 |
|
| PERL_UNUSED_ARG(nargs); |
| 975 |
|
| PERL_UNUSED_ARG(hookdata); |
| 976 |
|
| |
| 977 |
43 |
| OP *data_op = args[0]->op; |
| 978 |
43 |
| OP *path_op = args[1]->op; |
| 979 |
|
| |
| 980 |
|
| /* Always use custom op to avoid autovivification of intermediate levels */ |
| 981 |
43 |
| *out = kw_make_binop(aTHX_ data_op, path_op, pp_pathexists_dynamic); |
| 982 |
43 |
| return KEYWORD_PLUGIN_EXPR; |
| 983 |
|
| } |
| 984 |
|
| |
| 985 |
|
| /* Keyword hooks structure for pathexists */ |
| 986 |
|
| static const struct XSParseKeywordHooks hooks_pathexists = { |
| 987 |
|
| .permit_hintkey = "Data::Path::XS/pathexists", |
| 988 |
|
| .pieces = (const struct XSParseKeywordPieceType []) { |
| 989 |
|
| XPK_TERMEXPR_SCALARCTX, /* data structure */ |
| 990 |
|
| XPK_COMMA, /* , */ |
| 991 |
|
| XPK_TERMEXPR_SCALARCTX, /* path */ |
| 992 |
|
| {0} |
| 993 |
|
| }, |
| 994 |
|
| .build = &build_kw_pathexists, |
| 995 |
|
| }; |
| 996 |
|
| |
| 997 |
|
| /* ========== END KEYWORD SUPPORT ========== */ |
| 998 |
|
| |
| 999 |
|
| MODULE = Data::Path::XS PACKAGE = Data::Path::XS |
| 1000 |
|
| |
| 1001 |
|
| PROTOTYPES: DISABLE |
| 1002 |
|
| |
| 1003 |
|
| SV* |
| 1004 |
|
| path_get(data, path) |
| 1005 |
|
| SV *data |
| 1006 |
|
| SV *path |
| 1007 |
|
| CODE: |
| 1008 |
|
| STRLEN path_len; |
| 1009 |
44295 |
| const char *path_str = SvPV(path, path_len); |
| 1010 |
|
| const char *final_key; |
| 1011 |
|
| STRLEN final_key_len; |
| 1012 |
44295 |
▶ | const I32 utf8_flag = SvUTF8(path) ? -1 : 1; |
Branch: 1 branch
| Branch | True | False | Total |
| const I32 utf8_flag = SvUTF8(path) ? -1 : 1; |
4 |
44291 |
44295 |
|
| 1013 |
|
| |
| 1014 |
44295 |
▶ | if (path_len == 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (path_len == 0) { |
4 |
44291 |
44295 |
|
| 1015 |
4 |
| RETVAL = SvREFCNT_inc(data); |
| 1016 |
|
| } else { |
| 1017 |
44291 |
| SV *parent = navigate_to_parent(aTHX_ data, path_str, path_len, &final_key, &final_key_len, 0, utf8_flag); |
| 1018 |
|
| |
| 1019 |
|
| /* final_key == NULL means path refers to root (e.g., "/" or "///") */ |
| 1020 |
44291 |
▶ | if (!final_key) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!final_key) { |
4005 |
40286 |
44291 |
|
| 1021 |
4005 |
▶ | RETVAL = parent ? SvREFCNT_inc(parent) : &PL_sv_undef; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = parent ? SvREFCNT_inc(parent) : &PL_sv_undef; |
1 |
4004 |
4005 |
|
| 1022 |
40286 |
▶ | } else if (!parent || !SvROK(parent)) { |
Branch: 2 branches
| Branch | True | False | Total |
| } else if (!parent || !SvROK(parent)) { |
40286 |
0 |
40286 |
| } else if (!parent || !SvROK(parent)) { |
0 |
40286 |
40286 |
|
| 1023 |
0 |
| RETVAL = &PL_sv_undef; |
| 1024 |
|
| } else { |
| 1025 |
40286 |
| SV *inner = SvRV(parent); |
| 1026 |
40286 |
| svtype t = SvTYPE(inner); |
| 1027 |
|
| |
| 1028 |
40286 |
▶ | if (t == SVt_PVHV) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (t == SVt_PVHV) { |
20260 |
20026 |
40286 |
|
| 1029 |
20260 |
| SV *val = path_fetch(aTHX_ hv_fetch((HV*)inner, final_key, (I32)final_key_len * utf8_flag, 0)); |
| 1030 |
20260 |
▶ | RETVAL = val ? SvREFCNT_inc(val) : &PL_sv_undef; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = val ? SvREFCNT_inc(val) : &PL_sv_undef; |
18255 |
2005 |
20260 |
|
| 1031 |
20026 |
▶ | } else if (t == SVt_PVAV) { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if (t == SVt_PVAV) { |
20025 |
1 |
20026 |
|
| 1032 |
|
| IV idx; |
| 1033 |
20025 |
▶ | if (is_array_index(final_key, final_key_len, &idx)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (is_array_index(final_key, final_key_len, &idx)) { |
20021 |
4 |
20025 |
|
| 1034 |
20021 |
| SV *val = path_fetch(aTHX_ av_fetch((AV*)inner, idx, 0)); |
| 1035 |
20021 |
▶ | RETVAL = val ? SvREFCNT_inc(val) : &PL_sv_undef; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = val ? SvREFCNT_inc(val) : &PL_sv_undef; |
20018 |
3 |
20021 |
|
| 1036 |
|
| } else { |
| 1037 |
4 |
| RETVAL = &PL_sv_undef; |
| 1038 |
|
| } |
| 1039 |
|
| } else { |
| 1040 |
1 |
| RETVAL = &PL_sv_undef; |
| 1041 |
|
| } |
| 1042 |
|
| } |
| 1043 |
|
| } |
| 1044 |
|
| OUTPUT: |
| 1045 |
|
| RETVAL |
| 1046 |
|
| |
| 1047 |
|
| SV* |
| 1048 |
|
| path_set(data, path, value) |
| 1049 |
|
| SV *data |
| 1050 |
|
| SV *path |
| 1051 |
|
| SV *value |
| 1052 |
|
| PPCODE: |
| 1053 |
40783 |
| PUTBACK; |
| 1054 |
40783 |
| value = path_source(aTHX_ value); |
| 1055 |
|
| SV *stored; |
| 1056 |
|
| STRLEN path_len; |
| 1057 |
40783 |
| const char *path_str = SvPV(path, path_len); |
| 1058 |
|
| const char *final_key; |
| 1059 |
|
| STRLEN final_key_len; |
| 1060 |
40783 |
▶ | const I32 utf8_flag = SvUTF8(path) ? -1 : 1; |
Branch: 1 branch
| Branch | True | False | Total |
| const I32 utf8_flag = SvUTF8(path) ? -1 : 1; |
3 |
40780 |
40783 |
|
| 1061 |
|
| |
| 1062 |
40783 |
▶ | if (path_len == 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (path_len == 0) { |
2002 |
38781 |
40783 |
|
| 1063 |
2002 |
| croak("Cannot set root"); |
| 1064 |
|
| } |
| 1065 |
|
| |
| 1066 |
38781 |
| SV *parent = navigate_to_parent(aTHX_ data, path_str, path_len, &final_key, &final_key_len, 1, utf8_flag); |
| 1067 |
|
| |
| 1068 |
|
| /* final_key == NULL with parent means path refers to root - can't set |
| 1069 |
|
| * final_key == NULL without parent means navigation failed */ |
| 1070 |
38778 |
▶ | if (!final_key) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!final_key) { |
2 |
38776 |
38778 |
|
| 1071 |
2 |
▶ | croak(parent ? "Cannot set root" : "Cannot navigate to path"); |
Branch: 1 branch
| Branch | True | False | Total |
| croak(parent ? "Cannot set root" : "Cannot navigate to path"); |
1 |
1 |
2 |
|
| 1072 |
|
| } |
| 1073 |
38776 |
▶ | if (!parent || !SvROK(parent)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (!parent || !SvROK(parent)) { |
38776 |
0 |
38776 |
| if (!parent || !SvROK(parent)) { |
1 |
38775 |
38776 |
|
| 1074 |
1 |
| croak("Cannot navigate to path"); |
| 1075 |
|
| } |
| 1076 |
|
| |
| 1077 |
38775 |
| SV *inner = SvRV(parent); |
| 1078 |
38775 |
| svtype t = SvTYPE(inner); |
| 1079 |
|
| |
| 1080 |
38775 |
▶ | if (t == SVt_PVHV) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (t == SVt_PVHV) { |
18753 |
20022 |
38775 |
|
| 1081 |
18753 |
| stored = path_store_hash(aTHX_ (HV*)inner, final_key, (I32)final_key_len * utf8_flag, 0, value, "path_set"); |
| 1082 |
20022 |
▶ | } else if (t == SVt_PVAV) { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if (t == SVt_PVAV) { |
20022 |
0 |
20022 |
|
| 1083 |
|
| IV idx; |
| 1084 |
20022 |
▶ | if (!is_array_index(final_key, final_key_len, &idx)) croak("Invalid array index"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!is_array_index(final_key, final_key_len, &idx)) croak("Invalid array index"); |
2 |
20020 |
20022 |
|
| 1085 |
20020 |
| stored = path_store_array(aTHX_ (AV*)inner, idx, value, "path_set"); |
| 1086 |
|
| } else { |
| 1087 |
0 |
| croak("Parent is not a hash or array"); |
| 1088 |
|
| } |
| 1089 |
|
| |
| 1090 |
38763 |
| SPAGAIN; |
| 1091 |
38763 |
▶ | if (GIMME_V != G_VOID) |
Branch: 1 branch
| Branch | True | False | Total |
| if (GIMME_V != G_VOID) |
8 |
38755 |
38763 |
|
| 1092 |
8 |
▶ | XPUSHs(sv_2mortal(SvREFCNT_inc(stored))); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(sv_2mortal(SvREFCNT_inc(stored))); |
0 |
8 |
8 |
|
| 1093 |
|
| |
| 1094 |
|
| SV* |
| 1095 |
|
| path_delete(data, path) |
| 1096 |
|
| SV *data |
| 1097 |
|
| SV *path |
| 1098 |
|
| CODE: |
| 1099 |
|
| STRLEN path_len; |
| 1100 |
26228 |
| const char *path_str = SvPV(path, path_len); |
| 1101 |
|
| const char *final_key; |
| 1102 |
|
| STRLEN final_key_len; |
| 1103 |
26228 |
▶ | const I32 utf8_flag = SvUTF8(path) ? -1 : 1; |
Branch: 1 branch
| Branch | True | False | Total |
| const I32 utf8_flag = SvUTF8(path) ? -1 : 1; |
1 |
26227 |
26228 |
|
| 1104 |
|
| |
| 1105 |
26228 |
▶ | if (path_len == 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (path_len == 0) { |
2002 |
24226 |
26228 |
|
| 1106 |
2002 |
| croak("Cannot delete root"); |
| 1107 |
|
| } |
| 1108 |
|
| |
| 1109 |
24226 |
| SV *parent = navigate_to_parent(aTHX_ data, path_str, path_len, &final_key, &final_key_len, 0, utf8_flag); |
| 1110 |
|
| |
| 1111 |
|
| /* final_key == NULL with parent means path refers to root - can't delete |
| 1112 |
|
| * final_key == NULL without parent means navigation failed - return undef */ |
| 1113 |
24226 |
▶ | if (!final_key) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!final_key) { |
2003 |
22223 |
24226 |
|
| 1114 |
2003 |
▶ | if (parent) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (parent) { |
1 |
2002 |
2003 |
|
| 1115 |
1 |
| croak("Cannot delete root"); |
| 1116 |
|
| } |
| 1117 |
2002 |
| RETVAL = &PL_sv_undef; |
| 1118 |
22223 |
▶ | } else if (!parent || !SvROK(parent)) { |
Branch: 2 branches
| Branch | True | False | Total |
| } else if (!parent || !SvROK(parent)) { |
22223 |
0 |
22223 |
| } else if (!parent || !SvROK(parent)) { |
0 |
22223 |
22223 |
|
| 1119 |
0 |
| RETVAL = &PL_sv_undef; |
| 1120 |
|
| } else { |
| 1121 |
22223 |
| SV *inner = SvRV(parent); |
| 1122 |
22223 |
| svtype t = SvTYPE(inner); |
| 1123 |
|
| |
| 1124 |
22223 |
▶ | if (t == SVt_PVHV) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (t == SVt_PVHV) { |
22216 |
7 |
22223 |
|
| 1125 |
22216 |
| RETVAL = hv_delete((HV*)inner, final_key, (I32)final_key_len * utf8_flag, 0); |
| 1126 |
22216 |
▶ | if (RETVAL) SvREFCNT_inc(RETVAL); |
Branch: 1 branch
| Branch | True | False | Total |
| if (RETVAL) SvREFCNT_inc(RETVAL); |
22212 |
4 |
22216 |
|
| 1127 |
4 |
| else RETVAL = &PL_sv_undef; |
| 1128 |
7 |
▶ | } else if (t == SVt_PVAV) { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if (t == SVt_PVAV) { |
7 |
0 |
7 |
|
| 1129 |
|
| IV idx; |
| 1130 |
7 |
▶ | if (is_array_index(final_key, final_key_len, &idx)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (is_array_index(final_key, final_key_len, &idx)) { |
7 |
0 |
7 |
|
| 1131 |
7 |
| SV *old = av_delete((AV*)inner, idx, 0); |
| 1132 |
7 |
▶ | RETVAL = old ? SvREFCNT_inc(old) : &PL_sv_undef; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = old ? SvREFCNT_inc(old) : &PL_sv_undef; |
6 |
1 |
7 |
|
| 1133 |
|
| } else { |
| 1134 |
0 |
| RETVAL = &PL_sv_undef; |
| 1135 |
|
| } |
| 1136 |
|
| } else { |
| 1137 |
0 |
| RETVAL = &PL_sv_undef; |
| 1138 |
|
| } |
| 1139 |
|
| } |
| 1140 |
|
| OUTPUT: |
| 1141 |
|
| RETVAL |
| 1142 |
|
| |
| 1143 |
|
| int |
| 1144 |
|
| path_exists(data, path) |
| 1145 |
|
| SV *data |
| 1146 |
|
| SV *path |
| 1147 |
|
| CODE: |
| 1148 |
|
| STRLEN path_len; |
| 1149 |
2243 |
| const char *path_str = SvPV(path, path_len); |
| 1150 |
|
| const char *final_key; |
| 1151 |
|
| STRLEN final_key_len; |
| 1152 |
2243 |
▶ | const I32 utf8_flag = SvUTF8(path) ? -1 : 1; |
Branch: 1 branch
| Branch | True | False | Total |
| const I32 utf8_flag = SvUTF8(path) ? -1 : 1; |
2 |
2241 |
2243 |
|
| 1153 |
|
| |
| 1154 |
2243 |
▶ | if (path_len == 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (path_len == 0) { |
4 |
2239 |
2243 |
|
| 1155 |
4 |
| RETVAL = 1; |
| 1156 |
|
| } else { |
| 1157 |
2239 |
| SV *parent = navigate_to_parent(aTHX_ data, path_str, path_len, &final_key, &final_key_len, 0, utf8_flag); |
| 1158 |
|
| |
| 1159 |
|
| /* final_key == NULL with parent means path refers to root (e.g., "/" or "///") - always exists |
| 1160 |
|
| * final_key == NULL without parent means navigation failed (e.g., traverse non-ref) */ |
| 1161 |
2239 |
▶ | if (!final_key) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!final_key) { |
2002 |
237 |
2239 |
|
| 1162 |
2002 |
| RETVAL = parent ? 1 : 0; |
| 1163 |
237 |
▶ | } else if (!parent || !SvROK(parent)) { |
Branch: 2 branches
| Branch | True | False | Total |
| } else if (!parent || !SvROK(parent)) { |
237 |
0 |
237 |
| } else if (!parent || !SvROK(parent)) { |
0 |
237 |
237 |
|
| 1164 |
0 |
| RETVAL = 0; |
| 1165 |
|
| } else { |
| 1166 |
237 |
| SV *inner = SvRV(parent); |
| 1167 |
237 |
| svtype t = SvTYPE(inner); |
| 1168 |
|
| |
| 1169 |
237 |
▶ | if (t == SVt_PVHV) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (t == SVt_PVHV) { |
228 |
9 |
237 |
|
| 1170 |
228 |
| RETVAL = hv_exists((HV*)inner, final_key, (I32)final_key_len * utf8_flag); |
| 1171 |
9 |
▶ | } else if (t == SVt_PVAV) { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if (t == SVt_PVAV) { |
9 |
0 |
9 |
|
| 1172 |
|
| IV idx; |
| 1173 |
18 |
| RETVAL = is_array_index(final_key, final_key_len, &idx) |
| 1174 |
9 |
▶ | ? av_exists((AV*)inner, idx) : 0; |
Branch: 1 branch
| Branch | True | False | Total |
| ? av_exists((AV*)inner, idx) : 0; |
9 |
0 |
9 |
|
| 1175 |
|
| } else { |
| 1176 |
0 |
| RETVAL = 0; |
| 1177 |
|
| } |
| 1178 |
|
| } |
| 1179 |
|
| } |
| 1180 |
|
| OUTPUT: |
| 1181 |
|
| RETVAL |
| 1182 |
|
| |
| 1183 |
|
| SV* |
| 1184 |
|
| patha_get(data, path_av) |
| 1185 |
|
| SV *data |
| 1186 |
|
| AV *path_av |
| 1187 |
|
| CODE: |
| 1188 |
4076 |
| SSize_t len = av_len(path_av) + 1; |
| 1189 |
4076 |
| SV *current = path_value(aTHX_ data); |
| 1190 |
|
| |
| 1191 |
20197 |
▶ | for (SSize_t i = 0; i < len; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (SSize_t i = 0; i < len; i++) { |
16133 |
4064 |
20197 |
|
| 1192 |
16133 |
| SV **key_ptr = av_fetch(path_av, i, 0); |
| 1193 |
16133 |
▶ | if (UNLIKELY(!key_ptr || !*key_ptr || !SvROK(current))) { |
Branch: 4 branches
| Branch | True | False | Total |
| if (UNLIKELY(!key_ptr || !*key_ptr || !SvROK(current))) { |
16133 |
0 |
16133 |
| if (UNLIKELY(!key_ptr || !*key_ptr || !SvROK(current))) { |
0 |
16133 |
16133 |
| if (UNLIKELY(!key_ptr || !*key_ptr || !SvROK(current))) { |
16133 |
0 |
16133 |
| if (UNLIKELY(!key_ptr || !*key_ptr || !SvROK(current))) { |
1 |
16132 |
16133 |
|
| 1194 |
1 |
| RETVAL = &PL_sv_undef; |
| 1195 |
1 |
| goto done; |
| 1196 |
|
| } |
| 1197 |
|
| |
| 1198 |
16132 |
| SV *inner = SvRV(current); |
| 1199 |
16132 |
| svtype t = SvTYPE(inner); |
| 1200 |
|
| |
| 1201 |
16132 |
▶ | if (LIKELY(t == SVt_PVHV)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (LIKELY(t == SVt_PVHV)) { |
16088 |
44 |
16132 |
|
| 1202 |
|
| const char *kstr; |
| 1203 |
16088 |
| I32 sklen = sv_to_klen(aTHX_ *key_ptr, &kstr); |
| 1204 |
16088 |
| SV *val = path_fetch(aTHX_ hv_fetch((HV*)inner, kstr, sklen, 0)); |
| 1205 |
16088 |
▶ | if (UNLIKELY(!val)) { RETVAL = &PL_sv_undef; goto done; } |
Branch: 1 branch
| Branch | True | False | Total |
| if (UNLIKELY(!val)) { RETVAL = &PL_sv_undef; goto done; } |
5 |
16083 |
16088 |
|
| 1206 |
16083 |
| current = val; |
| 1207 |
44 |
▶ | } else if (t == SVt_PVAV) { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if (t == SVt_PVAV) { |
44 |
0 |
44 |
|
| 1208 |
|
| IV idx; |
| 1209 |
46 |
▶ | if (UNLIKELY(!sv_to_index(aTHX_ *key_ptr, &idx))) { RETVAL = &PL_sv_undef; goto done; } |
Branch: 1 branch
| Branch | True | False | Total |
| if (UNLIKELY(!sv_to_index(aTHX_ *key_ptr, &idx))) { RETVAL = &PL_sv_undef; goto done; } |
4 |
40 |
44 |
|
| 1210 |
40 |
| SV *val = path_fetch(aTHX_ av_fetch((AV*)inner, idx, 0)); |
| 1211 |
40 |
▶ | if (UNLIKELY(!val)) { RETVAL = &PL_sv_undef; goto done; } |
Branch: 1 branch
| Branch | True | False | Total |
| if (UNLIKELY(!val)) { RETVAL = &PL_sv_undef; goto done; } |
2 |
38 |
40 |
|
| 1212 |
38 |
| current = val; |
| 1213 |
|
| } else { |
| 1214 |
0 |
| RETVAL = &PL_sv_undef; |
| 1215 |
0 |
| goto done; |
| 1216 |
|
| } |
| 1217 |
|
| } |
| 1218 |
4064 |
| RETVAL = SvREFCNT_inc(current); |
| 1219 |
4076 |
| done: |
| 1220 |
|
| OUTPUT: |
| 1221 |
|
| RETVAL |
| 1222 |
|
| |
| 1223 |
|
| SV* |
| 1224 |
|
| patha_set(data, path_av, value) |
| 1225 |
|
| SV *data |
| 1226 |
|
| AV *path_av |
| 1227 |
|
| SV *value |
| 1228 |
|
| PPCODE: |
| 1229 |
4060 |
| PUTBACK; |
| 1230 |
4060 |
| value = path_source(aTHX_ value); |
| 1231 |
|
| SV *stored; |
| 1232 |
4060 |
| SSize_t len = av_len(path_av) + 1; |
| 1233 |
4060 |
| SV *current = path_value(aTHX_ data); |
| 1234 |
|
| |
| 1235 |
4060 |
▶ | if (UNLIKELY(len == 0)) croak("Cannot set root"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (UNLIKELY(len == 0)) croak("Cannot set root"); |
3 |
4057 |
4060 |
|
| 1236 |
|
| |
| 1237 |
12095 |
▶ | for (SSize_t i = 0; i < len - 1; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (SSize_t i = 0; i < len - 1; i++) { |
8041 |
4054 |
12095 |
|
| 1238 |
8041 |
| SV **key_ptr = av_fetch(path_av, i, 0); |
| 1239 |
8041 |
▶ | if (UNLIKELY(!key_ptr || !*key_ptr)) croak("Invalid path element"); |
Branch: 2 branches
| Branch | True | False | Total |
| if (UNLIKELY(!key_ptr || !*key_ptr)) croak("Invalid path element"); |
8041 |
0 |
8041 |
| if (UNLIKELY(!key_ptr || !*key_ptr)) croak("Invalid path element"); |
0 |
8041 |
8041 |
|
| 1240 |
8041 |
▶ | if (UNLIKELY(!SvROK(current))) croak("Cannot navigate to path"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (UNLIKELY(!SvROK(current))) croak("Cannot navigate to path"); |
0 |
8041 |
8041 |
|
| 1241 |
|
| |
| 1242 |
8041 |
| SV *inner = SvRV(current); |
| 1243 |
8041 |
| svtype t = SvTYPE(inner); |
| 1244 |
|
| |
| 1245 |
8041 |
▶ | if (LIKELY(t == SVt_PVHV)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (LIKELY(t == SVt_PVHV)) { |
8035 |
6 |
8041 |
|
| 1246 |
|
| const char *kstr; |
| 1247 |
8035 |
| I32 sklen = sv_to_klen(aTHX_ *key_ptr, &kstr); |
| 1248 |
8035 |
| SV *val = path_fetch(aTHX_ hv_fetch((HV*)inner, kstr, sklen, 0)); |
| 1249 |
8033 |
▶ | if (UNLIKELY(!val || !SvROK(val))) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (UNLIKELY(!val || !SvROK(val))) { |
4018 |
4015 |
8033 |
| if (UNLIKELY(!val || !SvROK(val))) { |
3 |
4015 |
4018 |
|
| 1250 |
4018 |
| SV **next_key = av_fetch(path_av, i + 1, 0); |
| 1251 |
|
| IV dummy; |
| 1252 |
4018 |
▶ | SV *new_ref = sv_2mortal((next_key && *next_key && sv_to_index(aTHX_ *next_key, &dummy)) |
Branch: 3 branches
| Branch | True | False | Total |
| SV *new_ref = sv_2mortal((next_key && *next_key && sv_to_index(aTHX_ *next_key, &dummy)) |
4018 |
0 |
4018 |
| SV *new_ref = sv_2mortal((next_key && *next_key && sv_to_index(aTHX_ *next_key, &dummy)) |
4018 |
0 |
4018 |
| SV *new_ref = sv_2mortal((next_key && *next_key && sv_to_index(aTHX_ *next_key, &dummy)) |
5 |
4013 |
4018 |
|
| 1253 |
|
| ? newRV_noinc((SV*)newAV()) |
| 1254 |
|
| : newRV_noinc((SV*)newHV())); |
| 1255 |
4018 |
▶ | if (UNLIKELY(!hv_store((HV*)inner, kstr, sklen, new_ref, 0))) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (UNLIKELY(!hv_store((HV*)inner, kstr, sklen, new_ref, 0))) { |
0 |
4018 |
4018 |
|
| 1256 |
0 |
▶ | croak(SvRMAGICAL(inner) |
Branch: 1 branch
| Branch | True | False | Total |
| croak(SvRMAGICAL(inner) |
0 |
0 |
0 |
|
| 1257 |
|
| ? "Cannot patha_set on tied/magical hash" |
| 1258 |
|
| : "Failed to store intermediate value"); |
| 1259 |
|
| } |
| 1260 |
4018 |
| SvREFCNT_inc_simple_void_NN(new_ref); |
| 1261 |
4018 |
| current = new_ref; |
| 1262 |
|
| } else { |
| 1263 |
4015 |
| current = val; |
| 1264 |
|
| } |
| 1265 |
6 |
▶ | } else if (t == SVt_PVAV) { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if (t == SVt_PVAV) { |
6 |
0 |
6 |
|
| 1266 |
|
| IV idx; |
| 1267 |
6 |
▶ | if (UNLIKELY(!sv_to_index(aTHX_ *key_ptr, &idx))) croak("Invalid array index"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (UNLIKELY(!sv_to_index(aTHX_ *key_ptr, &idx))) croak("Invalid array index"); |
0 |
6 |
6 |
|
| 1268 |
6 |
| SV *val = path_fetch(aTHX_ av_fetch((AV*)inner, idx, 0)); |
| 1269 |
6 |
▶ | if (UNLIKELY(!val || !SvROK(val))) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (UNLIKELY(!val || !SvROK(val))) { |
2 |
4 |
6 |
| if (UNLIKELY(!val || !SvROK(val))) { |
1 |
1 |
2 |
|
| 1270 |
5 |
| SV **next_key = av_fetch(path_av, i + 1, 0); |
| 1271 |
|
| IV dummy; |
| 1272 |
5 |
▶ | SV *new_ref = sv_2mortal((next_key && *next_key && sv_to_index(aTHX_ *next_key, &dummy)) |
Branch: 3 branches
| Branch | True | False | Total |
| SV *new_ref = sv_2mortal((next_key && *next_key && sv_to_index(aTHX_ *next_key, &dummy)) |
5 |
0 |
5 |
| SV *new_ref = sv_2mortal((next_key && *next_key && sv_to_index(aTHX_ *next_key, &dummy)) |
5 |
0 |
5 |
| SV *new_ref = sv_2mortal((next_key && *next_key && sv_to_index(aTHX_ *next_key, &dummy)) |
1 |
4 |
5 |
|
| 1273 |
|
| ? newRV_noinc((SV*)newAV()) |
| 1274 |
|
| : newRV_noinc((SV*)newHV())); |
| 1275 |
5 |
▶ | if (UNLIKELY(!av_store((AV*)inner, idx, new_ref))) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (UNLIKELY(!av_store((AV*)inner, idx, new_ref))) { |
1 |
4 |
5 |
|
| 1276 |
1 |
▶ | croak(SvRMAGICAL(inner) |
Branch: 1 branch
| Branch | True | False | Total |
| croak(SvRMAGICAL(inner) |
1 |
0 |
1 |
|
| 1277 |
|
| ? "Cannot patha_set on tied/magical array" |
| 1278 |
|
| : "Failed to store intermediate value"); |
| 1279 |
|
| } |
| 1280 |
4 |
| SvREFCNT_inc_simple_void_NN(new_ref); |
| 1281 |
4 |
| current = new_ref; |
| 1282 |
|
| } else { |
| 1283 |
1 |
| current = val; |
| 1284 |
|
| } |
| 1285 |
|
| } else { |
| 1286 |
0 |
| croak("Cannot navigate to path"); |
| 1287 |
|
| } |
| 1288 |
|
| } |
| 1289 |
|
| |
| 1290 |
4054 |
▶ | if (UNLIKELY(!SvROK(current))) croak("Cannot set on non-reference"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (UNLIKELY(!SvROK(current))) croak("Cannot set on non-reference"); |
0 |
4054 |
4054 |
|
| 1291 |
4054 |
| SV *inner = SvRV(current); |
| 1292 |
4054 |
| svtype t = SvTYPE(inner); |
| 1293 |
4054 |
| SV **final_key_ptr = av_fetch(path_av, len - 1, 0); |
| 1294 |
4054 |
▶ | if (UNLIKELY(!final_key_ptr || !*final_key_ptr)) croak("Invalid final key"); |
Branch: 2 branches
| Branch | True | False | Total |
| if (UNLIKELY(!final_key_ptr || !*final_key_ptr)) croak("Invalid final key"); |
4054 |
0 |
4054 |
| if (UNLIKELY(!final_key_ptr || !*final_key_ptr)) croak("Invalid final key"); |
0 |
4054 |
4054 |
|
| 1295 |
|
| |
| 1296 |
4054 |
▶ | if (LIKELY(t == SVt_PVHV)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (LIKELY(t == SVt_PVHV)) { |
4034 |
20 |
4054 |
|
| 1297 |
|
| const char *kstr; |
| 1298 |
4034 |
| I32 sklen = sv_to_klen(aTHX_ *final_key_ptr, &kstr); |
| 1299 |
4034 |
| stored = path_store_hash(aTHX_ (HV*)inner, kstr, sklen, 0, value, "patha_set"); |
| 1300 |
20 |
▶ | } else if (t == SVt_PVAV) { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if (t == SVt_PVAV) { |
20 |
0 |
20 |
|
| 1301 |
|
| IV idx; |
| 1302 |
20 |
▶ | if (!sv_to_index(aTHX_ *final_key_ptr, &idx)) croak("Invalid array index"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!sv_to_index(aTHX_ *final_key_ptr, &idx)) croak("Invalid array index"); |
2 |
18 |
20 |
|
| 1303 |
18 |
| stored = path_store_array(aTHX_ (AV*)inner, idx, value, "patha_set"); |
| 1304 |
|
| } else { |
| 1305 |
0 |
| croak("Parent is not a hash or array"); |
| 1306 |
|
| } |
| 1307 |
|
| |
| 1308 |
4043 |
| SPAGAIN; |
| 1309 |
4043 |
▶ | if (GIMME_V != G_VOID) |
Branch: 1 branch
| Branch | True | False | Total |
| if (GIMME_V != G_VOID) |
8 |
4035 |
4043 |
|
| 1310 |
8 |
▶ | XPUSHs(sv_2mortal(SvREFCNT_inc(stored))); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(sv_2mortal(SvREFCNT_inc(stored))); |
0 |
8 |
8 |
|
| 1311 |
|
| |
| 1312 |
|
| int |
| 1313 |
|
| patha_exists(data, path_av) |
| 1314 |
|
| SV *data |
| 1315 |
|
| AV *path_av |
| 1316 |
|
| CODE: |
| 1317 |
31 |
| SSize_t len = av_len(path_av) + 1; |
| 1318 |
31 |
| SV *current = path_value(aTHX_ data); |
| 1319 |
|
| |
| 1320 |
31 |
▶ | if (UNLIKELY(len == 0)) { RETVAL = 1; goto done; } |
Branch: 1 branch
| Branch | True | False | Total |
| if (UNLIKELY(len == 0)) { RETVAL = 1; goto done; } |
2 |
29 |
31 |
|
| 1321 |
|
| |
| 1322 |
55 |
▶ | for (SSize_t i = 0; i < len - 1; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (SSize_t i = 0; i < len - 1; i++) { |
26 |
29 |
55 |
|
| 1323 |
26 |
| SV **key_ptr = av_fetch(path_av, i, 0); |
| 1324 |
26 |
▶ | if (UNLIKELY(!key_ptr || !*key_ptr || !SvROK(current))) { RETVAL = 0; goto done; } |
Branch: 4 branches
| Branch | True | False | Total |
| if (UNLIKELY(!key_ptr || !*key_ptr || !SvROK(current))) { RETVAL = 0; goto done; } |
26 |
0 |
26 |
| if (UNLIKELY(!key_ptr || !*key_ptr || !SvROK(current))) { RETVAL = 0; goto done; } |
0 |
26 |
26 |
| if (UNLIKELY(!key_ptr || !*key_ptr || !SvROK(current))) { RETVAL = 0; goto done; } |
26 |
0 |
26 |
| if (UNLIKELY(!key_ptr || !*key_ptr || !SvROK(current))) { RETVAL = 0; goto done; } |
0 |
26 |
26 |
|
| 1325 |
|
| |
| 1326 |
26 |
| SV *inner = SvRV(current); |
| 1327 |
26 |
| svtype t = SvTYPE(inner); |
| 1328 |
|
| |
| 1329 |
26 |
▶ | if (LIKELY(t == SVt_PVHV)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (LIKELY(t == SVt_PVHV)) { |
24 |
2 |
26 |
|
| 1330 |
|
| const char *kstr; |
| 1331 |
24 |
| I32 sklen = sv_to_klen(aTHX_ *key_ptr, &kstr); |
| 1332 |
24 |
| SV *val = path_fetch(aTHX_ hv_fetch((HV*)inner, kstr, sklen, 0)); |
| 1333 |
24 |
▶ | if (UNLIKELY(!val)) { RETVAL = 0; goto done; } |
Branch: 1 branch
| Branch | True | False | Total |
| if (UNLIKELY(!val)) { RETVAL = 0; goto done; } |
0 |
24 |
24 |
|
| 1334 |
24 |
| current = val; |
| 1335 |
2 |
▶ | } else if (t == SVt_PVAV) { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if (t == SVt_PVAV) { |
2 |
0 |
2 |
|
| 1336 |
|
| IV idx; |
| 1337 |
2 |
▶ | if (UNLIKELY(!sv_to_index(aTHX_ *key_ptr, &idx))) { RETVAL = 0; goto done; } |
Branch: 1 branch
| Branch | True | False | Total |
| if (UNLIKELY(!sv_to_index(aTHX_ *key_ptr, &idx))) { RETVAL = 0; goto done; } |
0 |
2 |
2 |
|
| 1338 |
2 |
| SV *val = path_fetch(aTHX_ av_fetch((AV*)inner, idx, 0)); |
| 1339 |
2 |
▶ | if (UNLIKELY(!val)) { RETVAL = 0; goto done; } |
Branch: 1 branch
| Branch | True | False | Total |
| if (UNLIKELY(!val)) { RETVAL = 0; goto done; } |
0 |
2 |
2 |
|
| 1340 |
2 |
| current = val; |
| 1341 |
|
| } else { |
| 1342 |
0 |
| RETVAL = 0; goto done; |
| 1343 |
|
| } |
| 1344 |
|
| } |
| 1345 |
|
| |
| 1346 |
29 |
▶ | if (UNLIKELY(!SvROK(current))) { RETVAL = 0; goto done; } |
Branch: 1 branch
| Branch | True | False | Total |
| if (UNLIKELY(!SvROK(current))) { RETVAL = 0; goto done; } |
0 |
29 |
29 |
|
| 1347 |
29 |
| SV *inner = SvRV(current); |
| 1348 |
29 |
| svtype t = SvTYPE(inner); |
| 1349 |
29 |
| SV **final_key_ptr = av_fetch(path_av, len - 1, 0); |
| 1350 |
29 |
▶ | if (UNLIKELY(!final_key_ptr || !*final_key_ptr)) { RETVAL = 0; goto done; } |
Branch: 2 branches
| Branch | True | False | Total |
| if (UNLIKELY(!final_key_ptr || !*final_key_ptr)) { RETVAL = 0; goto done; } |
29 |
0 |
29 |
| if (UNLIKELY(!final_key_ptr || !*final_key_ptr)) { RETVAL = 0; goto done; } |
0 |
29 |
29 |
|
| 1351 |
|
| |
| 1352 |
29 |
▶ | if (LIKELY(t == SVt_PVHV)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (LIKELY(t == SVt_PVHV)) { |
14 |
15 |
29 |
|
| 1353 |
|
| const char *kstr; |
| 1354 |
14 |
| I32 sklen = sv_to_klen(aTHX_ *final_key_ptr, &kstr); |
| 1355 |
14 |
| RETVAL = hv_exists((HV*)inner, kstr, sklen); |
| 1356 |
15 |
▶ | } else if (t == SVt_PVAV) { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if (t == SVt_PVAV) { |
15 |
0 |
15 |
|
| 1357 |
|
| IV idx; |
| 1358 |
15 |
▶ | RETVAL = sv_to_index(aTHX_ *final_key_ptr, &idx) ? av_exists((AV*)inner, idx) : 0; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = sv_to_index(aTHX_ *final_key_ptr, &idx) ? av_exists((AV*)inner, idx) : 0; |
14 |
1 |
15 |
|
| 1359 |
|
| } else { |
| 1360 |
0 |
| RETVAL = 0; |
| 1361 |
|
| } |
| 1362 |
31 |
▶ | done: |
Branch: 1 branch
| Branch | True | False | Total |
| done: |
2 |
29 |
31 |
|
| 1363 |
|
| OUTPUT: |
| 1364 |
|
| RETVAL |
| 1365 |
|
| |
| 1366 |
|
| SV* |
| 1367 |
|
| patha_delete(data, path_av) |
| 1368 |
|
| SV *data |
| 1369 |
|
| AV *path_av |
| 1370 |
|
| CODE: |
| 1371 |
4021 |
| SSize_t len = av_len(path_av) + 1; |
| 1372 |
4021 |
| SV *current = path_value(aTHX_ data); |
| 1373 |
|
| |
| 1374 |
4021 |
▶ | if (UNLIKELY(len == 0)) croak("Cannot delete root"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (UNLIKELY(len == 0)) croak("Cannot delete root"); |
3 |
4018 |
4021 |
|
| 1375 |
|
| |
| 1376 |
12031 |
▶ | for (SSize_t i = 0; i < len - 1; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (SSize_t i = 0; i < len - 1; i++) { |
8014 |
4017 |
12031 |
|
| 1377 |
8014 |
| SV **key_ptr = av_fetch(path_av, i, 0); |
| 1378 |
8014 |
▶ | if (UNLIKELY(!key_ptr || !*key_ptr || !SvROK(current))) { RETVAL = &PL_sv_undef; goto done; } |
Branch: 4 branches
| Branch | True | False | Total |
| if (UNLIKELY(!key_ptr || !*key_ptr || !SvROK(current))) { RETVAL = &PL_sv_undef; goto done; } |
8014 |
0 |
8014 |
| if (UNLIKELY(!key_ptr || !*key_ptr || !SvROK(current))) { RETVAL = &PL_sv_undef; goto done; } |
0 |
8014 |
8014 |
| if (UNLIKELY(!key_ptr || !*key_ptr || !SvROK(current))) { RETVAL = &PL_sv_undef; goto done; } |
8014 |
0 |
8014 |
| if (UNLIKELY(!key_ptr || !*key_ptr || !SvROK(current))) { RETVAL = &PL_sv_undef; goto done; } |
1 |
8013 |
8014 |
|
| 1379 |
|
| |
| 1380 |
8013 |
| SV *inner = SvRV(current); |
| 1381 |
8013 |
| svtype t = SvTYPE(inner); |
| 1382 |
|
| |
| 1383 |
8013 |
▶ | if (LIKELY(t == SVt_PVHV)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (LIKELY(t == SVt_PVHV)) { |
8012 |
1 |
8013 |
|
| 1384 |
|
| const char *kstr; |
| 1385 |
8012 |
| I32 sklen = sv_to_klen(aTHX_ *key_ptr, &kstr); |
| 1386 |
8012 |
| SV *val = path_fetch(aTHX_ hv_fetch((HV*)inner, kstr, sklen, 0)); |
| 1387 |
8012 |
▶ | if (UNLIKELY(!val)) { RETVAL = &PL_sv_undef; goto done; } |
Branch: 1 branch
| Branch | True | False | Total |
| if (UNLIKELY(!val)) { RETVAL = &PL_sv_undef; goto done; } |
0 |
8012 |
8012 |
|
| 1388 |
8012 |
| current = val; |
| 1389 |
1 |
▶ | } else if (t == SVt_PVAV) { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if (t == SVt_PVAV) { |
1 |
0 |
1 |
|
| 1390 |
|
| IV idx; |
| 1391 |
1 |
▶ | if (UNLIKELY(!sv_to_index(aTHX_ *key_ptr, &idx))) { RETVAL = &PL_sv_undef; goto done; } |
Branch: 1 branch
| Branch | True | False | Total |
| if (UNLIKELY(!sv_to_index(aTHX_ *key_ptr, &idx))) { RETVAL = &PL_sv_undef; goto done; } |
0 |
1 |
1 |
|
| 1392 |
1 |
| SV *val = path_fetch(aTHX_ av_fetch((AV*)inner, idx, 0)); |
| 1393 |
1 |
▶ | if (UNLIKELY(!val)) { RETVAL = &PL_sv_undef; goto done; } |
Branch: 1 branch
| Branch | True | False | Total |
| if (UNLIKELY(!val)) { RETVAL = &PL_sv_undef; goto done; } |
0 |
1 |
1 |
|
| 1394 |
1 |
| current = val; |
| 1395 |
|
| } else { |
| 1396 |
0 |
| RETVAL = &PL_sv_undef; goto done; |
| 1397 |
|
| } |
| 1398 |
|
| } |
| 1399 |
|
| |
| 1400 |
4017 |
▶ | if (UNLIKELY(!SvROK(current))) { RETVAL = &PL_sv_undef; goto done; } |
Branch: 1 branch
| Branch | True | False | Total |
| if (UNLIKELY(!SvROK(current))) { RETVAL = &PL_sv_undef; goto done; } |
0 |
4017 |
4017 |
|
| 1401 |
4017 |
| SV *inner = SvRV(current); |
| 1402 |
4017 |
| svtype t = SvTYPE(inner); |
| 1403 |
4017 |
| SV **final_key_ptr = av_fetch(path_av, len - 1, 0); |
| 1404 |
4017 |
▶ | if (UNLIKELY(!final_key_ptr || !*final_key_ptr)) { RETVAL = &PL_sv_undef; goto done; } |
Branch: 2 branches
| Branch | True | False | Total |
| if (UNLIKELY(!final_key_ptr || !*final_key_ptr)) { RETVAL = &PL_sv_undef; goto done; } |
4017 |
0 |
4017 |
| if (UNLIKELY(!final_key_ptr || !*final_key_ptr)) { RETVAL = &PL_sv_undef; goto done; } |
0 |
4017 |
4017 |
|
| 1405 |
|
| |
| 1406 |
4017 |
▶ | if (LIKELY(t == SVt_PVHV)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (LIKELY(t == SVt_PVHV)) { |
4013 |
4 |
4017 |
|
| 1407 |
|
| const char *kstr; |
| 1408 |
4013 |
| I32 sklen = sv_to_klen(aTHX_ *final_key_ptr, &kstr); |
| 1409 |
4013 |
| RETVAL = hv_delete((HV*)inner, kstr, sklen, 0); |
| 1410 |
4013 |
▶ | if (RETVAL) SvREFCNT_inc(RETVAL); |
Branch: 1 branch
| Branch | True | False | Total |
| if (RETVAL) SvREFCNT_inc(RETVAL); |
4010 |
3 |
4013 |
|
| 1411 |
3 |
| else RETVAL = &PL_sv_undef; |
| 1412 |
4 |
▶ | } else if (t == SVt_PVAV) { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if (t == SVt_PVAV) { |
4 |
0 |
4 |
|
| 1413 |
|
| IV idx; |
| 1414 |
4 |
▶ | if (sv_to_index(aTHX_ *final_key_ptr, &idx)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (sv_to_index(aTHX_ *final_key_ptr, &idx)) { |
3 |
1 |
4 |
|
| 1415 |
3 |
| SV *old = av_delete((AV*)inner, idx, 0); |
| 1416 |
3 |
▶ | RETVAL = old ? SvREFCNT_inc(old) : &PL_sv_undef; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = old ? SvREFCNT_inc(old) : &PL_sv_undef; |
3 |
0 |
3 |
|
| 1417 |
|
| } else { |
| 1418 |
1 |
| RETVAL = &PL_sv_undef; |
| 1419 |
|
| } |
| 1420 |
|
| } else { |
| 1421 |
0 |
| RETVAL = &PL_sv_undef; |
| 1422 |
|
| } |
| 1423 |
4018 |
| done: |
| 1424 |
|
| OUTPUT: |
| 1425 |
|
| RETVAL |
| 1426 |
|
| |
| 1427 |
|
| # Compiled path API |
| 1428 |
|
| |
| 1429 |
|
| SV* |
| 1430 |
|
| path_compile(path) |
| 1431 |
|
| SV *path |
| 1432 |
|
| CODE: |
| 1433 |
101 |
| CompiledPath *cp = compile_path(aTHX_ path); |
| 1434 |
101 |
| SV *obj = newSV(0); |
| 1435 |
101 |
| sv_setref_pv(obj, "Data::Path::XS::Compiled", (void*)cp); |
| 1436 |
101 |
| RETVAL = obj; |
| 1437 |
|
| OUTPUT: |
| 1438 |
|
| RETVAL |
| 1439 |
|
| |
| 1440 |
|
| SV* |
| 1441 |
|
| pathc_get(data, compiled) |
| 1442 |
|
| SV *data |
| 1443 |
|
| SV *compiled |
| 1444 |
|
| CODE: |
| 1445 |
|
| CompiledPath *cp; |
| 1446 |
253 |
▶ | VALIDATE_COMPILED_PATH(compiled, cp); |
Branch: 4 branches
| Branch | True | False | Total |
| VALIDATE_COMPILED_PATH(compiled, cp); |
250 |
3 |
253 |
| VALIDATE_COMPILED_PATH(compiled, cp); |
7 |
243 |
250 |
| VALIDATE_COMPILED_PATH(compiled, cp); |
243 |
0 |
243 |
| VALIDATE_COMPILED_PATH(compiled, cp); |
0 |
243 |
243 |
|
| 1447 |
|
| |
| 1448 |
243 |
▶ | if (UNLIKELY(cp->count == 0)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (UNLIKELY(cp->count == 0)) { |
1 |
242 |
243 |
|
| 1449 |
1 |
| RETVAL = SvREFCNT_inc(data); |
| 1450 |
|
| } else { |
| 1451 |
|
| /* Fully inlined navigation for maximum speed */ |
| 1452 |
242 |
| SV *current = path_value(aTHX_ data); |
| 1453 |
242 |
| PathComponent *c = cp->components; |
| 1454 |
242 |
| PathComponent *end = c + cp->count; |
| 1455 |
242 |
| const I32 utf8_flag = cp->utf8_flag; |
| 1456 |
|
| |
| 1457 |
717 |
▶ | while (c < end) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (c < end) { |
478 |
239 |
717 |
|
| 1458 |
478 |
▶ | if (UNLIKELY(!SvROK(current))) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (UNLIKELY(!SvROK(current))) { |
1 |
477 |
478 |
|
| 1459 |
1 |
| RETVAL = &PL_sv_undef; |
| 1460 |
1 |
| goto done; |
| 1461 |
|
| } |
| 1462 |
|
| |
| 1463 |
477 |
| SV *inner = SvRV(current); |
| 1464 |
477 |
| svtype t = SvTYPE(inner); |
| 1465 |
|
| |
| 1466 |
477 |
▶ | if (LIKELY(t == SVt_PVHV)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (LIKELY(t == SVt_PVHV)) { |
462 |
15 |
477 |
|
| 1467 |
462 |
| SV *val = compiled_fetch(aTHX_ (HV*)inner, c, utf8_flag); |
| 1468 |
462 |
▶ | if (UNLIKELY(!val)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (UNLIKELY(!val)) { |
1 |
461 |
462 |
|
| 1469 |
1 |
| RETVAL = &PL_sv_undef; |
| 1470 |
1 |
| goto done; |
| 1471 |
|
| } |
| 1472 |
461 |
| current = val; |
| 1473 |
15 |
▶ | } else if (t == SVt_PVAV) { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if (t == SVt_PVAV) { |
15 |
0 |
15 |
|
| 1474 |
15 |
▶ | if (UNLIKELY(!c->is_numeric)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (UNLIKELY(!c->is_numeric)) { |
1 |
14 |
15 |
|
| 1475 |
1 |
| RETVAL = &PL_sv_undef; |
| 1476 |
1 |
| goto done; |
| 1477 |
|
| } |
| 1478 |
14 |
| SV *val = path_fetch(aTHX_ av_fetch((AV*)inner, c->idx, 0)); |
| 1479 |
14 |
▶ | if (UNLIKELY(!val)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (UNLIKELY(!val)) { |
0 |
14 |
14 |
|
| 1480 |
0 |
| RETVAL = &PL_sv_undef; |
| 1481 |
0 |
| goto done; |
| 1482 |
|
| } |
| 1483 |
14 |
| current = val; |
| 1484 |
|
| } else { |
| 1485 |
0 |
| RETVAL = &PL_sv_undef; |
| 1486 |
0 |
| goto done; |
| 1487 |
|
| } |
| 1488 |
475 |
| c++; |
| 1489 |
|
| } |
| 1490 |
239 |
| RETVAL = SvREFCNT_inc(current); |
| 1491 |
|
| } |
| 1492 |
243 |
| done: |
| 1493 |
|
| OUTPUT: |
| 1494 |
|
| RETVAL |
| 1495 |
|
| |
| 1496 |
|
| SV* |
| 1497 |
|
| pathc_set(data, compiled, value) |
| 1498 |
|
| SV *data |
| 1499 |
|
| SV *compiled |
| 1500 |
|
| SV *value |
| 1501 |
|
| PPCODE: |
| 1502 |
246 |
| PUTBACK; |
| 1503 |
246 |
| value = path_source(aTHX_ value); |
| 1504 |
|
| SV *stored; |
| 1505 |
|
| CompiledPath *cp; |
| 1506 |
246 |
▶ | VALIDATE_COMPILED_PATH(compiled, cp); |
Branch: 4 branches
| Branch | True | False | Total |
| VALIDATE_COMPILED_PATH(compiled, cp); |
246 |
0 |
246 |
| VALIDATE_COMPILED_PATH(compiled, cp); |
1 |
245 |
246 |
| VALIDATE_COMPILED_PATH(compiled, cp); |
245 |
0 |
245 |
| VALIDATE_COMPILED_PATH(compiled, cp); |
0 |
245 |
245 |
|
| 1507 |
|
| |
| 1508 |
245 |
▶ | if (UNLIKELY(cp->count == 0)) croak("Cannot set root"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (UNLIKELY(cp->count == 0)) croak("Cannot set root"); |
2 |
243 |
245 |
|
| 1509 |
|
| |
| 1510 |
|
| /* Fully inlined navigation with creation for maximum speed */ |
| 1511 |
243 |
| SV *current = path_value(aTHX_ data); |
| 1512 |
243 |
| PathComponent *c = cp->components; |
| 1513 |
243 |
| PathComponent *last = c + cp->count - 1; |
| 1514 |
243 |
| const I32 utf8_flag = cp->utf8_flag; |
| 1515 |
|
| |
| 1516 |
|
| /* Navigate to parent, creating intermediate structures as needed */ |
| 1517 |
467 |
▶ | while (c < last) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (c < last) { |
228 |
239 |
467 |
|
| 1518 |
228 |
▶ | if (UNLIKELY(!SvROK(current))) croak("Cannot navigate to path"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (UNLIKELY(!SvROK(current))) croak("Cannot navigate to path"); |
0 |
228 |
228 |
|
| 1519 |
|
| |
| 1520 |
228 |
| SV *inner = SvRV(current); |
| 1521 |
228 |
| svtype t = SvTYPE(inner); |
| 1522 |
|
| |
| 1523 |
228 |
▶ | if (LIKELY(t == SVt_PVHV)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (LIKELY(t == SVt_PVHV)) { |
225 |
3 |
228 |
|
| 1524 |
225 |
| I32 klen = (I32)c->len * utf8_flag; |
| 1525 |
225 |
| SV *val = compiled_fetch(aTHX_ (HV*)inner, c, utf8_flag); |
| 1526 |
223 |
▶ | if (UNLIKELY(!val || !SvROK(val))) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (UNLIKELY(!val || !SvROK(val))) { |
214 |
9 |
223 |
| if (UNLIKELY(!val || !SvROK(val))) { |
5 |
209 |
214 |
|
| 1527 |
|
| /* Create intermediate structure using pre-computed type */ |
| 1528 |
14 |
▶ | SV *new_ref = sv_2mortal(c->next_is_array |
Branch: 1 branch
| Branch | True | False | Total |
| SV *new_ref = sv_2mortal(c->next_is_array |
2 |
12 |
14 |
|
| 1529 |
|
| ? newRV_noinc((SV*)newAV()) |
| 1530 |
|
| : newRV_noinc((SV*)newHV())); |
| 1531 |
14 |
▶ | if (UNLIKELY(!hv_store((HV*)inner, c->str, klen, new_ref, c->hash))) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (UNLIKELY(!hv_store((HV*)inner, c->str, klen, new_ref, c->hash))) { |
0 |
14 |
14 |
|
| 1532 |
0 |
▶ | croak(SvRMAGICAL(inner) |
Branch: 1 branch
| Branch | True | False | Total |
| croak(SvRMAGICAL(inner) |
0 |
0 |
0 |
|
| 1533 |
|
| ? "Cannot pathc_set on tied/magical hash" |
| 1534 |
|
| : "Failed to store intermediate value"); |
| 1535 |
|
| } |
| 1536 |
14 |
| SvREFCNT_inc_simple_void_NN(new_ref); |
| 1537 |
14 |
| current = new_ref; |
| 1538 |
|
| } else { |
| 1539 |
209 |
| current = val; |
| 1540 |
|
| } |
| 1541 |
3 |
▶ | } else if (t == SVt_PVAV) { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if (t == SVt_PVAV) { |
3 |
0 |
3 |
|
| 1542 |
3 |
▶ | if (UNLIKELY(!c->is_numeric)) croak("Invalid array index"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (UNLIKELY(!c->is_numeric)) croak("Invalid array index"); |
1 |
2 |
3 |
|
| 1543 |
2 |
| SV *val = path_fetch(aTHX_ av_fetch((AV*)inner, c->idx, 0)); |
| 1544 |
2 |
▶ | if (UNLIKELY(!val || !SvROK(val))) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (UNLIKELY(!val || !SvROK(val))) { |
1 |
1 |
2 |
| if (UNLIKELY(!val || !SvROK(val))) { |
1 |
0 |
1 |
|
| 1545 |
2 |
▶ | SV *new_ref = sv_2mortal(c->next_is_array |
Branch: 1 branch
| Branch | True | False | Total |
| SV *new_ref = sv_2mortal(c->next_is_array |
0 |
2 |
2 |
|
| 1546 |
|
| ? newRV_noinc((SV*)newAV()) |
| 1547 |
|
| : newRV_noinc((SV*)newHV())); |
| 1548 |
2 |
▶ | if (UNLIKELY(!av_store((AV*)inner, c->idx, new_ref))) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (UNLIKELY(!av_store((AV*)inner, c->idx, new_ref))) { |
1 |
1 |
2 |
|
| 1549 |
1 |
▶ | croak(SvRMAGICAL(inner) |
Branch: 1 branch
| Branch | True | False | Total |
| croak(SvRMAGICAL(inner) |
1 |
0 |
1 |
|
| 1550 |
|
| ? "Cannot pathc_set on tied/magical array" |
| 1551 |
|
| : "Failed to store intermediate value"); |
| 1552 |
|
| } |
| 1553 |
1 |
| SvREFCNT_inc_simple_void_NN(new_ref); |
| 1554 |
1 |
| current = new_ref; |
| 1555 |
|
| } else { |
| 1556 |
0 |
| current = val; |
| 1557 |
|
| } |
| 1558 |
|
| } else { |
| 1559 |
0 |
| croak("Cannot navigate to path"); |
| 1560 |
|
| } |
| 1561 |
224 |
| c++; |
| 1562 |
|
| } |
| 1563 |
|
| |
| 1564 |
|
| /* Set the final value */ |
| 1565 |
239 |
▶ | if (UNLIKELY(!SvROK(current))) croak("Cannot navigate to path"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (UNLIKELY(!SvROK(current))) croak("Cannot navigate to path"); |
0 |
239 |
239 |
|
| 1566 |
239 |
| SV *inner = SvRV(current); |
| 1567 |
239 |
| svtype t = SvTYPE(inner); |
| 1568 |
|
| |
| 1569 |
239 |
▶ | if (LIKELY(t == SVt_PVHV)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (LIKELY(t == SVt_PVHV)) { |
227 |
12 |
239 |
|
| 1570 |
227 |
| stored = path_store_hash(aTHX_ (HV*)inner, last->str, (I32)last->len * utf8_flag, last->hash, value, "pathc_set"); |
| 1571 |
12 |
▶ | } else if (t == SVt_PVAV) { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if (t == SVt_PVAV) { |
12 |
0 |
12 |
|
| 1572 |
12 |
▶ | if (!last->is_numeric) croak("Invalid array index"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!last->is_numeric) croak("Invalid array index"); |
2 |
10 |
12 |
|
| 1573 |
10 |
| stored = path_store_array(aTHX_ (AV*)inner, last->idx, value, "pathc_set"); |
| 1574 |
|
| } else { |
| 1575 |
0 |
| croak("Parent is not a hash or array"); |
| 1576 |
|
| } |
| 1577 |
|
| |
| 1578 |
228 |
| SPAGAIN; |
| 1579 |
228 |
▶ | if (GIMME_V != G_VOID) |
Branch: 1 branch
| Branch | True | False | Total |
| if (GIMME_V != G_VOID) |
7 |
221 |
228 |
|
| 1580 |
7 |
▶ | XPUSHs(sv_2mortal(SvREFCNT_inc(stored))); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(sv_2mortal(SvREFCNT_inc(stored))); |
0 |
7 |
7 |
|
| 1581 |
|
| |
| 1582 |
|
| int |
| 1583 |
|
| pathc_exists(data, compiled) |
| 1584 |
|
| SV *data |
| 1585 |
|
| SV *compiled |
| 1586 |
|
| CODE: |
| 1587 |
|
| CompiledPath *cp; |
| 1588 |
14 |
▶ | VALIDATE_COMPILED_PATH(compiled, cp); |
Branch: 4 branches
| Branch | True | False | Total |
| VALIDATE_COMPILED_PATH(compiled, cp); |
14 |
0 |
14 |
| VALIDATE_COMPILED_PATH(compiled, cp); |
1 |
13 |
14 |
| VALIDATE_COMPILED_PATH(compiled, cp); |
13 |
0 |
13 |
| VALIDATE_COMPILED_PATH(compiled, cp); |
0 |
13 |
13 |
|
| 1589 |
|
| |
| 1590 |
13 |
▶ | if (UNLIKELY(cp->count == 0)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (UNLIKELY(cp->count == 0)) { |
1 |
12 |
13 |
|
| 1591 |
1 |
| RETVAL = 1; |
| 1592 |
|
| } else { |
| 1593 |
|
| /* Inlined navigation to parent */ |
| 1594 |
12 |
| SV *current = path_value(aTHX_ data); |
| 1595 |
12 |
| PathComponent *c = cp->components; |
| 1596 |
12 |
| PathComponent *last = c + cp->count - 1; |
| 1597 |
12 |
| const I32 utf8_flag = cp->utf8_flag; |
| 1598 |
|
| |
| 1599 |
23 |
▶ | while (c < last) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (c < last) { |
11 |
12 |
23 |
|
| 1600 |
11 |
▶ | if (UNLIKELY(!SvROK(current))) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (UNLIKELY(!SvROK(current))) { |
0 |
11 |
11 |
|
| 1601 |
0 |
| RETVAL = 0; |
| 1602 |
0 |
| goto done; |
| 1603 |
|
| } |
| 1604 |
11 |
| SV *inner = SvRV(current); |
| 1605 |
11 |
| svtype t = SvTYPE(inner); |
| 1606 |
|
| |
| 1607 |
11 |
▶ | if (LIKELY(t == SVt_PVHV)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (LIKELY(t == SVt_PVHV)) { |
11 |
0 |
11 |
|
| 1608 |
11 |
| SV *val = compiled_fetch(aTHX_ (HV*)inner, c, utf8_flag); |
| 1609 |
11 |
▶ | if (UNLIKELY(!val)) { RETVAL = 0; goto done; } |
Branch: 1 branch
| Branch | True | False | Total |
| if (UNLIKELY(!val)) { RETVAL = 0; goto done; } |
0 |
11 |
11 |
|
| 1610 |
11 |
| current = val; |
| 1611 |
0 |
▶ | } else if (t == SVt_PVAV) { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if (t == SVt_PVAV) { |
0 |
0 |
0 |
|
| 1612 |
0 |
▶ | if (UNLIKELY(!c->is_numeric)) { RETVAL = 0; goto done; } |
Branch: 1 branch
| Branch | True | False | Total |
| if (UNLIKELY(!c->is_numeric)) { RETVAL = 0; goto done; } |
0 |
0 |
0 |
|
| 1613 |
0 |
| SV *val = path_fetch(aTHX_ av_fetch((AV*)inner, c->idx, 0)); |
| 1614 |
0 |
▶ | if (UNLIKELY(!val)) { RETVAL = 0; goto done; } |
Branch: 1 branch
| Branch | True | False | Total |
| if (UNLIKELY(!val)) { RETVAL = 0; goto done; } |
0 |
0 |
0 |
|
| 1615 |
0 |
| current = val; |
| 1616 |
|
| } else { |
| 1617 |
0 |
| RETVAL = 0; |
| 1618 |
0 |
| goto done; |
| 1619 |
|
| } |
| 1620 |
11 |
| c++; |
| 1621 |
|
| } |
| 1622 |
|
| |
| 1623 |
|
| /* Check final key existence */ |
| 1624 |
12 |
▶ | if (UNLIKELY(!SvROK(current))) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (UNLIKELY(!SvROK(current))) { |
0 |
12 |
12 |
|
| 1625 |
0 |
| RETVAL = 0; |
| 1626 |
|
| } else { |
| 1627 |
12 |
| SV *inner = SvRV(current); |
| 1628 |
12 |
| svtype t = SvTYPE(inner); |
| 1629 |
12 |
▶ | if (LIKELY(t == SVt_PVHV)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (LIKELY(t == SVt_PVHV)) { |
6 |
6 |
12 |
|
| 1630 |
6 |
| RETVAL = cBOOL(hv_common_key_len((HV*)inner, last->str, (I32)last->len * utf8_flag, HV_FETCH_ISEXISTS, NULL, last->hash)); |
| 1631 |
6 |
▶ | } else if (t == SVt_PVAV) { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if (t == SVt_PVAV) { |
6 |
0 |
6 |
|
| 1632 |
6 |
▶ | RETVAL = last->is_numeric ? av_exists((AV*)inner, last->idx) : 0; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = last->is_numeric ? av_exists((AV*)inner, last->idx) : 0; |
5 |
1 |
6 |
|
| 1633 |
|
| } else { |
| 1634 |
0 |
| RETVAL = 0; |
| 1635 |
|
| } |
| 1636 |
|
| } |
| 1637 |
|
| } |
| 1638 |
13 |
▶ | done: |
Branch: 1 branch
| Branch | True | False | Total |
| done: |
2 |
11 |
13 |
|
| 1639 |
|
| OUTPUT: |
| 1640 |
|
| RETVAL |
| 1641 |
|
| |
| 1642 |
|
| SV* |
| 1643 |
|
| pathc_delete(data, compiled) |
| 1644 |
|
| SV *data |
| 1645 |
|
| SV *compiled |
| 1646 |
|
| CODE: |
| 1647 |
|
| CompiledPath *cp; |
| 1648 |
10 |
▶ | VALIDATE_COMPILED_PATH(compiled, cp); |
Branch: 4 branches
| Branch | True | False | Total |
| VALIDATE_COMPILED_PATH(compiled, cp); |
10 |
0 |
10 |
| VALIDATE_COMPILED_PATH(compiled, cp); |
1 |
9 |
10 |
| VALIDATE_COMPILED_PATH(compiled, cp); |
9 |
0 |
9 |
| VALIDATE_COMPILED_PATH(compiled, cp); |
0 |
9 |
9 |
|
| 1649 |
|
| |
| 1650 |
9 |
▶ | if (UNLIKELY(cp->count == 0)) croak("Cannot delete root"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (UNLIKELY(cp->count == 0)) croak("Cannot delete root"); |
2 |
7 |
9 |
|
| 1651 |
|
| |
| 1652 |
|
| /* Inlined navigation to parent */ |
| 1653 |
7 |
| SV *current = path_value(aTHX_ data); |
| 1654 |
7 |
| PathComponent *c = cp->components; |
| 1655 |
7 |
| PathComponent *last = c + cp->count - 1; |
| 1656 |
7 |
| const I32 utf8_flag = cp->utf8_flag; |
| 1657 |
|
| |
| 1658 |
15 |
▶ | while (c < last) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (c < last) { |
8 |
7 |
15 |
|
| 1659 |
8 |
▶ | if (UNLIKELY(!SvROK(current))) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (UNLIKELY(!SvROK(current))) { |
0 |
8 |
8 |
|
| 1660 |
0 |
| RETVAL = &PL_sv_undef; |
| 1661 |
0 |
| goto done; |
| 1662 |
|
| } |
| 1663 |
8 |
| SV *inner = SvRV(current); |
| 1664 |
8 |
| svtype t = SvTYPE(inner); |
| 1665 |
|
| |
| 1666 |
8 |
▶ | if (LIKELY(t == SVt_PVHV)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (LIKELY(t == SVt_PVHV)) { |
8 |
0 |
8 |
|
| 1667 |
8 |
| SV *val = compiled_fetch(aTHX_ (HV*)inner, c, utf8_flag); |
| 1668 |
8 |
▶ | if (UNLIKELY(!val)) { RETVAL = &PL_sv_undef; goto done; } |
Branch: 1 branch
| Branch | True | False | Total |
| if (UNLIKELY(!val)) { RETVAL = &PL_sv_undef; goto done; } |
0 |
8 |
8 |
|
| 1669 |
8 |
| current = val; |
| 1670 |
0 |
▶ | } else if (t == SVt_PVAV) { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if (t == SVt_PVAV) { |
0 |
0 |
0 |
|
| 1671 |
0 |
▶ | if (UNLIKELY(!c->is_numeric)) { RETVAL = &PL_sv_undef; goto done; } |
Branch: 1 branch
| Branch | True | False | Total |
| if (UNLIKELY(!c->is_numeric)) { RETVAL = &PL_sv_undef; goto done; } |
0 |
0 |
0 |
|
| 1672 |
0 |
| SV *val = path_fetch(aTHX_ av_fetch((AV*)inner, c->idx, 0)); |
| 1673 |
0 |
▶ | if (UNLIKELY(!val)) { RETVAL = &PL_sv_undef; goto done; } |
Branch: 1 branch
| Branch | True | False | Total |
| if (UNLIKELY(!val)) { RETVAL = &PL_sv_undef; goto done; } |
0 |
0 |
0 |
|
| 1674 |
0 |
| current = val; |
| 1675 |
|
| } else { |
| 1676 |
0 |
| RETVAL = &PL_sv_undef; |
| 1677 |
0 |
| goto done; |
| 1678 |
|
| } |
| 1679 |
8 |
| c++; |
| 1680 |
|
| } |
| 1681 |
|
| |
| 1682 |
|
| /* Delete final key */ |
| 1683 |
7 |
▶ | if (UNLIKELY(!SvROK(current))) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (UNLIKELY(!SvROK(current))) { |
0 |
7 |
7 |
|
| 1684 |
0 |
| RETVAL = &PL_sv_undef; |
| 1685 |
|
| } else { |
| 1686 |
7 |
| SV *inner = SvRV(current); |
| 1687 |
7 |
| svtype t = SvTYPE(inner); |
| 1688 |
|
| |
| 1689 |
7 |
▶ | if (LIKELY(t == SVt_PVHV)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (LIKELY(t == SVt_PVHV)) { |
5 |
2 |
7 |
|
| 1690 |
5 |
| RETVAL = hv_delete((HV*)inner, last->str, (I32)last->len * utf8_flag, 0); |
| 1691 |
5 |
▶ | if (RETVAL) SvREFCNT_inc(RETVAL); |
Branch: 1 branch
| Branch | True | False | Total |
| if (RETVAL) SvREFCNT_inc(RETVAL); |
4 |
1 |
5 |
|
| 1692 |
1 |
| else RETVAL = &PL_sv_undef; |
| 1693 |
2 |
▶ | } else if (t == SVt_PVAV) { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if (t == SVt_PVAV) { |
2 |
0 |
2 |
|
| 1694 |
2 |
▶ | if (last->is_numeric) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (last->is_numeric) { |
1 |
1 |
2 |
|
| 1695 |
1 |
| SV *old = av_delete((AV*)inner, last->idx, 0); |
| 1696 |
1 |
▶ | RETVAL = old ? SvREFCNT_inc(old) : &PL_sv_undef; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = old ? SvREFCNT_inc(old) : &PL_sv_undef; |
1 |
0 |
1 |
|
| 1697 |
|
| } else { |
| 1698 |
1 |
| RETVAL = &PL_sv_undef; |
| 1699 |
|
| } |
| 1700 |
|
| } else { |
| 1701 |
0 |
| RETVAL = &PL_sv_undef; |
| 1702 |
|
| } |
| 1703 |
|
| } |
| 1704 |
7 |
| done: |
| 1705 |
|
| OUTPUT: |
| 1706 |
|
| RETVAL |
| 1707 |
|
| |
| 1708 |
|
| MODULE = Data::Path::XS PACKAGE = Data::Path::XS::Compiled |
| 1709 |
|
| |
| 1710 |
|
| int |
| 1711 |
|
| CLONE_SKIP(class) |
| 1712 |
|
| SV *class |
| 1713 |
|
| CODE: |
| 1714 |
|
| PERL_UNUSED_VAR(class); |
| 1715 |
0 |
▶ | RETVAL = 1; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = 1; |
0 |
0 |
0 |
|
| 1716 |
|
| OUTPUT: |
| 1717 |
|
| RETVAL |
| 1718 |
|
| |
| 1719 |
|
| void |
| 1720 |
|
| DESTROY(self) |
| 1721 |
|
| SV *self |
| 1722 |
|
| CODE: |
| 1723 |
106 |
▶ | if (SvROK(self)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvROK(self)) { |
106 |
0 |
106 |
|
| 1724 |
106 |
| SV *inner = SvRV(self); |
| 1725 |
|
| /* SvIOK guard avoids "Argument isn't numeric" warnings when this |
| 1726 |
|
| * package name was abused to bless arbitrary refs. */ |
| 1727 |
106 |
▶ | if (SvIOK(inner)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvIOK(inner)) { |
101 |
5 |
106 |
|
| 1728 |
101 |
| CompiledPath *cp = INT2PTR(CompiledPath*, SvIVX(inner)); |
| 1729 |
101 |
▶ | if (cp && cp->magic == COMPILED_PATH_MAGIC) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (cp && cp->magic == COMPILED_PATH_MAGIC) { |
101 |
0 |
101 |
| if (cp && cp->magic == COMPILED_PATH_MAGIC) { |
101 |
0 |
101 |
|
| 1730 |
101 |
| free_compiled_path(aTHX_ cp); |
| 1731 |
|
| } |
| 1732 |
|
| } |
| 1733 |
|
| } |
| 1734 |
|
| |
| 1735 |
|
| MODULE = Data::Path::XS PACKAGE = Data::Path::XS |
| 1736 |
|
| |
| 1737 |
|
| BOOT: |
| 1738 |
|
| { |
| 1739 |
|
| #define REGISTER_XOP(xop, nm, dsc, pp) STMT_START { \ |
| 1740 |
|
| XopENTRY_set(&(xop), xop_name, (nm)); \ |
| 1741 |
|
| XopENTRY_set(&(xop), xop_desc, (dsc)); \ |
| 1742 |
|
| Perl_custom_op_register(aTHX_ (pp), &(xop)); \ |
| 1743 |
|
| } STMT_END |
| 1744 |
|
| |
| 1745 |
22 |
| REGISTER_XOP(xop_pathget, "pathget_dynamic", "dynamic path get", pp_pathget_dynamic); |
| 1746 |
22 |
| REGISTER_XOP(xop_pathset, "pathset_dynamic", "dynamic path set", pp_pathset_dynamic); |
| 1747 |
22 |
| REGISTER_XOP(xop_pathdelete, "pathdelete_dynamic", "dynamic path delete", pp_pathdelete_dynamic); |
| 1748 |
22 |
| REGISTER_XOP(xop_pathexists, "pathexists_dynamic", "dynamic path exists", pp_pathexists_dynamic); |
| 1749 |
|
| #undef REGISTER_XOP |
| 1750 |
|
| |
| 1751 |
22 |
| boot_xs_parse_keyword(0.40); |
| 1752 |
22 |
| register_xs_parse_keyword("pathget", &hooks_pathget, NULL); |
| 1753 |
22 |
| register_xs_parse_keyword("pathset", &hooks_pathset, NULL); |
| 1754 |
22 |
| register_xs_parse_keyword("pathdelete", &hooks_pathdelete, NULL); |
| 1755 |
22 |
| register_xs_parse_keyword("pathexists", &hooks_pathexists, NULL); |
| 1756 |
|
| } |