include/sa/sa_xop.h

filter: Statementstmt 89.3% 376 / 421 Branchbran 57.5% 638 / 1108 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 66.3% 1014 / 1529 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« include/sa/sa_abi_impl.h ↑ Summary xs/abi.xs »
1 #ifndef SA_XOP_H
2 #define SA_XOP_H
3  
4 /* sa_xop.h - the hot doors as opcodes rather than calls.
5 *
6 * `$cache->get($k)` is two ops and an XSUB call frame, and the frame runs before
7 * any of the work does. This removes it, so the method form becomes the fast
8 * form and there is no separate "fast API" to migrate to.
9 *
10 * ---- BOTH ops, not just one -------------------------------------------------
11 *
12 * Swapping op_ppaddr on OP_ENTERSUB removes the call frame AND NOTHING ELSE.
13 * `$obj->get($k)` still runs pp_method_named first, which walks the stash for
14 * the name and validates the method cache before the hooked entersub is
15 * reached. So the check hook swaps two ops on the same subtree: the
16 * METHOD_NAMED that resolves the name, and the ENTERSUB that would call what it
17 * resolved.
18 *
19 * How much each half is worth, measured on an M-series Mac at 500k iterations,
20 * as XSUB / entersub only / both (bench/xop.pl, which runs the same binary
21 * three ways):
22 *
23 * cache->get 62.2 61.7 48.8 ns
24 * map->incr 38.9 31.2 26.6
25 * bloom->check 33.5 30.3 23.2
26 * hist->record 26.4 20.2 14.2
27 *
28 * Read the first row before deciding the second swap is a refinement: hooking
29 * entersub alone bought `get` NOTHING. The whole of that door's saving is the
30 * method resolution, and a version that swapped one op would have been all of
31 * the risk for none of the gain.
32 *
33 * ---- how a monkeypatch still wins ------------------------------------------
34 *
35 * `*Shared::Arena::Cache::get = sub { ... }` puts a different CV in the same
36 * glob, and a caller who does that has every reason to expect it to take
37 * effect. Two things together make sure it does.
38 *
39 * The GLOB is read per call, never the CV. The method op pushes whatever the
40 * glob holds NOW, which after a monkeypatch is the replacement.
41 *
42 * The ORIGINAL CV is captured at BOOT and used for identity, never called. The
43 * entersub op runs its C door only when the thing on the stack is that exact
44 * XSUB; a replacement is a different pointer, so the guard declines and the
45 * ordinary path calls what the caller installed.
46 *
47 * Both halves are needed. Comparing against the glob's current CV instead
48 * would make a replacement match ITSELF and the C door would run in its place -
49 * a monkeypatch that silently does nothing, which is the worst outcome
50 * available. And a reference is held on the original, so that a sub which is
51 * deleted rather than replaced cannot free the CV and let a later allocation
52 * land on the same address and pass an identity check it should fail.
53 *
54 * ---- one pp function per door ----------------------------------------------
55 *
56 * A single generic one would have to read the method name off the op to know
57 * what to do, which means looking it up, which is the cost being removed.
58 *
59 * ---- when another dist got there first -------------------------------------
60 *
61 * Frozen hooks OP_ENTERSUB too, and it hooks `->get($k)` - one argument, same
62 * name. Since Frozen is a prerequisite here it is ALWAYS loaded, so this is not
63 * a corner case, it is the flagship door.
64 *
65 * Two hooks cannot both own one op_ppaddr. Overwriting the other dist's would
66 * silently cost it its fast path; refusing the site outright costs this one its
67 * own, which is what happened first and is why `cache->get` briefly went back
68 * to being an ordinary call.
69 *
70 * So when the entersub is already somebody's, only the METHOD_NAMED op is
71 * taken. The other dist keeps its entersub guard, which declines for an
72 * invocant that is not its own and delegates, so both stay correct.
73 *
74 * IT WAS NOT THE WHOLE WIN, AND THE ABLATION SAID SO. `cache->get` measured
75 * 60.2ns unhooked, 55.1ns with the method op alone, and 48.8ns with both. The
76 * two swaps are not additive - each alone is worth about 5ns and together they
77 * are worth 12 - because when both belong to the same hook the method op
78 * pushes a CV that the entersub immediately consumes, and neither has to go
79 * through a generic dispatch to hand it over.
80 *
81 * Overwriting the other hook's ppaddr would take the same saving off THEIR
82 * door, which is no better for being invisible from here. So at a shared site
83 * the method op makes the whole call itself and returns the op AFTER the
84 * entersub, which then never runs: sa_pp_methdoor_cache_get, below. That is
85 * the two-op saving from one op, with no change to the other dist and no side
86 * table keyed by op address. Measured on one machine: 52.5ns before, 42.4
87 * after.
88 *
89 * The guards compose because each one checks the invocant's class and the
90 * CV's identity. For a Cache the method op answers and Frozen's entersub is
91 * never reached. For a Frozen container this declines at the method op and
92 * Frozen's own fast path runs untouched.
93 *
94 * ---- what it costs everybody else ------------------------------------------
95 *
96 * The hook sees every `->get`, `->set`, `->add`, `->check`, `->record`,
97 * `->store`, `->fetch`, `->exists`, `->incr`, `->counter`, `->publish`,
98 * `->allow`, `->remaining`, `->retry_after` and `->estimate` in the whole
99 * program, not only this dist's, at each width a door exists for. A call on
100 * another class runs the guard, declines and delegates: measured at 2.5ns per
101 * non-matching call, 39.6 to 42.1. A program that makes millions of those and
102 * few of ours is paying for something it does not use, and sets
103 * SHARED_ARENA_NO_XOP=1.
104 *
105 * `delete` and `remove` are deliberately not hooked at all. They are common
106 * names on other classes, the tax would fall on every one of them, and neither
107 * is on a request path often enough to pay for that.
108 *
109 * ---- what is NOT hooked ----------------------------------------------------
110 *
111 * op_type is left alone, so B::Deparse, B::Concise and every other dumper see
112 * an ordinary entersub and keep working. A guard that fails delegates rather
113 * than croaking. A door with optional arguments is a separate door per width,
114 * each compiled only where the call site has exactly that many; a width nobody
115 * wrote a door for - `drain` with a max - takes the ordinary path, because a
116 * guard that has to cope with any stack shape is a guard that has stopped
117 * being cheap.
118 */
119  
120 #include "sa/sa_cache.h"
121 #include "sa/sa_hash.h"
122 #include "sa/sa_bloom.h"
123 #include "sa/sa_hist.h"
124 #include "sa/sa_ring.h"
125 #include "sa/sa_rate.h"
126 #include "sa/sa_cms.h"
127 #include "sa/sa_cuckoo.h"
128 #include "xop_compat.h"
129  
130 static Perl_check_t sa_prev_ck_entersub = NULL;
131  
132 static HV *sa_stash_cache = NULL;
133 static HV *sa_stash_map = NULL;
134 static HV *sa_stash_bloom = NULL;
135 static HV *sa_stash_hist = NULL;
136 static HV *sa_stash_ring = NULL;
137 static HV *sa_stash_rate = NULL;
138 static HV *sa_stash_cms = NULL;
139 static HV *sa_stash_cuckoo = NULL;
140  
141 /* Per door: the glob, read every call, and the XSUB that was in it at BOOT,
142 * compared but never called. */
143 #define SA_DOORS(_) \
144 _(cache_get, "Shared::Arena::Cache::get") \
145 _(cache_set, "Shared::Arena::Cache::set") \
146 _(map_fetch, "Shared::Arena::Map::fetch") \
147 _(map_store, "Shared::Arena::Map::store") \
148 _(map_incr, "Shared::Arena::Map::incr") \
149 _(map_exists, "Shared::Arena::Map::exists") \
150 _(bloom_add, "Shared::Arena::Bloom::add") \
151 _(bloom_check, "Shared::Arena::Bloom::check") \
152 _(hist_record, "Shared::Arena::Histogram::record") \
153 _(ring_publish, "Shared::Arena::Ring::publish") \
154 _(rate_allow, "Shared::Arena::Rate::allow") \
155 _(cms_add, "Shared::Arena::CountMin::add") \
156 _(cms_estimate, "Shared::Arena::CountMin::estimate") \
157 _(cuckoo_add, "Shared::Arena::Cuckoo::add") \
158 _(cuckoo_check, "Shared::Arena::Cuckoo::check") \
159 _(rate_remaining, "Shared::Arena::Rate::remaining") \
160 _(rate_retry_after, "Shared::Arena::Rate::retry_after") \
161 _(map_counter, "Shared::Arena::Map::counter")
162  
163 #define SA_DOOR_DECL(door, path) \
164 static GV *sa_gv_##door = NULL; static CV *sa_cv_##door = NULL;
165 SA_DOORS(SA_DOOR_DECL)
166 #undef SA_DOOR_DECL
167  
168 static IV sa_xop_hook = 0; /* call sites rewritten at compile time */
169 static IV sa_xop_hits = 0; /* calls that took the op path */
170 static IV sa_xop_miss = 0; /* calls that declined and delegated */
171 static IV sa_xop_meth = 0; /* sites where only the method op was ours */
172  
173 #define SA_IS(sv, stash) \
174 ((stash) && SvROK(sv) && SvOBJECT(SvRV(sv)) && SvSTASH(SvRV(sv)) == (stash))
175  
176 #ifdef G_LIST
177 # define SA_G_LIST G_LIST
178 #else
179 # define SA_G_LIST G_ARRAY
180 #endif
181  
182 /* The invocant, if this call is one we may answer: the stack shape is what the
183 * op was hooked for, the CV is still the one the glob holds, and the invocant
184 * is of the class this door belongs to. Anything else and the caller gets the
185 * ordinary path. */
186 #define SA_XOP_SELF(want_cv, stash, nargs) \
187 SV **mark = PL_stack_base + TOPMARK; \
188 SV *self; \
189 do { \
190 if (sp - mark != (nargs) + 2) goto delegate; \
191 if (!(want_cv) || (CV *)*sp != (want_cv)) goto delegate; \
192 self = mark[1]; \
193 if (!SA_IS(self, stash)) goto delegate; \
194 } while (0)
195  
196 #define SA_XOP_PTR(type) INT2PTR(type, SvIV(SvRV(self)))
197  
198 #define SA_XOP_RETURN(nargs, sv) \
199 do { \
200 (void)POPMARK; \
201 sp -= (nargs) + 2; \
202 PUSHs(sv); \
203 PUTBACK; \
204 sa_xop_hits++; \
205 return NORMAL; \
206 } while (0)
207  
208 /* An empty list in list context, undef in scalar - the shape every "absent"
209 * door in this dist uses, so the op path and the XSUB path agree. */
210 #define SA_XOP_EMPTY(nargs) \
211 do { \
212 (void)POPMARK; \
213 sp -= (nargs) + 2; \
214 if (GIMME_V != SA_G_LIST) PUSHs(&PL_sv_undef); \
215 PUTBACK; \
216 sa_xop_hits++; \
217 return NORMAL; \
218 } while (0)
219  
220 #define SA_XOP_DELEGATE() \
221 delegate: \
222 sa_xop_miss++; \
223 return PL_ppaddr[OP_ENTERSUB](aTHX)
224  
225 /* After a codec call. Encoding or decoding a value can run Perl (an anonymous
226 * sub is deparsed one way and eval'd the other), which may reallocate the
227 * value stack under `sp` and `mark`. Both are re-derived, and the callee's
228 * marks are balanced so TOPMARK is ours again. */
229 #define SA_XOP_RESYNC() \
230 do { \
231 SPAGAIN; \
232 mark = PL_stack_base + TOPMARK; \
233 } while (0)
234  
235 /* An integer answer goes in the entersub's pad target, which is where the XSUB
236 * this replaces put it through dXSTARG. A fresh mortal per call is an
237 * allocation and a free that the XSUB never paid. */
238 #define SA_XOP_TARG() \
239 ((PL_op->op_private & OPpENTERSUB_HASTARG) \
240 ? PAD_SV(PL_op->op_targ) : sv_newmortal())
241  
242 #define SA_XOP_RETURN_IV(nargs, iv) \
243 do { \
244 SV *targ_ = SA_XOP_TARG(); \
245 sv_setiv_mg(targ_, (IV)(iv)); \
246 SA_XOP_RETURN(nargs, targ_); \
247 } while (0)
248  
249 #define SA_XOP_RETURN_UV(nargs, uv) \
250 do { \
251 SV *targ_ = SA_XOP_TARG(); \
252 sv_setuv_mg(targ_, (UV)(uv)); \
253 SA_XOP_RETURN(nargs, targ_); \
254 } while (0)
255  
256 #define SA_XOP_RETURN_NV(nargs, nv) \
257 do { \
258 SV *targ_ = SA_XOP_TARG(); \
259 sv_setnv_mg(targ_, (NV)(nv)); \
260 SA_XOP_RETURN(nargs, targ_); \
261 } while (0)
262  
263 /* Nothing to return, as from the void XSUB this replaces - which pp_entersub
264 * turns into ONE undef in scalar context. The op has to do the same, or
265 * `map { scalar $h->record($_) } 1 .. 3` comes back with no elements. */
266 #define SA_XOP_VOID(nargs) \
267 do { \
268 (void)POPMARK; \
269 sp -= (nargs) + 2; \
270 if (GIMME_V == G_SCALAR) PUSHs(&PL_sv_undef); \
271 PUTBACK; \
272 sa_xop_hits++; \
273 return NORMAL; \
274 } while (0)
275  
276 /* ---- the method resolution ------------------------------------------------
277 *
278 * pp_method_named walks the stash and checks the method cache. When the
279 * invocant is ours the answer is known without looking, so this pushes it and
280 * returns. Everything else delegates, including a CV somebody has replaced. */
281 #define SA_XOP_METH(door, stash) \
282 static OP *sa_pp_meth_##door(pTHX) { \
283 dSP; \
284 SV **mark = PL_stack_base + TOPMARK; \
285 SV *self; \
286 CV *cv; \
287 if (sp <= mark) return PL_ppaddr[OP_METHOD_NAMED](aTHX); \
288 self = mark[1]; \
289 if (!SA_IS(self, stash)) return PL_ppaddr[OP_METHOD_NAMED](aTHX); \
290 cv = sa_gv_##door ? GvCV(sa_gv_##door) : NULL; \
291 if (!cv) return PL_ppaddr[OP_METHOD_NAMED](aTHX); \
292 XPUSHs((SV *)cv); \
293 PUTBACK; \
294 return NORMAL; \
295 }
296  
297 40 ▶SA_XOP_METH(cache_get, sa_stash_cache)
Branch: 8 branches
BranchTrueFalseTotal
SA_XOP_METH(cache_get, sa_stash_cache) 0 40 40
SA_XOP_METH(cache_get, sa_stash_cache) 40 0 40
SA_XOP_METH(cache_get, sa_stash_cache) 39 1 40
SA_XOP_METH(cache_get, sa_stash_cache) 39 0 39
SA_XOP_METH(cache_get, sa_stash_cache) 35 4 39
SA_XOP_METH(cache_get, sa_stash_cache) 4 0 4
SA_XOP_METH(cache_get, sa_stash_cache) 0 4 4
SA_XOP_METH(cache_get, sa_stash_cache) 0 4 4
298 910 ▶SA_XOP_METH(cache_set, sa_stash_cache)
Branch: 8 branches
BranchTrueFalseTotal
SA_XOP_METH(cache_set, sa_stash_cache) 0 910 910
SA_XOP_METH(cache_set, sa_stash_cache) 910 0 910
SA_XOP_METH(cache_set, sa_stash_cache) 910 0 910
SA_XOP_METH(cache_set, sa_stash_cache) 910 0 910
SA_XOP_METH(cache_set, sa_stash_cache) 1 909 910
SA_XOP_METH(cache_set, sa_stash_cache) 909 0 909
SA_XOP_METH(cache_set, sa_stash_cache) 0 909 909
SA_XOP_METH(cache_set, sa_stash_cache) 0 909 909
299 666 ▶SA_XOP_METH(map_fetch, sa_stash_map)
Branch: 8 branches
BranchTrueFalseTotal
SA_XOP_METH(map_fetch, sa_stash_map) 0 666 666
SA_XOP_METH(map_fetch, sa_stash_map) 666 0 666
SA_XOP_METH(map_fetch, sa_stash_map) 666 0 666
SA_XOP_METH(map_fetch, sa_stash_map) 666 0 666
SA_XOP_METH(map_fetch, sa_stash_map) 1 665 666
SA_XOP_METH(map_fetch, sa_stash_map) 665 0 665
SA_XOP_METH(map_fetch, sa_stash_map) 0 665 665
SA_XOP_METH(map_fetch, sa_stash_map) 0 665 665
300 130 ▶SA_XOP_METH(map_store, sa_stash_map)
Branch: 8 branches
BranchTrueFalseTotal
SA_XOP_METH(map_store, sa_stash_map) 0 130 130
SA_XOP_METH(map_store, sa_stash_map) 130 0 130
SA_XOP_METH(map_store, sa_stash_map) 130 0 130
SA_XOP_METH(map_store, sa_stash_map) 130 0 130
SA_XOP_METH(map_store, sa_stash_map) 0 130 130
SA_XOP_METH(map_store, sa_stash_map) 130 0 130
SA_XOP_METH(map_store, sa_stash_map) 0 130 130
SA_XOP_METH(map_store, sa_stash_map) 0 130 130
301 241 ▶SA_XOP_METH(map_incr, sa_stash_map)
Branch: 8 branches
BranchTrueFalseTotal
SA_XOP_METH(map_incr, sa_stash_map) 0 241 241
SA_XOP_METH(map_incr, sa_stash_map) 241 0 241
SA_XOP_METH(map_incr, sa_stash_map) 241 0 241
SA_XOP_METH(map_incr, sa_stash_map) 241 0 241
SA_XOP_METH(map_incr, sa_stash_map) 18 223 241
SA_XOP_METH(map_incr, sa_stash_map) 223 0 223
SA_XOP_METH(map_incr, sa_stash_map) 0 223 223
SA_XOP_METH(map_incr, sa_stash_map) 0 223 223
302 189 ▶SA_XOP_METH(map_exists, sa_stash_map)
Branch: 8 branches
BranchTrueFalseTotal
SA_XOP_METH(map_exists, sa_stash_map) 0 189 189
SA_XOP_METH(map_exists, sa_stash_map) 189 0 189
SA_XOP_METH(map_exists, sa_stash_map) 189 0 189
SA_XOP_METH(map_exists, sa_stash_map) 189 0 189
SA_XOP_METH(map_exists, sa_stash_map) 8 181 189
SA_XOP_METH(map_exists, sa_stash_map) 181 0 181
SA_XOP_METH(map_exists, sa_stash_map) 0 181 181
SA_XOP_METH(map_exists, sa_stash_map) 0 181 181
303 1679 ▶SA_XOP_METH(hist_record, sa_stash_hist)
Branch: 8 branches
BranchTrueFalseTotal
SA_XOP_METH(hist_record, sa_stash_hist) 0 1679 1679
SA_XOP_METH(hist_record, sa_stash_hist) 1679 0 1679
SA_XOP_METH(hist_record, sa_stash_hist) 1679 0 1679
SA_XOP_METH(hist_record, sa_stash_hist) 1679 0 1679
SA_XOP_METH(hist_record, sa_stash_hist) 0 1679 1679
SA_XOP_METH(hist_record, sa_stash_hist) 1679 0 1679
SA_XOP_METH(hist_record, sa_stash_hist) 0 1679 1679
SA_XOP_METH(hist_record, sa_stash_hist) 0 1679 1679
304 2882 ▶SA_XOP_METH(ring_publish, sa_stash_ring)
Branch: 8 branches
BranchTrueFalseTotal
SA_XOP_METH(ring_publish, sa_stash_ring) 0 2882 2882
SA_XOP_METH(ring_publish, sa_stash_ring) 2882 0 2882
SA_XOP_METH(ring_publish, sa_stash_ring) 2882 0 2882
SA_XOP_METH(ring_publish, sa_stash_ring) 2882 0 2882
SA_XOP_METH(ring_publish, sa_stash_ring) 0 2882 2882
SA_XOP_METH(ring_publish, sa_stash_ring) 2882 0 2882
SA_XOP_METH(ring_publish, sa_stash_ring) 0 2882 2882
SA_XOP_METH(ring_publish, sa_stash_ring) 0 2882 2882
305 8420 ▶SA_XOP_METH(rate_allow, sa_stash_rate)
Branch: 8 branches
BranchTrueFalseTotal
SA_XOP_METH(rate_allow, sa_stash_rate) 0 8420 8420
SA_XOP_METH(rate_allow, sa_stash_rate) 8420 0 8420
SA_XOP_METH(rate_allow, sa_stash_rate) 8420 0 8420
SA_XOP_METH(rate_allow, sa_stash_rate) 8420 0 8420
SA_XOP_METH(rate_allow, sa_stash_rate) 0 8420 8420
SA_XOP_METH(rate_allow, sa_stash_rate) 8420 0 8420
SA_XOP_METH(rate_allow, sa_stash_rate) 0 8420 8420
SA_XOP_METH(rate_allow, sa_stash_rate) 0 8420 8420
306 3521 ▶SA_XOP_METH(cms_estimate, sa_stash_cms)
Branch: 8 branches
BranchTrueFalseTotal
SA_XOP_METH(cms_estimate, sa_stash_cms) 0 3521 3521
SA_XOP_METH(cms_estimate, sa_stash_cms) 3521 0 3521
SA_XOP_METH(cms_estimate, sa_stash_cms) 3521 0 3521
SA_XOP_METH(cms_estimate, sa_stash_cms) 3521 0 3521
SA_XOP_METH(cms_estimate, sa_stash_cms) 0 3521 3521
SA_XOP_METH(cms_estimate, sa_stash_cms) 3521 0 3521
SA_XOP_METH(cms_estimate, sa_stash_cms) 0 3521 3521
SA_XOP_METH(cms_estimate, sa_stash_cms) 0 3521 3521
307  
308 /* ---- the doors themselves -------------------------------------------------- */
309  
310 0 static OP *sa_pp_cache_get(pTHX) {
311 0 dSP;
312 {
313 0 ▶ SA_XOP_SELF(sa_cv_cache_get, sa_stash_cache, 1);
Branch: 7 branches
BranchTrueFalseTotal
SA_XOP_SELF(sa_cv_cache_get, sa_stash_cache, 1); 0 0 0
SA_XOP_SELF(sa_cv_cache_get, sa_stash_cache, 1); 0 0 0
SA_XOP_SELF(sa_cv_cache_get, sa_stash_cache, 1); 0 0 0
SA_XOP_SELF(sa_cv_cache_get, sa_stash_cache, 1); 0 0 0
SA_XOP_SELF(sa_cv_cache_get, sa_stash_cache, 1); 0 0 0
SA_XOP_SELF(sa_cv_cache_get, sa_stash_cache, 1); 0 0 0
SA_XOP_SELF(sa_cv_cache_get, sa_stash_cache, 1); 0 0 0
314 {
315 0 sa_cache *c = SA_XOP_PTR(sa_cache *);
316 STRLEN klen;
317 const char *k;
318 SV *out;
319 char buf[1024];
320 0 uint32_t vlen = 0;
321 0 ▶ if (!c) goto delegate;
Branch: 1 branch
BranchTrueFalseTotal
if (!c) goto delegate; 0 0 0
322 0 k = SvPV(mark[2], klen);
323 /* Stack first where an entry fits, as the XSUB does: a miss
324 * allocates nothing and a hit only what the value needs. On a
325 * serialised cache the copy is decoded from wherever it landed;
326 * a door that delegated on the flag would give the small-value
327 * win straight back. */
328 0 ▶ if (c->pair_max < sizeof buf) {
Branch: 1 branch
BranchTrueFalseTotal
if (c->pair_max < sizeof buf) { 0 0 0
329 0 ▶ if (sa_cache_get(c, k, (uint32_t)klen, buf,
Branch: 1 branch
BranchTrueFalseTotal
if (sa_cache_get(c, k, (uint32_t)klen, buf, 0 0 0
330 0 (uint32_t)c->pair_max, &vlen) != SA_C_HIT)
331 0 ▶ SA_XOP_EMPTY(1);
Branch: 1 branch
BranchTrueFalseTotal
SA_XOP_EMPTY(1); 0 0 0
332 0 ▶ if (c->serialise) {
Branch: 1 branch
BranchTrueFalseTotal
if (c->serialise) { 0 0 0
333 0 out = SA_SER_DECODE(buf, vlen);
334 0 SA_XOP_RESYNC();
335 0 SA_XOP_RETURN(1, out);
336 }
337 0 SA_XOP_RETURN(1, sv_2mortal(newSVpvn(buf, (STRLEN)vlen)));
338 }
339 0 out = sv_2mortal(newSV((STRLEN)c->pair_max + 1));
340 0 SvPOK_on(out);
341 0 ▶ if (sa_cache_get(c, k, (uint32_t)klen, SvPVX(out),
Branch: 1 branch
BranchTrueFalseTotal
if (sa_cache_get(c, k, (uint32_t)klen, SvPVX(out), 0 0 0
342 0 (uint32_t)c->pair_max, &vlen) != SA_C_HIT)
343 0 ▶ SA_XOP_EMPTY(1);
Branch: 1 branch
BranchTrueFalseTotal
SA_XOP_EMPTY(1); 0 0 0
344 0 ▶ if (c->serialise) {
Branch: 1 branch
BranchTrueFalseTotal
if (c->serialise) { 0 0 0
345 0 out = SA_SER_DECODE(SvPVX(out), vlen);
346 0 SA_XOP_RESYNC();
347 0 SA_XOP_RETURN(1, out);
348 }
349 0 SvCUR_set(out, (STRLEN)vlen);
350 0 SvPVX(out)[vlen] = '\0';
351 0 SA_XOP_RETURN(1, out);
352 }
353 }
354 0 SA_XOP_DELEGATE();
355 }
356  
357 900 static OP *sa_pp_cache_set(pTHX) {
358 900 dSP;
359 {
360 900 ▶ SA_XOP_SELF(sa_cv_cache_set, sa_stash_cache, 2);
Branch: 7 branches
BranchTrueFalseTotal
SA_XOP_SELF(sa_cv_cache_set, sa_stash_cache, 2); 0 900 900
SA_XOP_SELF(sa_cv_cache_set, sa_stash_cache, 2); 900 0 900
SA_XOP_SELF(sa_cv_cache_set, sa_stash_cache, 2); 1 899 900
SA_XOP_SELF(sa_cv_cache_set, sa_stash_cache, 2); 899 0 899
SA_XOP_SELF(sa_cv_cache_set, sa_stash_cache, 2); 899 0 899
SA_XOP_SELF(sa_cv_cache_set, sa_stash_cache, 2); 899 0 899
SA_XOP_SELF(sa_cv_cache_set, sa_stash_cache, 2); 0 899 899
361 {
362 899 sa_cache *c = SA_XOP_PTR(sa_cache *);
363 STRLEN klen, vlen;
364 const char *k, *v;
365 int rc;
366 char sbuf[SA_SER_STACK];
367 899 ▶ if (!c) goto delegate;
Branch: 1 branch
BranchTrueFalseTotal
if (!c) goto delegate; 1 898 899
368 898 k = SvPV(mark[2], klen);
369 898 ▶ if (c->serialise) {
Branch: 1 branch
BranchTrueFalseTotal
if (c->serialise) { 16 882 898
370 16 vlen = sa_ser_encode(aTHX_ mark[3], c->pair_max, klen, sbuf, &v);
371 14 SA_XOP_RESYNC();
372 906 ▶ if (!vlen) SA_XOP_RETURN_IV(2, SA_C_TOOBIG);
Branch: 2 branches
BranchTrueFalseTotal
if (!vlen) SA_XOP_RETURN_IV(2, SA_C_TOOBIG); 4 10 14
if (!vlen) SA_XOP_RETURN_IV(2, SA_C_TOOBIG); 4 0 4
373 }
374 else
375 1764 v = SvPV(mark[3], vlen);
376 892 rc = sa_cache_set(c, k, (uint32_t)klen, v, (uint32_t)vlen, 0);
377 892 ▶ SA_XOP_RETURN_IV(2, rc);
Branch: 1 branch
BranchTrueFalseTotal
SA_XOP_RETURN_IV(2, rc); 892 0 892
378 }
379 }
380 2 SA_XOP_DELEGATE();
381 }
382  
383 666 static OP *sa_pp_map_fetch(pTHX) {
384 666 dSP;
385 {
386 666 ▶ SA_XOP_SELF(sa_cv_map_fetch, sa_stash_map, 1);
Branch: 7 branches
BranchTrueFalseTotal
SA_XOP_SELF(sa_cv_map_fetch, sa_stash_map, 1); 0 666 666
SA_XOP_SELF(sa_cv_map_fetch, sa_stash_map, 1); 666 0 666
SA_XOP_SELF(sa_cv_map_fetch, sa_stash_map, 1); 1 665 666
SA_XOP_SELF(sa_cv_map_fetch, sa_stash_map, 1); 665 0 665
SA_XOP_SELF(sa_cv_map_fetch, sa_stash_map, 1); 665 0 665
SA_XOP_SELF(sa_cv_map_fetch, sa_stash_map, 1); 665 0 665
SA_XOP_SELF(sa_cv_map_fetch, sa_stash_map, 1); 0 665 665
387 {
388 665 sa_hash *m = SA_XOP_PTR(sa_hash *);
389 STRLEN klen;
390 const char *k;
391 SV *out;
392 char buf[1024];
393 665 uint32_t vlen = 0;
394 665 ▶ if (!m) goto delegate;
Branch: 1 branch
BranchTrueFalseTotal
if (!m) goto delegate; 0 665 665
395 665 k = SvPV(mark[2], klen);
396 /* Stack first where a slot fits, as the XSUB does; decoded from
397 * wherever the copy landed on a serialised map. */
398 665 ▶ if (m->pair_max < sizeof buf) {
Branch: 1 branch
BranchTrueFalseTotal
if (m->pair_max < sizeof buf) { 664 1 665
399 664 ▶ if (sa_hash_fetch(m, k, (uint32_t)klen, buf,
Branch: 1 branch
BranchTrueFalseTotal
if (sa_hash_fetch(m, k, (uint32_t)klen, buf, 467 197 664
400 664 (uint32_t)m->pair_max, &vlen) != SA_H_HIT)
401 665 ▶ SA_XOP_EMPTY(1);
Branch: 1 branch
BranchTrueFalseTotal
SA_XOP_EMPTY(1); 464 3 467
402 197 ▶ if (m->serialise) {
Branch: 1 branch
BranchTrueFalseTotal
if (m->serialise) { 8 189 197
403 8 out = SA_SER_DECODE(buf, vlen);
404 8 SA_XOP_RESYNC();
405 8 SA_XOP_RETURN(1, out);
406 }
407 189 SA_XOP_RETURN(1, sv_2mortal(newSVpvn(buf, (STRLEN)vlen)));
408 }
409 1 out = sv_2mortal(newSV((STRLEN)m->pair_max + 1));
410 1 SvPOK_on(out);
411 1 ▶ if (sa_hash_fetch(m, k, (uint32_t)klen, SvPVX(out),
Branch: 1 branch
BranchTrueFalseTotal
if (sa_hash_fetch(m, k, (uint32_t)klen, SvPVX(out), 0 1 1
412 1 (uint32_t)m->pair_max, &vlen) != SA_H_HIT)
413 0 ▶ SA_XOP_EMPTY(1);
Branch: 1 branch
BranchTrueFalseTotal
SA_XOP_EMPTY(1); 0 0 0
414 1 ▶ if (m->serialise) {
Branch: 1 branch
BranchTrueFalseTotal
if (m->serialise) { 1 0 1
415 1 out = SA_SER_DECODE(SvPVX(out), vlen);
416 1 SA_XOP_RESYNC();
417 1 SA_XOP_RETURN(1, out);
418 }
419 0 SvCUR_set(out, (STRLEN)vlen);
420 0 SvPVX(out)[vlen] = '\0';
421 0 SA_XOP_RETURN(1, out);
422 }
423 }
424 1 SA_XOP_DELEGATE();
425 }
426  
427 130 static OP *sa_pp_map_store(pTHX) {
428 130 dSP;
429 {
430 130 ▶ SA_XOP_SELF(sa_cv_map_store, sa_stash_map, 2);
Branch: 7 branches
BranchTrueFalseTotal
SA_XOP_SELF(sa_cv_map_store, sa_stash_map, 2); 0 130 130
SA_XOP_SELF(sa_cv_map_store, sa_stash_map, 2); 130 0 130
SA_XOP_SELF(sa_cv_map_store, sa_stash_map, 2); 0 130 130
SA_XOP_SELF(sa_cv_map_store, sa_stash_map, 2); 130 0 130
SA_XOP_SELF(sa_cv_map_store, sa_stash_map, 2); 130 0 130
SA_XOP_SELF(sa_cv_map_store, sa_stash_map, 2); 130 0 130
SA_XOP_SELF(sa_cv_map_store, sa_stash_map, 2); 0 130 130
431 {
432 130 sa_hash *m = SA_XOP_PTR(sa_hash *);
433 STRLEN klen, vlen;
434 const char *k, *v;
435 int rc;
436 char sbuf[SA_SER_STACK];
437 130 ▶ if (!m) goto delegate;
Branch: 1 branch
BranchTrueFalseTotal
if (!m) goto delegate; 0 130 130
438 130 k = SvPV(mark[2], klen);
439 130 ▶ if (m->serialise) {
Branch: 1 branch
BranchTrueFalseTotal
if (m->serialise) { 11 119 130
440 11 vlen = sa_ser_encode(aTHX_ mark[3], m->pair_max, klen, sbuf, &v);
441 10 SA_XOP_RESYNC();
442 137 ▶ if (!vlen) SA_XOP_RETURN_IV(2, SA_H_TOOBIG);
Branch: 2 branches
BranchTrueFalseTotal
if (!vlen) SA_XOP_RETURN_IV(2, SA_H_TOOBIG); 2 8 10
if (!vlen) SA_XOP_RETURN_IV(2, SA_H_TOOBIG); 2 0 2
443 }
444 else
445 238 v = SvPV(mark[3], vlen);
446 127 rc = sa_hash_store(m, k, (uint32_t)klen, v, (uint32_t)vlen);
447 127 ▶ SA_XOP_RETURN_IV(2, rc);
Branch: 1 branch
BranchTrueFalseTotal
SA_XOP_RETURN_IV(2, rc); 127 0 127
448 }
449 }
450 0 SA_XOP_DELEGATE();
451 }
452  
453 /* A counter is a raw word and cannot also be an encoded value: both incr
454 * widths croak on a serialised map, as the XSUB does. */
455 92 static OP *sa_pp_map_incr(pTHX) {
456 92 dSP;
457 {
458 92 ▶ SA_XOP_SELF(sa_cv_map_incr, sa_stash_map, 1);
Branch: 7 branches
BranchTrueFalseTotal
SA_XOP_SELF(sa_cv_map_incr, sa_stash_map, 1); 0 92 92
SA_XOP_SELF(sa_cv_map_incr, sa_stash_map, 1); 92 0 92
SA_XOP_SELF(sa_cv_map_incr, sa_stash_map, 1); 0 92 92
SA_XOP_SELF(sa_cv_map_incr, sa_stash_map, 1); 92 0 92
SA_XOP_SELF(sa_cv_map_incr, sa_stash_map, 1); 92 0 92
SA_XOP_SELF(sa_cv_map_incr, sa_stash_map, 1); 92 0 92
SA_XOP_SELF(sa_cv_map_incr, sa_stash_map, 1); 0 92 92
459 {
460 92 sa_hash *m = SA_XOP_PTR(sa_hash *);
461 STRLEN klen;
462 const char *k;
463 92 uint64_t now = 0;
464 92 ▶ if (!m) goto delegate;
Branch: 1 branch
BranchTrueFalseTotal
if (!m) goto delegate; 0 92 92
465 92 ▶ if (m->serialise) croak(SA_SER_INCR_MSG);
Branch: 1 branch
BranchTrueFalseTotal
if (m->serialise) croak(SA_SER_INCR_MSG); 1 91 92
466 91 k = SvPV(mark[2], klen);
467 91 ▶ if (sa_hash_incr(m, k, (uint32_t)klen, 1, &now) != SA_H_OK)
Branch: 1 branch
BranchTrueFalseTotal
if (sa_hash_incr(m, k, (uint32_t)klen, 1, &now) != SA_H_OK) 1 90 91
468 91 SA_XOP_RETURN(1, &PL_sv_undef);
469 90 ▶ SA_XOP_RETURN_UV(1, (UV)now);
Branch: 1 branch
BranchTrueFalseTotal
SA_XOP_RETURN_UV(1, (UV)now); 90 0 90
470 }
471 }
472 0 SA_XOP_DELEGATE();
473 }
474  
475 189 static OP *sa_pp_map_exists(pTHX) {
476 189 dSP;
477 {
478 189 ▶ SA_XOP_SELF(sa_cv_map_exists, sa_stash_map, 1);
Branch: 7 branches
BranchTrueFalseTotal
SA_XOP_SELF(sa_cv_map_exists, sa_stash_map, 1); 0 189 189
SA_XOP_SELF(sa_cv_map_exists, sa_stash_map, 1); 189 0 189
SA_XOP_SELF(sa_cv_map_exists, sa_stash_map, 1); 8 181 189
SA_XOP_SELF(sa_cv_map_exists, sa_stash_map, 1); 181 0 181
SA_XOP_SELF(sa_cv_map_exists, sa_stash_map, 1); 181 0 181
SA_XOP_SELF(sa_cv_map_exists, sa_stash_map, 1); 181 0 181
SA_XOP_SELF(sa_cv_map_exists, sa_stash_map, 1); 0 181 181
479 {
480 181 sa_hash *m = SA_XOP_PTR(sa_hash *);
481 STRLEN klen;
482 const char *k;
483 char scratch[8];
484 181 uint32_t vlen = 0;
485 int hit;
486 181 ▶ if (!m) goto delegate;
Branch: 1 branch
BranchTrueFalseTotal
if (!m) goto delegate; 0 181 181
487 181 k = SvPV(mark[2], klen);
488 181 hit = sa_hash_fetch(m, k, (uint32_t)klen, scratch, 0, &vlen)
489 181 != SA_H_MISS;
490 181 ▶ SA_XOP_RETURN_IV(1, hit ? 1 : 0);
Branch: 2 branches
BranchTrueFalseTotal
SA_XOP_RETURN_IV(1, hit ? 1 : 0); 181 0 181
SA_XOP_RETURN_IV(1, hit ? 1 : 0); 89 92 181
491 }
492 }
493 8 SA_XOP_DELEGATE();
494 }
495  
496 /* `check` is a name both filters answer to, so it is one door for two classes,
497 * told apart the way `add` below tells its three apart: by the CV the method op
498 * pushed, which is also the identity that keeps a monkeypatch working. */
499 120066 static OP *sa_pp_meth_check(pTHX) {
500 120066 dSP;
501 120066 SV **mark = PL_stack_base + TOPMARK;
502 SV *self;
503 120066 CV *cv = NULL;
504 120066 ▶ if (sp <= mark) return PL_ppaddr[OP_METHOD_NAMED](aTHX);
Branch: 1 branch
BranchTrueFalseTotal
if (sp <= mark) return PL_ppaddr[OP_METHOD_NAMED](aTHX); 0 120066 120066
505 120066 self = mark[1];
506 120066 ▶ if (SA_IS(self, sa_stash_bloom) && sa_gv_bloom_check)
Branch: 5 branches
BranchTrueFalseTotal
if (SA_IS(self, sa_stash_bloom) && sa_gv_bloom_check) 120066 0 120066
if (SA_IS(self, sa_stash_bloom) && sa_gv_bloom_check) 120066 0 120066
if (SA_IS(self, sa_stash_bloom) && sa_gv_bloom_check) 120066 0 120066
if (SA_IS(self, sa_stash_bloom) && sa_gv_bloom_check) 33014 87052 120066
if (SA_IS(self, sa_stash_bloom) && sa_gv_bloom_check) 33014 0 33014
507 33014 cv = GvCV(sa_gv_bloom_check);
508 87052 ▶ else if (SA_IS(self, sa_stash_cuckoo) && sa_gv_cuckoo_check)
Branch: 5 branches
BranchTrueFalseTotal
else if (SA_IS(self, sa_stash_cuckoo) && sa_gv_cuckoo_check) 87052 0 87052
else if (SA_IS(self, sa_stash_cuckoo) && sa_gv_cuckoo_check) 87052 0 87052
else if (SA_IS(self, sa_stash_cuckoo) && sa_gv_cuckoo_check) 87052 0 87052
else if (SA_IS(self, sa_stash_cuckoo) && sa_gv_cuckoo_check) 87052 0 87052
else if (SA_IS(self, sa_stash_cuckoo) && sa_gv_cuckoo_check) 87052 0 87052
509 87052 cv = GvCV(sa_gv_cuckoo_check);
510 120066 ▶ if (!cv) return PL_ppaddr[OP_METHOD_NAMED](aTHX);
Branch: 1 branch
BranchTrueFalseTotal
if (!cv) return PL_ppaddr[OP_METHOD_NAMED](aTHX); 0 120066 120066
511 120066 ▶ XPUSHs((SV *)cv);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs((SV *)cv); 0 120066 120066
512 120066 PUTBACK;
513 120066 return NORMAL;
514 }
515  
516 120066 static OP *sa_pp_check(pTHX) {
517 120066 dSP;
518 120066 SV **mark = PL_stack_base + TOPMARK;
519 SV *self;
520 STRLEN klen;
521 const char *k;
522  
523 120066 ▶ if (sp - mark != 3) goto delegate;
Branch: 1 branch
BranchTrueFalseTotal
if (sp - mark != 3) goto delegate; 0 120066 120066
524 120066 self = mark[1];
525  
526 120066 ▶ if ((CV *)*sp == sa_cv_bloom_check && SA_IS(self, sa_stash_bloom)) {
Branch: 5 branches
BranchTrueFalseTotal
if ((CV *)*sp == sa_cv_bloom_check && SA_IS(self, sa_stash_bloom)) { 33014 87052 120066
if ((CV *)*sp == sa_cv_bloom_check && SA_IS(self, sa_stash_bloom)) { 33014 0 33014
if ((CV *)*sp == sa_cv_bloom_check && SA_IS(self, sa_stash_bloom)) { 33014 0 33014
if ((CV *)*sp == sa_cv_bloom_check && SA_IS(self, sa_stash_bloom)) { 33014 0 33014
if ((CV *)*sp == sa_cv_bloom_check && SA_IS(self, sa_stash_bloom)) { 33014 0 33014
527 33014 sa_bloom *b = SA_XOP_PTR(sa_bloom *);
528 33014 ▶ if (!b) goto delegate;
Branch: 1 branch
BranchTrueFalseTotal
if (!b) goto delegate; 0 33014 33014
529 33014 k = SvPV(mark[2], klen);
530 33014 ▶ SA_XOP_RETURN_IV(1, sa_bloom_check(b, k, (uint32_t)klen));
Branch: 1 branch
BranchTrueFalseTotal
SA_XOP_RETURN_IV(1, sa_bloom_check(b, k, (uint32_t)klen)); 33014 0 33014
531 }
532 87052 ▶ if ((CV *)*sp == sa_cv_cuckoo_check && SA_IS(self, sa_stash_cuckoo)) {
Branch: 5 branches
BranchTrueFalseTotal
if ((CV *)*sp == sa_cv_cuckoo_check && SA_IS(self, sa_stash_cuckoo)) { 87052 0 87052
if ((CV *)*sp == sa_cv_cuckoo_check && SA_IS(self, sa_stash_cuckoo)) { 0 87052 87052
if ((CV *)*sp == sa_cv_cuckoo_check && SA_IS(self, sa_stash_cuckoo)) { 0 87052 87052
if ((CV *)*sp == sa_cv_cuckoo_check && SA_IS(self, sa_stash_cuckoo)) { 0 87052 87052
if ((CV *)*sp == sa_cv_cuckoo_check && SA_IS(self, sa_stash_cuckoo)) { 0 87052 87052
533 87052 sa_cuckoo *ck = SA_XOP_PTR(sa_cuckoo *);
534 87052 ▶ if (!ck) goto delegate;
Branch: 1 branch
BranchTrueFalseTotal
if (!ck) goto delegate; 0 87052 87052
535 87052 k = SvPV(mark[2], klen);
536 87052 ▶ SA_XOP_RETURN_IV(1, sa_cuckoo_check(ck, k, (uint32_t)klen));
Branch: 1 branch
BranchTrueFalseTotal
SA_XOP_RETURN_IV(1, sa_cuckoo_check(ck, k, (uint32_t)klen)); 87052 0 87052
537 }
538  
539 0 SA_XOP_DELEGATE();
540 }
541  
542 1675 static OP *sa_pp_hist_record(pTHX) {
543 1675 dSP;
544 {
545 1675 ▶ SA_XOP_SELF(sa_cv_hist_record, sa_stash_hist, 1);
Branch: 7 branches
BranchTrueFalseTotal
SA_XOP_SELF(sa_cv_hist_record, sa_stash_hist, 1); 0 1675 1675
SA_XOP_SELF(sa_cv_hist_record, sa_stash_hist, 1); 1675 0 1675
SA_XOP_SELF(sa_cv_hist_record, sa_stash_hist, 1); 0 1675 1675
SA_XOP_SELF(sa_cv_hist_record, sa_stash_hist, 1); 1675 0 1675
SA_XOP_SELF(sa_cv_hist_record, sa_stash_hist, 1); 1675 0 1675
SA_XOP_SELF(sa_cv_hist_record, sa_stash_hist, 1); 1675 0 1675
SA_XOP_SELF(sa_cv_hist_record, sa_stash_hist, 1); 0 1675 1675
546 {
547 1675 sa_hist *h = SA_XOP_PTR(sa_hist *);
548 1675 ▶ if (!h) goto delegate;
Branch: 1 branch
BranchTrueFalseTotal
if (!h) goto delegate; 0 1675 1675
549 1675 sa_hist_record(h, (uint64_t)SvUV(mark[2]), 1);
550 /* record returns nothing, so the op must leave the stack the way
551 * a void XSUB would - which is not quite empty: see SA_XOP_VOID. */
552 1675 ▶ SA_XOP_VOID(1);
Branch: 1 branch
BranchTrueFalseTotal
SA_XOP_VOID(1); 3 1672 1675
553 }
554 }
555 0 SA_XOP_DELEGATE();
556 }
557  
558 2882 static OP *sa_pp_ring_publish(pTHX) {
559 2882 dSP;
560 {
561 2882 ▶ SA_XOP_SELF(sa_cv_ring_publish, sa_stash_ring, 2);
Branch: 7 branches
BranchTrueFalseTotal
SA_XOP_SELF(sa_cv_ring_publish, sa_stash_ring, 2); 0 2882 2882
SA_XOP_SELF(sa_cv_ring_publish, sa_stash_ring, 2); 2882 0 2882
SA_XOP_SELF(sa_cv_ring_publish, sa_stash_ring, 2); 0 2882 2882
SA_XOP_SELF(sa_cv_ring_publish, sa_stash_ring, 2); 2882 0 2882
SA_XOP_SELF(sa_cv_ring_publish, sa_stash_ring, 2); 2882 0 2882
SA_XOP_SELF(sa_cv_ring_publish, sa_stash_ring, 2); 2882 0 2882
SA_XOP_SELF(sa_cv_ring_publish, sa_stash_ring, 2); 0 2882 2882
562 {
563 2882 sa_ring *r = SA_XOP_PTR(sa_ring *);
564 STRLEN tlen, plen;
565 const char *t, *p;
566 2882 uint64_t seq = 0;
567 int rc;
568 2882 ▶ if (!r) goto delegate;
Branch: 1 branch
BranchTrueFalseTotal
if (!r) goto delegate; 0 2882 2882
569 2882 t = SvPV(mark[2], tlen);
570 2882 ▶ p = SvPV(mark[3], plen);
Branch: 1 branch
BranchTrueFalseTotal
p = SvPV(mark[3], plen); 2568 314 2882
571 2882 rc = sa_ring_publish(r, t, (uint32_t)tlen, p, (uint32_t)plen, &seq);
572 2882 ▶ SA_XOP_RETURN_IV(2,
Branch: 2 branches
BranchTrueFalseTotal
SA_XOP_RETURN_IV(2, 2882 0 2882
SA_XOP_RETURN_IV(2, 5 2877 2882
573 rc == SA_PUB_OK ? (IV)seq : (IV)rc);
574 }
575 }
576 0 SA_XOP_DELEGATE();
577 }
578  
579 /* A limiter is asked once per request, so the guard runs on a door whose own
580 * work is a couple of atomics. Without atomics the XSUB allows everything
581 * rather than refusing good requests, and this says the same thing. */
582 8401 static OP *sa_pp_rate_allow(pTHX) {
583 8401 dSP;
584 {
585 8401 ▶ SA_XOP_SELF(sa_cv_rate_allow, sa_stash_rate, 1);
Branch: 7 branches
BranchTrueFalseTotal
SA_XOP_SELF(sa_cv_rate_allow, sa_stash_rate, 1); 0 8401 8401
SA_XOP_SELF(sa_cv_rate_allow, sa_stash_rate, 1); 8401 0 8401
SA_XOP_SELF(sa_cv_rate_allow, sa_stash_rate, 1); 0 8401 8401
SA_XOP_SELF(sa_cv_rate_allow, sa_stash_rate, 1); 8401 0 8401
SA_XOP_SELF(sa_cv_rate_allow, sa_stash_rate, 1); 8401 0 8401
SA_XOP_SELF(sa_cv_rate_allow, sa_stash_rate, 1); 8401 0 8401
SA_XOP_SELF(sa_cv_rate_allow, sa_stash_rate, 1); 0 8401 8401
586 {
587 8401 sa_rate *rl = SA_XOP_PTR(sa_rate *);
588 STRLEN klen;
589 const char *k;
590 int ok;
591 8401 ▶ if (!rl) goto delegate;
Branch: 1 branch
BranchTrueFalseTotal
if (!rl) goto delegate; 0 8401 8401
592 8401 k = SvPV(mark[2], klen);
593 #if SA_HAVE_ATOMICS
594 8401 ok = sa_rate_take(rl, k, (uint32_t)klen,
595 (uint64_t)SA_RATE_SCALE, 0, NULL, NULL);
596 #else
597 ok = 1;
598 #endif
599 8401 ▶ SA_XOP_RETURN_IV(1, ok);
Branch: 1 branch
BranchTrueFalseTotal
SA_XOP_RETURN_IV(1, ok); 8401 0 8401
600 }
601 }
602 0 SA_XOP_DELEGATE();
603 }
604  
605 /* A sketch is added to once per event and asked once per report, so `add` is as
606 * hot as anything in the dist. Both return the counter's new or current value,
607 * which is the one estimate a caller wants without a second call. */
608 /* `add` is a name THREE of this dist's own classes answer to, so one door has
609 * to cover them all. The method op resolves whichever class the invocant is, and the
610 * entersub door below tells them apart by the CV the method op pushed - which
611 * is the same identity check that keeps a monkeypatch working, doing a second
612 * job here for free.
613 *
614 * Without this the first entry in the hook table would win the name outright
615 * and the other class would silently lose its fast path, which is exactly the
616 * failure two SEPARATE dists hit and is no more acceptable for being internal. */
617 1323327 static OP *sa_pp_meth_add(pTHX) {
618 1323327 dSP;
619 1323327 SV **mark = PL_stack_base + TOPMARK;
620 SV *self;
621 1323327 CV *cv = NULL;
622 1323327 ▶ if (sp <= mark) return PL_ppaddr[OP_METHOD_NAMED](aTHX);
Branch: 1 branch
BranchTrueFalseTotal
if (sp <= mark) return PL_ppaddr[OP_METHOD_NAMED](aTHX); 0 1323327 1323327
623 1323327 self = mark[1];
624 1323327 ▶ if (SA_IS(self, sa_stash_bloom) && sa_gv_bloom_add)
Branch: 5 branches
BranchTrueFalseTotal
if (SA_IS(self, sa_stash_bloom) && sa_gv_bloom_add) 1323327 0 1323327
if (SA_IS(self, sa_stash_bloom) && sa_gv_bloom_add) 1323327 0 1323327
if (SA_IS(self, sa_stash_bloom) && sa_gv_bloom_add) 1323327 0 1323327
if (SA_IS(self, sa_stash_bloom) && sa_gv_bloom_add) 25617 1297710 1323327
if (SA_IS(self, sa_stash_bloom) && sa_gv_bloom_add) 25617 0 25617
625 25617 cv = GvCV(sa_gv_bloom_add);
626 1297710 ▶ else if (SA_IS(self, sa_stash_cms) && sa_gv_cms_add)
Branch: 5 branches
BranchTrueFalseTotal
else if (SA_IS(self, sa_stash_cms) && sa_gv_cms_add) 1297710 0 1297710
else if (SA_IS(self, sa_stash_cms) && sa_gv_cms_add) 1297710 0 1297710
else if (SA_IS(self, sa_stash_cms) && sa_gv_cms_add) 1297710 0 1297710
else if (SA_IS(self, sa_stash_cms) && sa_gv_cms_add) 148423 1149287 1297710
else if (SA_IS(self, sa_stash_cms) && sa_gv_cms_add) 148423 0 148423
627 148423 cv = GvCV(sa_gv_cms_add);
628 1149287 ▶ else if (SA_IS(self, sa_stash_cuckoo) && sa_gv_cuckoo_add)
Branch: 5 branches
BranchTrueFalseTotal
else if (SA_IS(self, sa_stash_cuckoo) && sa_gv_cuckoo_add) 1149287 0 1149287
else if (SA_IS(self, sa_stash_cuckoo) && sa_gv_cuckoo_add) 1149287 0 1149287
else if (SA_IS(self, sa_stash_cuckoo) && sa_gv_cuckoo_add) 1149287 0 1149287
else if (SA_IS(self, sa_stash_cuckoo) && sa_gv_cuckoo_add) 40370 1108917 1149287
else if (SA_IS(self, sa_stash_cuckoo) && sa_gv_cuckoo_add) 40370 0 40370
629 40370 cv = GvCV(sa_gv_cuckoo_add);
630 1323327 ▶ if (!cv) return PL_ppaddr[OP_METHOD_NAMED](aTHX);
Branch: 1 branch
BranchTrueFalseTotal
if (!cv) return PL_ppaddr[OP_METHOD_NAMED](aTHX); 1108917 214410 1323327
631 214410 ▶ XPUSHs((SV *)cv);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs((SV *)cv); 0 214410 214410
632 214410 PUTBACK;
633 214410 return NORMAL;
634 }
635  
636 1323316 static OP *sa_pp_add(pTHX) {
637 1323316 dSP;
638 1323316 SV **mark = PL_stack_base + TOPMARK;
639 SV *self;
640 STRLEN klen;
641 const char *k;
642  
643 1323316 ▶ if (sp - mark != 3) goto delegate;
Branch: 1 branch
BranchTrueFalseTotal
if (sp - mark != 3) goto delegate; 0 1323316 1323316
644 1323316 self = mark[1];
645  
646 1323316 ▶ if ((CV *)*sp == sa_cv_bloom_add && SA_IS(self, sa_stash_bloom)) {
Branch: 5 branches
BranchTrueFalseTotal
if ((CV *)*sp == sa_cv_bloom_add && SA_IS(self, sa_stash_bloom)) { 25616 1297700 1323316
if ((CV *)*sp == sa_cv_bloom_add && SA_IS(self, sa_stash_bloom)) { 25616 0 25616
if ((CV *)*sp == sa_cv_bloom_add && SA_IS(self, sa_stash_bloom)) { 25616 0 25616
if ((CV *)*sp == sa_cv_bloom_add && SA_IS(self, sa_stash_bloom)) { 25616 0 25616
if ((CV *)*sp == sa_cv_bloom_add && SA_IS(self, sa_stash_bloom)) { 25616 0 25616
647 25616 sa_bloom *b = SA_XOP_PTR(sa_bloom *);
648 25616 ▶ if (!b) goto delegate;
Branch: 1 branch
BranchTrueFalseTotal
if (!b) goto delegate; 0 25616 25616
649 25616 k = SvPV(mark[2], klen);
650 25616 ▶ SA_XOP_RETURN_IV(1, sa_bloom_add(b, k, (uint32_t)klen));
Branch: 1 branch
BranchTrueFalseTotal
SA_XOP_RETURN_IV(1, sa_bloom_add(b, k, (uint32_t)klen)); 25616 0 25616
651 }
652 1297700 ▶ if ((CV *)*sp == sa_cv_cms_add && SA_IS(self, sa_stash_cms)) {
Branch: 5 branches
BranchTrueFalseTotal
if ((CV *)*sp == sa_cv_cms_add && SA_IS(self, sa_stash_cms)) { 148413 1149287 1297700
if ((CV *)*sp == sa_cv_cms_add && SA_IS(self, sa_stash_cms)) { 148413 0 148413
if ((CV *)*sp == sa_cv_cms_add && SA_IS(self, sa_stash_cms)) { 148413 0 148413
if ((CV *)*sp == sa_cv_cms_add && SA_IS(self, sa_stash_cms)) { 148413 0 148413
if ((CV *)*sp == sa_cv_cms_add && SA_IS(self, sa_stash_cms)) { 148413 0 148413
653 148413 sa_cms *cm = SA_XOP_PTR(sa_cms *);
654 148413 ▶ if (!cm) goto delegate;
Branch: 1 branch
BranchTrueFalseTotal
if (!cm) goto delegate; 0 148413 148413
655 148413 k = SvPV(mark[2], klen);
656 148413 ▶ SA_XOP_RETURN_UV(1, (UV)sa_cms_add(cm, k, (uint32_t)klen, 1));
Branch: 1 branch
BranchTrueFalseTotal
SA_XOP_RETURN_UV(1, (UV)sa_cms_add(cm, k, (uint32_t)klen, 1)); 148413 0 148413
657 }
658 1149287 ▶ if ((CV *)*sp == sa_cv_cuckoo_add && SA_IS(self, sa_stash_cuckoo)) {
Branch: 5 branches
BranchTrueFalseTotal
if ((CV *)*sp == sa_cv_cuckoo_add && SA_IS(self, sa_stash_cuckoo)) { 40370 1108917 1149287
if ((CV *)*sp == sa_cv_cuckoo_add && SA_IS(self, sa_stash_cuckoo)) { 0 40370 40370
if ((CV *)*sp == sa_cv_cuckoo_add && SA_IS(self, sa_stash_cuckoo)) { 0 40370 40370
if ((CV *)*sp == sa_cv_cuckoo_add && SA_IS(self, sa_stash_cuckoo)) { 0 40370 40370
if ((CV *)*sp == sa_cv_cuckoo_add && SA_IS(self, sa_stash_cuckoo)) { 0 40370 40370
659 40370 sa_cuckoo *ck = SA_XOP_PTR(sa_cuckoo *);
660 40370 ▶ if (!ck) goto delegate;
Branch: 1 branch
BranchTrueFalseTotal
if (!ck) goto delegate; 0 40370 40370
661 40370 k = SvPV(mark[2], klen);
662 40370 ▶ SA_XOP_RETURN_IV(1, sa_cuckoo_add(ck, k, (uint32_t)klen));
Branch: 1 branch
BranchTrueFalseTotal
SA_XOP_RETURN_IV(1, sa_cuckoo_add(ck, k, (uint32_t)klen)); 40370 0 40370
663 }
664  
665 1108917 SA_XOP_DELEGATE();
666 }
667  
668 3521 static OP *sa_pp_cms_estimate(pTHX) {
669 3521 dSP;
670 {
671 3521 ▶ SA_XOP_SELF(sa_cv_cms_estimate, sa_stash_cms, 1);
Branch: 7 branches
BranchTrueFalseTotal
SA_XOP_SELF(sa_cv_cms_estimate, sa_stash_cms, 1); 0 3521 3521
SA_XOP_SELF(sa_cv_cms_estimate, sa_stash_cms, 1); 3521 0 3521
SA_XOP_SELF(sa_cv_cms_estimate, sa_stash_cms, 1); 0 3521 3521
SA_XOP_SELF(sa_cv_cms_estimate, sa_stash_cms, 1); 3521 0 3521
SA_XOP_SELF(sa_cv_cms_estimate, sa_stash_cms, 1); 3521 0 3521
SA_XOP_SELF(sa_cv_cms_estimate, sa_stash_cms, 1); 3521 0 3521
SA_XOP_SELF(sa_cv_cms_estimate, sa_stash_cms, 1); 0 3521 3521
672 {
673 3521 sa_cms *cm = SA_XOP_PTR(sa_cms *);
674 STRLEN klen;
675 const char *k;
676 3521 ▶ if (!cm) goto delegate;
Branch: 1 branch
BranchTrueFalseTotal
if (!cm) goto delegate; 0 3521 3521
677 3521 k = SvPV(mark[2], klen);
678 3521 ▶ SA_XOP_RETURN_UV(1,
Branch: 1 branch
BranchTrueFalseTotal
SA_XOP_RETURN_UV(1, 3521 0 3521
679 (UV)sa_cms_estimate(cm, k, (uint32_t)klen));
680 }
681 }
682 0 SA_XOP_DELEGATE();
683 }
684  
685 /* ---- the other widths of the same doors ------------------------------------
686 *
687 * An optional argument used to send the call the ordinary way, on the
688 * reasoning that a guard coping with any stack shape stops being cheap. It
689 * would, so each width is its own door instead, compiled only at a call site
690 * with exactly that many arguments and counted again at runtime. Measured
691 * before, on an M-series Mac, the hooked width against the same door with its
692 * optional argument:
693 *
694 * map->incr($k) / ($k, $by) 26.2 / 40.4 ns
695 * cache->set($k, $v) / (..., ttl => N) 31.2 / 42.8
696 * hist->record($v) / ($v, $n) 13.5 / 30.3
697 * rate->allow($k) / ($k, $cost) 28.6 / 37.5
698 * countmin->add($k) / ($k, $n) 25.0 / 33.4
699 *
700 * Each shares the method op of the narrower width, which pushes the same CV
701 * whatever the width. Arguments are read in the order the XSUB reads them, so
702 * a tied one is fetched the same number of times either way. */
703  
704 149 static OP *sa_pp_map_incr_by(pTHX) {
705 149 dSP;
706 {
707 149 ▶ SA_XOP_SELF(sa_cv_map_incr, sa_stash_map, 2);
Branch: 7 branches
BranchTrueFalseTotal
SA_XOP_SELF(sa_cv_map_incr, sa_stash_map, 2); 0 149 149
SA_XOP_SELF(sa_cv_map_incr, sa_stash_map, 2); 149 0 149
SA_XOP_SELF(sa_cv_map_incr, sa_stash_map, 2); 18 131 149
SA_XOP_SELF(sa_cv_map_incr, sa_stash_map, 2); 131 0 131
SA_XOP_SELF(sa_cv_map_incr, sa_stash_map, 2); 131 0 131
SA_XOP_SELF(sa_cv_map_incr, sa_stash_map, 2); 131 0 131
SA_XOP_SELF(sa_cv_map_incr, sa_stash_map, 2); 0 131 131
708 {
709 131 sa_hash *m = SA_XOP_PTR(sa_hash *);
710 STRLEN klen;
711 const char *k;
712 IV by;
713 131 uint64_t now = 0;
714 131 ▶ if (!m) goto delegate;
Branch: 1 branch
BranchTrueFalseTotal
if (!m) goto delegate; 0 131 131
715 131 ▶ if (m->serialise) croak(SA_SER_INCR_MSG);
Branch: 1 branch
BranchTrueFalseTotal
if (m->serialise) croak(SA_SER_INCR_MSG); 1 130 131
716 130 k = SvPV(mark[2], klen);
717 130 by = SvIV(mark[3]);
718 130 ▶ if (sa_hash_incr(m, k, (uint32_t)klen, (int64_t)by, &now) != SA_H_OK)
Branch: 1 branch
BranchTrueFalseTotal
if (sa_hash_incr(m, k, (uint32_t)klen, (int64_t)by, &now) != SA_H_OK) 0 130 130
719 130 SA_XOP_RETURN(2, &PL_sv_undef);
720 130 ▶ SA_XOP_RETURN_UV(2, (UV)now);
Branch: 1 branch
BranchTrueFalseTotal
SA_XOP_RETURN_UV(2, (UV)now); 130 0 130
721 }
722 }
723 18 SA_XOP_DELEGATE();
724 }
725  
726 /* `set($k, $v, ttl => N)` and its `ttl_ms` spelling. Any other option name is
727 * the XSUB's to handle, so the door looks at the name before touching anything
728 * else and steps aside for one it does not know. */
729 10 static OP *sa_pp_cache_set_ttl(pTHX) {
730 10 dSP;
731 {
732 10 ▶ SA_XOP_SELF(sa_cv_cache_set, sa_stash_cache, 4);
Branch: 7 branches
BranchTrueFalseTotal
SA_XOP_SELF(sa_cv_cache_set, sa_stash_cache, 4); 0 10 10
SA_XOP_SELF(sa_cv_cache_set, sa_stash_cache, 4); 10 0 10
SA_XOP_SELF(sa_cv_cache_set, sa_stash_cache, 4); 0 10 10
SA_XOP_SELF(sa_cv_cache_set, sa_stash_cache, 4); 10 0 10
SA_XOP_SELF(sa_cv_cache_set, sa_stash_cache, 4); 10 0 10
SA_XOP_SELF(sa_cv_cache_set, sa_stash_cache, 4); 10 0 10
SA_XOP_SELF(sa_cv_cache_set, sa_stash_cache, 4); 0 10 10
733 {
734 10 sa_cache *c = SA_XOP_PTR(sa_cache *);
735 10 SV *opt = mark[4];
736 STRLEN klen, vlen;
737 const char *k, *v;
738 int ms, rc;
739 UV ttl;
740 char sbuf[SA_SER_STACK];
741 11 ▶ if (!c) goto delegate;
Branch: 1 branch
BranchTrueFalseTotal
if (!c) goto delegate; 0 10 10
742 10 ▶ if (!SvPOK(opt) || SvGMAGICAL(opt)) goto delegate;
Branch: 2 branches
BranchTrueFalseTotal
if (!SvPOK(opt) || SvGMAGICAL(opt)) goto delegate; 10 0 10
if (!SvPOK(opt) || SvGMAGICAL(opt)) goto delegate; 0 10 10
743 10 ▶ if (SvCUR(opt) == 3 && memEQ(SvPVX(opt), "ttl", 3)) ms = 0;
Branch: 2 branches
BranchTrueFalseTotal
if (SvCUR(opt) == 3 && memEQ(SvPVX(opt), "ttl", 3)) ms = 0; 3 7 10
if (SvCUR(opt) == 3 && memEQ(SvPVX(opt), "ttl", 3)) ms = 0; 3 0 3
744 7 ▶ else if (SvCUR(opt) == 6 && memEQ(SvPVX(opt), "ttl_ms", 6)) ms = 1;
Branch: 2 branches
BranchTrueFalseTotal
else if (SvCUR(opt) == 6 && memEQ(SvPVX(opt), "ttl_ms", 6)) ms = 1; 6 1 7
else if (SvCUR(opt) == 6 && memEQ(SvPVX(opt), "ttl_ms", 6)) ms = 1; 6 0 6
745 1 else goto delegate;
746 9 k = SvPV(mark[2], klen);
747 9 ▶ if (c->serialise) {
Branch: 1 branch
BranchTrueFalseTotal
if (c->serialise) { 1 8 9
748 1 vlen = sa_ser_encode(aTHX_ mark[3], c->pair_max, klen, sbuf, &v);
749 1 SA_XOP_RESYNC();
750 10 ▶ if (!vlen) SA_XOP_RETURN_IV(4, SA_C_TOOBIG);
Branch: 2 branches
BranchTrueFalseTotal
if (!vlen) SA_XOP_RETURN_IV(4, SA_C_TOOBIG); 0 1 1
if (!vlen) SA_XOP_RETURN_IV(4, SA_C_TOOBIG); 0 0 0
751 }
752 else
753 16 v = SvPV(mark[3], vlen);
754 9 ▶ ttl = ms ? SvUV(mark[5]) : (UV)(SvNV(mark[5]) * 1000.0);
Branch: 1 branch
BranchTrueFalseTotal
ttl = ms ? SvUV(mark[5]) : (UV)(SvNV(mark[5]) * 1000.0); 6 3 9
755 9 rc = sa_cache_set(c, k, (uint32_t)klen, v, (uint32_t)vlen,
756 (uint64_t)ttl);
757 9 ▶ SA_XOP_RETURN_IV(4, rc);
Branch: 1 branch
BranchTrueFalseTotal
SA_XOP_RETURN_IV(4, rc); 9 0 9
758 }
759 }
760 1 SA_XOP_DELEGATE();
761 }
762  
763 4 static OP *sa_pp_hist_record_n(pTHX) {
764 4 dSP;
765 {
766 4 ▶ SA_XOP_SELF(sa_cv_hist_record, sa_stash_hist, 2);
Branch: 7 branches
BranchTrueFalseTotal
SA_XOP_SELF(sa_cv_hist_record, sa_stash_hist, 2); 0 4 4
SA_XOP_SELF(sa_cv_hist_record, sa_stash_hist, 2); 4 0 4
SA_XOP_SELF(sa_cv_hist_record, sa_stash_hist, 2); 0 4 4
SA_XOP_SELF(sa_cv_hist_record, sa_stash_hist, 2); 4 0 4
SA_XOP_SELF(sa_cv_hist_record, sa_stash_hist, 2); 4 0 4
SA_XOP_SELF(sa_cv_hist_record, sa_stash_hist, 2); 4 0 4
SA_XOP_SELF(sa_cv_hist_record, sa_stash_hist, 2); 0 4 4
767 {
768 4 sa_hist *h = SA_XOP_PTR(sa_hist *);
769 UV v, n;
770 4 ▶ if (!h) goto delegate;
Branch: 1 branch
BranchTrueFalseTotal
if (!h) goto delegate; 0 4 4
771 4 v = SvUV(mark[2]);
772 4 n = SvUV(mark[3]);
773 4 sa_hist_record(h, (uint64_t)v, (uint64_t)n);
774 4 ▶ SA_XOP_VOID(2);
Branch: 1 branch
BranchTrueFalseTotal
SA_XOP_VOID(2); 3 1 4
775 }
776 }
777 0 SA_XOP_DELEGATE();
778 }
779  
780 19 static OP *sa_pp_rate_allow_cost(pTHX) {
781 19 dSP;
782 {
783 19 ▶ SA_XOP_SELF(sa_cv_rate_allow, sa_stash_rate, 2);
Branch: 7 branches
BranchTrueFalseTotal
SA_XOP_SELF(sa_cv_rate_allow, sa_stash_rate, 2); 0 19 19
SA_XOP_SELF(sa_cv_rate_allow, sa_stash_rate, 2); 19 0 19
SA_XOP_SELF(sa_cv_rate_allow, sa_stash_rate, 2); 0 19 19
SA_XOP_SELF(sa_cv_rate_allow, sa_stash_rate, 2); 19 0 19
SA_XOP_SELF(sa_cv_rate_allow, sa_stash_rate, 2); 19 0 19
SA_XOP_SELF(sa_cv_rate_allow, sa_stash_rate, 2); 19 0 19
SA_XOP_SELF(sa_cv_rate_allow, sa_stash_rate, 2); 0 19 19
784 {
785 19 sa_rate *rl = SA_XOP_PTR(sa_rate *);
786 STRLEN klen;
787 const char *k;
788 UV cost;
789 int ok;
790 19 ▶ if (!rl) goto delegate;
Branch: 1 branch
BranchTrueFalseTotal
if (!rl) goto delegate; 0 19 19
791 19 cost = SvUV(mark[3]);
792 19 ▶ if (cost < 1) cost = 1;
Branch: 1 branch
BranchTrueFalseTotal
if (cost < 1) cost = 1; 0 19 19
793 19 k = SvPV(mark[2], klen);
794 #if SA_HAVE_ATOMICS
795 19 ok = sa_rate_take(rl, k, (uint32_t)klen,
796 (uint64_t)cost * SA_RATE_SCALE, 0, NULL, NULL);
797 #else
798 PERL_UNUSED_VAR(k);
799 ok = 1;
800 #endif
801 19 ▶ SA_XOP_RETURN_IV(2, ok);
Branch: 1 branch
BranchTrueFalseTotal
SA_XOP_RETURN_IV(2, ok); 19 0 19
802 }
803 }
804 0 SA_XOP_DELEGATE();
805 }
806  
807 /* `add($k, $n)` is the sketch's alone: the filters take one argument, so a
808 * filter at this width gets the ordinary call and its ordinary usage error. */
809 11 static OP *sa_pp_add_n(pTHX) {
810 11 dSP;
811 11 SV **mark = PL_stack_base + TOPMARK;
812 SV *self;
813  
814 11 ▶ if (sp - mark != 4) goto delegate;
Branch: 1 branch
BranchTrueFalseTotal
if (sp - mark != 4) goto delegate; 0 11 11
815 11 self = mark[1];
816  
817 11 ▶ if ((CV *)*sp == sa_cv_cms_add && SA_IS(self, sa_stash_cms)) {
Branch: 5 branches
BranchTrueFalseTotal
if ((CV *)*sp == sa_cv_cms_add && SA_IS(self, sa_stash_cms)) { 10 1 11
if ((CV *)*sp == sa_cv_cms_add && SA_IS(self, sa_stash_cms)) { 0 10 10
if ((CV *)*sp == sa_cv_cms_add && SA_IS(self, sa_stash_cms)) { 0 10 10
if ((CV *)*sp == sa_cv_cms_add && SA_IS(self, sa_stash_cms)) { 0 10 10
if ((CV *)*sp == sa_cv_cms_add && SA_IS(self, sa_stash_cms)) { 0 10 10
818 10 sa_cms *cm = SA_XOP_PTR(sa_cms *);
819 STRLEN klen;
820 const char *k;
821 UV n;
822 10 ▶ if (!cm) goto delegate;
Branch: 1 branch
BranchTrueFalseTotal
if (!cm) goto delegate; 0 10 10
823 10 n = SvUV(mark[3]);
824 10 ▶ if (n < 1) n = 1;
Branch: 1 branch
BranchTrueFalseTotal
if (n < 1) n = 1; 0 10 10
825 10 k = SvPV(mark[2], klen);
826 #if SA_HAVE_ATOMICS
827 10 ▶ SA_XOP_RETURN_UV(2, (UV)sa_cms_add(cm, k, (uint32_t)klen, (uint64_t)n));
Branch: 1 branch
BranchTrueFalseTotal
SA_XOP_RETURN_UV(2, (UV)sa_cms_add(cm, k, (uint32_t)klen, (uint64_t)n)); 10 0 10
828 #else
829 PERL_UNUSED_VAR(k);
830 SA_XOP_RETURN_UV(2, 0);
831 #endif
832 }
833  
834 1 SA_XOP_DELEGATE();
835 }
836  
837 /* ---- the rest of a request's rate limiting, and a counter read ---------------
838 *
839 * A handler that sets X-RateLimit headers asks `remaining` on every request and
840 * `retry_after` on every refusal, beside the `allow` that was already an op;
841 * both were ordinary calls at 34ns. `counter` reads a Map counter without
842 * changing it, at 38.5ns. None of the three is a common method name, so what
843 * the hook costs other classes' call sites is close to nothing. */
844 67 ▶SA_XOP_METH(rate_remaining, sa_stash_rate)
Branch: 8 branches
BranchTrueFalseTotal
SA_XOP_METH(rate_remaining, sa_stash_rate) 0 67 67
SA_XOP_METH(rate_remaining, sa_stash_rate) 67 0 67
SA_XOP_METH(rate_remaining, sa_stash_rate) 67 0 67
SA_XOP_METH(rate_remaining, sa_stash_rate) 67 0 67
SA_XOP_METH(rate_remaining, sa_stash_rate) 0 67 67
SA_XOP_METH(rate_remaining, sa_stash_rate) 67 0 67
SA_XOP_METH(rate_remaining, sa_stash_rate) 0 67 67
SA_XOP_METH(rate_remaining, sa_stash_rate) 0 67 67
845 12 ▶SA_XOP_METH(rate_retry_after, sa_stash_rate)
Branch: 8 branches
BranchTrueFalseTotal
SA_XOP_METH(rate_retry_after, sa_stash_rate) 0 12 12
SA_XOP_METH(rate_retry_after, sa_stash_rate) 12 0 12
SA_XOP_METH(rate_retry_after, sa_stash_rate) 12 0 12
SA_XOP_METH(rate_retry_after, sa_stash_rate) 12 0 12
SA_XOP_METH(rate_retry_after, sa_stash_rate) 0 12 12
SA_XOP_METH(rate_retry_after, sa_stash_rate) 12 0 12
SA_XOP_METH(rate_retry_after, sa_stash_rate) 0 12 12
SA_XOP_METH(rate_retry_after, sa_stash_rate) 0 12 12
846 291 ▶SA_XOP_METH(map_counter, sa_stash_map)
Branch: 8 branches
BranchTrueFalseTotal
SA_XOP_METH(map_counter, sa_stash_map) 0 291 291
SA_XOP_METH(map_counter, sa_stash_map) 291 0 291
SA_XOP_METH(map_counter, sa_stash_map) 291 0 291
SA_XOP_METH(map_counter, sa_stash_map) 291 0 291
SA_XOP_METH(map_counter, sa_stash_map) 0 291 291
SA_XOP_METH(map_counter, sa_stash_map) 291 0 291
SA_XOP_METH(map_counter, sa_stash_map) 0 291 291
SA_XOP_METH(map_counter, sa_stash_map) 0 291 291
847  
848 67 static OP *sa_pp_rate_remaining(pTHX) {
849 67 dSP;
850 {
851 67 ▶ SA_XOP_SELF(sa_cv_rate_remaining, sa_stash_rate, 1);
Branch: 7 branches
BranchTrueFalseTotal
SA_XOP_SELF(sa_cv_rate_remaining, sa_stash_rate, 1); 0 67 67
SA_XOP_SELF(sa_cv_rate_remaining, sa_stash_rate, 1); 67 0 67
SA_XOP_SELF(sa_cv_rate_remaining, sa_stash_rate, 1); 0 67 67
SA_XOP_SELF(sa_cv_rate_remaining, sa_stash_rate, 1); 67 0 67
SA_XOP_SELF(sa_cv_rate_remaining, sa_stash_rate, 1); 67 0 67
SA_XOP_SELF(sa_cv_rate_remaining, sa_stash_rate, 1); 67 0 67
SA_XOP_SELF(sa_cv_rate_remaining, sa_stash_rate, 1); 0 67 67
852 {
853 67 sa_rate *rl = SA_XOP_PTR(sa_rate *);
854 STRLEN klen;
855 const char *k;
856 67 uint64_t left = 0;
857 67 ▶ if (!rl) goto delegate;
Branch: 1 branch
BranchTrueFalseTotal
if (!rl) goto delegate; 0 67 67
858 67 k = SvPV(mark[2], klen);
859 #if SA_HAVE_ATOMICS
860 67 (void)sa_rate_take(rl, k, (uint32_t)klen,
861 (uint64_t)SA_RATE_SCALE, 1, &left, NULL);
862 #else
863 PERL_UNUSED_VAR(k);
864 #endif
865 67 ▶ SA_XOP_RETURN_NV(1, (NV)left / (NV)SA_RATE_SCALE);
Branch: 1 branch
BranchTrueFalseTotal
SA_XOP_RETURN_NV(1, (NV)left / (NV)SA_RATE_SCALE); 67 0 67
866 }
867 }
868 0 SA_XOP_DELEGATE();
869 }
870  
871 12 static OP *sa_pp_rate_retry_after(pTHX) {
872 12 dSP;
873 {
874 12 ▶ SA_XOP_SELF(sa_cv_rate_retry_after, sa_stash_rate, 1);
Branch: 7 branches
BranchTrueFalseTotal
SA_XOP_SELF(sa_cv_rate_retry_after, sa_stash_rate, 1); 0 12 12
SA_XOP_SELF(sa_cv_rate_retry_after, sa_stash_rate, 1); 12 0 12
SA_XOP_SELF(sa_cv_rate_retry_after, sa_stash_rate, 1); 0 12 12
SA_XOP_SELF(sa_cv_rate_retry_after, sa_stash_rate, 1); 12 0 12
SA_XOP_SELF(sa_cv_rate_retry_after, sa_stash_rate, 1); 12 0 12
SA_XOP_SELF(sa_cv_rate_retry_after, sa_stash_rate, 1); 12 0 12
SA_XOP_SELF(sa_cv_rate_retry_after, sa_stash_rate, 1); 0 12 12
875 {
876 12 sa_rate *rl = SA_XOP_PTR(sa_rate *);
877 STRLEN klen;
878 const char *k;
879 12 uint64_t retry = 0;
880 12 ▶ if (!rl) goto delegate;
Branch: 1 branch
BranchTrueFalseTotal
if (!rl) goto delegate; 0 12 12
881 12 k = SvPV(mark[2], klen);
882 #if SA_HAVE_ATOMICS
883 12 (void)sa_rate_take(rl, k, (uint32_t)klen,
884 (uint64_t)SA_RATE_SCALE, 1, NULL, &retry);
885 #else
886 PERL_UNUSED_VAR(k);
887 #endif
888 12 ▶ SA_XOP_RETURN_NV(1, (NV)retry / (NV)1000.0);
Branch: 1 branch
BranchTrueFalseTotal
SA_XOP_RETURN_NV(1, (NV)retry / (NV)1000.0); 12 0 12
889 }
890 }
891 0 SA_XOP_DELEGATE();
892 }
893  
894 291 static OP *sa_pp_map_counter(pTHX) {
895 291 dSP;
896 {
897 291 ▶ SA_XOP_SELF(sa_cv_map_counter, sa_stash_map, 1);
Branch: 7 branches
BranchTrueFalseTotal
SA_XOP_SELF(sa_cv_map_counter, sa_stash_map, 1); 0 291 291
SA_XOP_SELF(sa_cv_map_counter, sa_stash_map, 1); 291 0 291
SA_XOP_SELF(sa_cv_map_counter, sa_stash_map, 1); 0 291 291
SA_XOP_SELF(sa_cv_map_counter, sa_stash_map, 1); 291 0 291
SA_XOP_SELF(sa_cv_map_counter, sa_stash_map, 1); 291 0 291
SA_XOP_SELF(sa_cv_map_counter, sa_stash_map, 1); 291 0 291
SA_XOP_SELF(sa_cv_map_counter, sa_stash_map, 1); 0 291 291
898 {
899 291 sa_hash *m = SA_XOP_PTR(sa_hash *);
900 STRLEN klen;
901 const char *k;
902 char buf[8];
903 291 uint32_t vlen = 0;
904 uint64_t v;
905 291 ▶ if (!m) goto delegate;
Branch: 1 branch
BranchTrueFalseTotal
if (!m) goto delegate; 0 291 291
906 /* Nothing in a serialised map is a counter, whatever its
907 * length: an eight-byte encoding is not a word. */
908 581 ▶ if (m->serialise) SA_XOP_RETURN(1, &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
if (m->serialise) SA_XOP_RETURN(1, &PL_sv_undef); 1 290 291
909 290 k = SvPV(mark[2], klen);
910 290 ▶ if (sa_hash_fetch(m, k, (uint32_t)klen, buf, 8, &vlen) != SA_H_HIT
Branch: 1 branch
BranchTrueFalseTotal
if (sa_hash_fetch(m, k, (uint32_t)klen, buf, 8, &vlen) != SA_H_HIT 88 202 290
911 88 ▶ || vlen != 8)
Branch: 1 branch
BranchTrueFalseTotal
|| vlen != 8) 1 87 88
912 203 SA_XOP_RETURN(1, &PL_sv_undef);
913 87 memcpy(&v, buf, 8);
914 87 ▶ SA_XOP_RETURN_UV(1, (UV)v);
Branch: 1 branch
BranchTrueFalseTotal
SA_XOP_RETURN_UV(1, (UV)v); 87 0 87
915 }
916 }
917 0 SA_XOP_DELEGATE();
918 }
919  
920 /* ---- the whole door in the method op, where the entersub is not ours -------
921 *
922 * Frozen owns the entersub at every one-argument `->get` site, and Frozen is
923 * always loaded, so the cache's main door was only ever half hooked: the
924 * method op pushed our CV, Frozen's entersub stepped aside for it, and
925 * pp_entersub then made an ordinary XSUB call. 55.1ns against 48.8 with both
926 * ops ours.
927 *
928 * A pp function returns the op to run next. So a method op that has already
929 * made the call can return the op AFTER the entersub and skip it entirely,
930 * whoever owns it - which needs no change to the other dist and no side table
931 * keyed by op address. The method op then does the entersub's checking itself:
932 *
933 * - the width, one fewer here because no CV has been pushed yet;
934 * - the identity: the glob's CV against the one captured at BOOT, so a
935 * monkeypatch falls through to the ordinary path and the replacement runs;
936 * - the context, which is the ENTERSUB's. This op's own flags say scalar
937 * whatever the call, so GIMME_V is read with PL_op pointed at the call.
938 *
939 * Anything else falls through to the plain method-op door, which pushes the
940 * CV and lets the entersub, and its owner, carry on as before. Installed only
941 * where the entersub is another dist's; where both ops are ours the two-op door
942 * already has the whole saving. */
943 323 static OP *sa_pp_methdoor_cache_get(pTHX) {
944 323 dSP;
945 323 SV **mark = PL_stack_base + TOPMARK;
946 323 OP *call = PL_op->op_next;
947 323 SV *self, *out = NULL;
948 sa_cache *c;
949 STRLEN klen;
950 const char *k;
951 char buf[1024];
952 323 uint32_t vlen = 0;
953 int hit;
954 U8 gimme;
955  
956 323 ▶ if (sp - mark != 2 || !call || call->op_type != OP_ENTERSUB)
Branch: 3 branches
BranchTrueFalseTotal
if (sp - mark != 2 || !call || call->op_type != OP_ENTERSUB) 321 2 323
if (sp - mark != 2 || !call || call->op_type != OP_ENTERSUB) 321 0 321
if (sp - mark != 2 || !call || call->op_type != OP_ENTERSUB) 0 321 321
957 2 return sa_pp_meth_cache_get(aTHX);
958 321 self = mark[1];
959 321 ▶ if (!SA_IS(self, sa_stash_cache) || !sa_gv_cache_get || !sa_cv_cache_get
Branch: 6 branches
BranchTrueFalseTotal
if (!SA_IS(self, sa_stash_cache) || !sa_gv_cache_get || !sa_cv_cache_get 321 0 321
if (!SA_IS(self, sa_stash_cache) || !sa_gv_cache_get || !sa_cv_cache_get 320 1 321
if (!SA_IS(self, sa_stash_cache) || !sa_gv_cache_get || !sa_cv_cache_get 320 0 320
if (!SA_IS(self, sa_stash_cache) || !sa_gv_cache_get || !sa_cv_cache_get 285 35 320
if (!SA_IS(self, sa_stash_cache) || !sa_gv_cache_get || !sa_cv_cache_get 285 0 285
if (!SA_IS(self, sa_stash_cache) || !sa_gv_cache_get || !sa_cv_cache_get 285 0 285
960 285 ▶ || GvCV(sa_gv_cache_get) != sa_cv_cache_get)
Branch: 1 branch
BranchTrueFalseTotal
|| GvCV(sa_gv_cache_get) != sa_cv_cache_get) 1 284 285
961 37 return sa_pp_meth_cache_get(aTHX);
962 284 c = SA_XOP_PTR(sa_cache *);
963 284 ▶ if (!c) return sa_pp_meth_cache_get(aTHX);
Branch: 1 branch
BranchTrueFalseTotal
if (!c) return sa_pp_meth_cache_get(aTHX); 1 283 284
964  
965 283 k = SvPV(mark[2], klen);
966 /* EVERY one-argument ->get site runs this door, not sa_pp_cache_get,
967 * because Frozen owns those entersubs: without the serialise branch here
968 * a get through the method form would silently hand back bytes. */
969 283 ▶ if (c->pair_max < sizeof buf) {
Branch: 1 branch
BranchTrueFalseTotal
if (c->pair_max < sizeof buf) { 278 5 283
970 278 hit = sa_cache_get(c, k, (uint32_t)klen, buf, (uint32_t)c->pair_max,
971 278 &vlen) == SA_C_HIT;
972 278 ▶ if (hit)
Branch: 1 branch
BranchTrueFalseTotal
if (hit) 256 22 278
973 256 out = c->serialise ? SA_SER_DECODE(buf, vlen)
974 256 ▶ : sv_2mortal(newSVpvn(buf, (STRLEN)vlen));
Branch: 1 branch
BranchTrueFalseTotal
: sv_2mortal(newSVpvn(buf, (STRLEN)vlen)); 9 247 256
975 }
976 else {
977 5 out = sv_2mortal(newSV((STRLEN)c->pair_max + 1));
978 5 SvPOK_on(out);
979 10 hit = sa_cache_get(c, k, (uint32_t)klen, SvPVX(out),
980 5 (uint32_t)c->pair_max, &vlen) == SA_C_HIT;
981 5 ▶ if (hit) {
Branch: 1 branch
BranchTrueFalseTotal
if (hit) { 3 2 5
982 3 ▶ if (c->serialise) out = SA_SER_DECODE(SvPVX(out), vlen);
Branch: 1 branch
BranchTrueFalseTotal
if (c->serialise) out = SA_SER_DECODE(SvPVX(out), vlen); 1 2 3
983 2 else { SvCUR_set(out, (STRLEN)vlen); SvPVX(out)[vlen] = '\0'; }
984 }
985 }
986 /* A decode may have run Perl; see SA_XOP_RESYNC. Unconditional, because
987 * it is two loads and the branch would cost the same. */
988 283 SA_XOP_RESYNC();
989  
990 {
991 283 OP *was = PL_op;
992 283 PL_op = call;
993 283 gimme = GIMME_V;
994 283 PL_op = was;
995 }
996 283 (void)POPMARK;
997 283 sp = mark;
998 283 ▶ if (hit) PUSHs(out);
Branch: 1 branch
BranchTrueFalseTotal
if (hit) PUSHs(out); 259 24 283
999 24 ▶ else if (gimme != SA_G_LIST) PUSHs(&PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
else if (gimme != SA_G_LIST) PUSHs(&PL_sv_undef); 15 9 24
1000 283 PUTBACK;
1001 283 sa_xop_hits++;
1002 283 return call->op_next;
1003 }
1004  
1005 /* ---- the check hook -------------------------------------------------------- */
1006  
1007 205157 static int sa_xop_is_ours(Perl_ppaddr_t p) {
1008 205157 ▶ return p == sa_pp_cache_get || p == sa_pp_cache_set
Branch: 1 branch
BranchTrueFalseTotal
return p == sa_pp_cache_get || p == sa_pp_cache_set 205157 0 205157
1009 205157 ▶ || p == sa_pp_map_fetch || p == sa_pp_map_store
Branch: 2 branches
BranchTrueFalseTotal
|| p == sa_pp_map_fetch || p == sa_pp_map_store 205157 0 205157
|| p == sa_pp_map_fetch || p == sa_pp_map_store 205157 0 205157
1010 205157 ▶ || p == sa_pp_map_incr || p == sa_pp_map_exists
Branch: 2 branches
BranchTrueFalseTotal
|| p == sa_pp_map_incr || p == sa_pp_map_exists 205157 0 205157
|| p == sa_pp_map_incr || p == sa_pp_map_exists 205157 0 205157
1011 205157 ▶ || p == sa_pp_check || p == sa_pp_meth_check
Branch: 2 branches
BranchTrueFalseTotal
|| p == sa_pp_check || p == sa_pp_meth_check 205157 0 205157
|| p == sa_pp_check || p == sa_pp_meth_check 205157 0 205157
1012 205157 ▶ || p == sa_pp_hist_record || p == sa_pp_ring_publish
Branch: 2 branches
BranchTrueFalseTotal
|| p == sa_pp_hist_record || p == sa_pp_ring_publish 205157 0 205157
|| p == sa_pp_hist_record || p == sa_pp_ring_publish 205157 0 205157
1013 205157 ▶ || p == sa_pp_rate_allow || p == sa_pp_add
Branch: 2 branches
BranchTrueFalseTotal
|| p == sa_pp_rate_allow || p == sa_pp_add 205157 0 205157
|| p == sa_pp_rate_allow || p == sa_pp_add 205157 0 205157
1014 205157 ▶ || p == sa_pp_meth_add
Branch: 1 branch
BranchTrueFalseTotal
|| p == sa_pp_meth_add 205157 0 205157
1015 205157 ▶ || p == sa_pp_cms_estimate
Branch: 1 branch
BranchTrueFalseTotal
|| p == sa_pp_cms_estimate 205157 0 205157
1016 205157 ▶ || p == sa_pp_map_incr_by || p == sa_pp_cache_set_ttl
Branch: 2 branches
BranchTrueFalseTotal
|| p == sa_pp_map_incr_by || p == sa_pp_cache_set_ttl 205157 0 205157
|| p == sa_pp_map_incr_by || p == sa_pp_cache_set_ttl 205157 0 205157
1017 205157 ▶ || p == sa_pp_hist_record_n || p == sa_pp_rate_allow_cost
Branch: 2 branches
BranchTrueFalseTotal
|| p == sa_pp_hist_record_n || p == sa_pp_rate_allow_cost 205157 0 205157
|| p == sa_pp_hist_record_n || p == sa_pp_rate_allow_cost 205157 0 205157
1018 205157 ▶ || p == sa_pp_add_n || p == sa_pp_rate_remaining
Branch: 2 branches
BranchTrueFalseTotal
|| p == sa_pp_add_n || p == sa_pp_rate_remaining 205157 0 205157
|| p == sa_pp_add_n || p == sa_pp_rate_remaining 205157 0 205157
1019 410314 ▶ || p == sa_pp_rate_retry_after || p == sa_pp_map_counter;
Branch: 3 branches
BranchTrueFalseTotal
|| p == sa_pp_rate_retry_after || p == sa_pp_map_counter; 205157 0 205157
|| p == sa_pp_rate_retry_after || p == sa_pp_map_counter; 205157 0 205157
|| p == sa_pp_rate_retry_after || p == sa_pp_map_counter; 0 205157 205157
1020 }
1021  
1022 207975 static void sa_try_hook(pTHX_ OP *o) {
1023 OP *pushop, *selfop, *last, *cur;
1024 207975 int nargs = 0;
1025 const char *name;
1026  
1027 207975 ▶ if (!o || o->op_type != OP_ENTERSUB) return;
Branch: 2 branches
BranchTrueFalseTotal
if (!o || o->op_type != OP_ENTERSUB) return; 207975 0 207975
if (!o || o->op_type != OP_ENTERSUB) return; 2818 205157 207975
1028 205157 ▶ if (sa_xop_is_ours(o->op_ppaddr)) return;
Branch: 1 branch
BranchTrueFalseTotal
if (sa_xop_is_ours(o->op_ppaddr)) return; 0 205157 205157
1029  
1030 205157 pushop = cUNOPx(o)->op_first;
1031 205157 ▶ if (!pushop) return;
Branch: 1 branch
BranchTrueFalseTotal
if (!pushop) return; 0 205157 205157
1032 205157 ▶ if (!OpHAS_SIBLING(pushop)) pushop = cUNOPx(pushop)->op_first;
Branch: 1 branch
BranchTrueFalseTotal
if (!OpHAS_SIBLING(pushop)) pushop = cUNOPx(pushop)->op_first; 135204 69953 205157
1033 205157 ▶ if (!pushop) return;
Branch: 1 branch
BranchTrueFalseTotal
if (!pushop) return; 0 205157 205157
1034  
1035 205157 ▶ selfop = OpSIBLING(pushop);
Branch: 1 branch
BranchTrueFalseTotal
selfop = OpSIBLING(pushop); 205157 0 205157
1036 205157 ▶ if (!selfop) return;
Branch: 1 branch
BranchTrueFalseTotal
if (!selfop) return; 0 205157 205157
1037  
1038 205157 last = selfop;
1039 429559 ▶ while (OpHAS_SIBLING(last)) { cur = OpSIBLING(last); if (!cur) break; last = cur; }
Branch: 3 branches
BranchTrueFalseTotal
while (OpHAS_SIBLING(last)) { cur = OpSIBLING(last); if (!cur) break; last = cur; } 224402 0 224402
while (OpHAS_SIBLING(last)) { cur = OpSIBLING(last); if (!cur) break; last = cur; } 0 224402 224402
while (OpHAS_SIBLING(last)) { cur = OpSIBLING(last); if (!cur) break; last = cur; } 224402 205157 429559
1040 205157 ▶ if (!last || last->op_type != OP_METHOD_NAMED) return;
Branch: 2 branches
BranchTrueFalseTotal
if (!last || last->op_type != OP_METHOD_NAMED) return; 205157 0 205157
if (!last || last->op_type != OP_METHOD_NAMED) return; 135776 69381 205157
1041  
1042 137068 ▶ for (cur = OpSIBLING(selfop); cur && cur != last; cur = OpSIBLING(cur))
Branch: 3 branches
BranchTrueFalseTotal
for (cur = OpSIBLING(selfop); cur && cur != last; cur = OpSIBLING(cur)) 69381 0 69381
for (cur = OpSIBLING(selfop); cur && cur != last; cur = OpSIBLING(cur)) 137068 0 137068
for (cur = OpSIBLING(selfop); cur && cur != last; cur = OpSIBLING(cur)) 67687 69381 137068
1043 67687 ▶ nargs++;
Branch: 1 branch
BranchTrueFalseTotal
nargs++; 67687 0 67687
1044  
1045 {
1046 SV *namesv;
1047 #if defined(OPpMETH_NO_BAREWORD_IO) || PERL_VERSION_GE(5,22,0)
1048 69381 namesv = cMETHOPx_meth(last);
1049 #else
1050 namesv = cSVOPx_sv(last);
1051 #endif
1052 69381 ▶ if (!namesv || !SvPOK(namesv)) return;
Branch: 2 branches
BranchTrueFalseTotal
if (!namesv || !SvPOK(namesv)) return; 69381 0 69381
if (!namesv || !SvPOK(namesv)) return; 0 69381 69381
1053 69381 name = SvPVX(namesv);
1054 }
1055  
1056 /* BOTH ops where both are free: the entersub loses the call frame, and the
1057 * method_named loses the stash walk that would otherwise happen first.
1058 * Where another dist already owns the entersub, the method op gets
1059 * `shared` instead: for `get` that is the door which makes the whole call
1060 * from the method op and skips the entersub, elsewhere the plain push.
1061 * `mdoor` names the method op, which a wider form shares with the
1062 * narrower one because it pushes the same CV. */
1063 #define SA_HOOK_AS(n, meth, door, mdoor, shared) \
1064 if (nargs == (n) && strEQ(name, meth)) { \
1065 int got = 0; \
1066 if (o->op_ppaddr == PL_ppaddr[OP_ENTERSUB]) { \
1067 o->op_ppaddr = sa_pp_##door; \
1068 got = 1; \
1069 } \
1070 if (last->op_ppaddr == PL_ppaddr[OP_METHOD_NAMED]) { \
1071 last->op_ppaddr = got ? sa_pp_meth_##mdoor : (shared); \
1072 if (!got) sa_xop_meth++; \
1073 got = 1; \
1074 } \
1075 if (got) sa_xop_hook++; \
1076 return; \
1077 }
1078 #define SA_HOOK(n, meth, door) \
1079 SA_HOOK_AS(n, meth, door, door, sa_pp_meth_##door)
1080  
1081 69381 ▶ SA_HOOK_AS(1, "get", cache_get, cache_get, sa_pp_methdoor_cache_get)
Branch: 7 branches
BranchTrueFalseTotal
SA_HOOK_AS(1, "get", cache_get, cache_get, sa_pp_methdoor_cache_get) 27141 42240 69381
SA_HOOK_AS(1, "get", cache_get, cache_get, sa_pp_methdoor_cache_get) 97 27044 27141
SA_HOOK_AS(1, "get", cache_get, cache_get, sa_pp_methdoor_cache_get) 0 97 97
SA_HOOK_AS(1, "get", cache_get, cache_get, sa_pp_methdoor_cache_get) 97 0 97
SA_HOOK_AS(1, "get", cache_get, cache_get, sa_pp_methdoor_cache_get) 0 97 97
SA_HOOK_AS(1, "get", cache_get, cache_get, sa_pp_methdoor_cache_get) 97 0 97
SA_HOOK_AS(1, "get", cache_get, cache_get, sa_pp_methdoor_cache_get) 97 0 97
1082 69284 ▶ SA_HOOK(2, "set", cache_set)
Branch: 6 branches
BranchTrueFalseTotal
SA_HOOK(2, "set", cache_set) 12762 56522 69284
SA_HOOK(2, "set", cache_set) 44 12718 12762
SA_HOOK(2, "set", cache_set) 44 0 44
SA_HOOK(2, "set", cache_set) 44 0 44
SA_HOOK(2, "set", cache_set) 0 44 44
SA_HOOK(2, "set", cache_set) 44 0 44
1083 69240 ▶ SA_HOOK_AS(4, "set", cache_set_ttl, cache_set, sa_pp_meth_cache_set)
Branch: 6 branches
BranchTrueFalseTotal
SA_HOOK_AS(4, "set", cache_set_ttl, cache_set, sa_pp_meth_cache_set) 801 68439 69240
SA_HOOK_AS(4, "set", cache_set_ttl, cache_set, sa_pp_meth_cache_set) 7 794 801
SA_HOOK_AS(4, "set", cache_set_ttl, cache_set, sa_pp_meth_cache_set) 7 0 7
SA_HOOK_AS(4, "set", cache_set_ttl, cache_set, sa_pp_meth_cache_set) 7 0 7
SA_HOOK_AS(4, "set", cache_set_ttl, cache_set, sa_pp_meth_cache_set) 0 7 7
SA_HOOK_AS(4, "set", cache_set_ttl, cache_set, sa_pp_meth_cache_set) 7 0 7
1084 69233 ▶ SA_HOOK(1, "fetch", map_fetch)
Branch: 6 branches
BranchTrueFalseTotal
SA_HOOK(1, "fetch", map_fetch) 27044 42189 69233
SA_HOOK(1, "fetch", map_fetch) 278 26766 27044
SA_HOOK(1, "fetch", map_fetch) 278 0 278
SA_HOOK(1, "fetch", map_fetch) 278 0 278
SA_HOOK(1, "fetch", map_fetch) 0 278 278
SA_HOOK(1, "fetch", map_fetch) 278 0 278
1085 68955 ▶ SA_HOOK(2, "store", map_store)
Branch: 6 branches
BranchTrueFalseTotal
SA_HOOK(2, "store", map_store) 12718 56237 68955
SA_HOOK(2, "store", map_store) 114 12604 12718
SA_HOOK(2, "store", map_store) 114 0 114
SA_HOOK(2, "store", map_store) 114 0 114
SA_HOOK(2, "store", map_store) 0 114 114
SA_HOOK(2, "store", map_store) 114 0 114
1086 68841 ▶ SA_HOOK(1, "incr", map_incr)
Branch: 6 branches
BranchTrueFalseTotal
SA_HOOK(1, "incr", map_incr) 26766 42075 68841
SA_HOOK(1, "incr", map_incr) 93 26673 26766
SA_HOOK(1, "incr", map_incr) 93 0 93
SA_HOOK(1, "incr", map_incr) 93 0 93
SA_HOOK(1, "incr", map_incr) 0 93 93
SA_HOOK(1, "incr", map_incr) 93 0 93
1087 68748 ▶ SA_HOOK_AS(2, "incr", map_incr_by, map_incr, sa_pp_meth_map_incr)
Branch: 6 branches
BranchTrueFalseTotal
SA_HOOK_AS(2, "incr", map_incr_by, map_incr, sa_pp_meth_map_incr) 12604 56144 68748
SA_HOOK_AS(2, "incr", map_incr_by, map_incr, sa_pp_meth_map_incr) 149 12455 12604
SA_HOOK_AS(2, "incr", map_incr_by, map_incr, sa_pp_meth_map_incr) 149 0 149
SA_HOOK_AS(2, "incr", map_incr_by, map_incr, sa_pp_meth_map_incr) 149 0 149
SA_HOOK_AS(2, "incr", map_incr_by, map_incr, sa_pp_meth_map_incr) 0 149 149
SA_HOOK_AS(2, "incr", map_incr_by, map_incr, sa_pp_meth_map_incr) 149 0 149
1088 68599 ▶ SA_HOOK(1, "exists", map_exists)
Branch: 6 branches
BranchTrueFalseTotal
SA_HOOK(1, "exists", map_exists) 26673 41926 68599
SA_HOOK(1, "exists", map_exists) 313 26360 26673
SA_HOOK(1, "exists", map_exists) 313 0 313
SA_HOOK(1, "exists", map_exists) 313 0 313
SA_HOOK(1, "exists", map_exists) 0 313 313
SA_HOOK(1, "exists", map_exists) 313 0 313
1089 68286 ▶ SA_HOOK(1, "counter", map_counter)
Branch: 6 branches
BranchTrueFalseTotal
SA_HOOK(1, "counter", map_counter) 26360 41926 68286
SA_HOOK(1, "counter", map_counter) 175 26185 26360
SA_HOOK(1, "counter", map_counter) 175 0 175
SA_HOOK(1, "counter", map_counter) 175 0 175
SA_HOOK(1, "counter", map_counter) 0 175 175
SA_HOOK(1, "counter", map_counter) 175 0 175
1090 68111 ▶ SA_HOOK(1, "check", check)
Branch: 6 branches
BranchTrueFalseTotal
SA_HOOK(1, "check", check) 26185 41926 68111
SA_HOOK(1, "check", check) 32 26153 26185
SA_HOOK(1, "check", check) 32 0 32
SA_HOOK(1, "check", check) 32 0 32
SA_HOOK(1, "check", check) 0 32 32
SA_HOOK(1, "check", check) 32 0 32
1091 68079 ▶ SA_HOOK(1, "record", hist_record)
Branch: 6 branches
BranchTrueFalseTotal
SA_HOOK(1, "record", hist_record) 26153 41926 68079
SA_HOOK(1, "record", hist_record) 14 26139 26153
SA_HOOK(1, "record", hist_record) 14 0 14
SA_HOOK(1, "record", hist_record) 14 0 14
SA_HOOK(1, "record", hist_record) 0 14 14
SA_HOOK(1, "record", hist_record) 14 0 14
1092 68065 ▶ SA_HOOK_AS(2, "record", hist_record_n, hist_record, sa_pp_meth_hist_record)
Branch: 6 branches
BranchTrueFalseTotal
SA_HOOK_AS(2, "record", hist_record_n, hist_record, sa_pp_meth_hist_record) 12455 55610 68065
SA_HOOK_AS(2, "record", hist_record_n, hist_record, sa_pp_meth_hist_record) 2 12453 12455
SA_HOOK_AS(2, "record", hist_record_n, hist_record, sa_pp_meth_hist_record) 2 0 2
SA_HOOK_AS(2, "record", hist_record_n, hist_record, sa_pp_meth_hist_record) 2 0 2
SA_HOOK_AS(2, "record", hist_record_n, hist_record, sa_pp_meth_hist_record) 0 2 2
SA_HOOK_AS(2, "record", hist_record_n, hist_record, sa_pp_meth_hist_record) 2 0 2
1093 68063 ▶ SA_HOOK(2, "publish", ring_publish)
Branch: 6 branches
BranchTrueFalseTotal
SA_HOOK(2, "publish", ring_publish) 12453 55610 68063
SA_HOOK(2, "publish", ring_publish) 105 12348 12453
SA_HOOK(2, "publish", ring_publish) 105 0 105
SA_HOOK(2, "publish", ring_publish) 105 0 105
SA_HOOK(2, "publish", ring_publish) 0 105 105
SA_HOOK(2, "publish", ring_publish) 105 0 105
1094 67958 ▶ SA_HOOK(1, "allow", rate_allow)
Branch: 6 branches
BranchTrueFalseTotal
SA_HOOK(1, "allow", rate_allow) 26139 41819 67958
SA_HOOK(1, "allow", rate_allow) 108 26031 26139
SA_HOOK(1, "allow", rate_allow) 108 0 108
SA_HOOK(1, "allow", rate_allow) 108 0 108
SA_HOOK(1, "allow", rate_allow) 0 108 108
SA_HOOK(1, "allow", rate_allow) 108 0 108
1095 67850 ▶ SA_HOOK_AS(2, "allow", rate_allow_cost, rate_allow, sa_pp_meth_rate_allow)
Branch: 6 branches
BranchTrueFalseTotal
SA_HOOK_AS(2, "allow", rate_allow_cost, rate_allow, sa_pp_meth_rate_allow) 12348 55502 67850
SA_HOOK_AS(2, "allow", rate_allow_cost, rate_allow, sa_pp_meth_rate_allow) 19 12329 12348
SA_HOOK_AS(2, "allow", rate_allow_cost, rate_allow, sa_pp_meth_rate_allow) 19 0 19
SA_HOOK_AS(2, "allow", rate_allow_cost, rate_allow, sa_pp_meth_rate_allow) 19 0 19
SA_HOOK_AS(2, "allow", rate_allow_cost, rate_allow, sa_pp_meth_rate_allow) 0 19 19
SA_HOOK_AS(2, "allow", rate_allow_cost, rate_allow, sa_pp_meth_rate_allow) 19 0 19
1096 67831 ▶ SA_HOOK(1, "remaining", rate_remaining)
Branch: 6 branches
BranchTrueFalseTotal
SA_HOOK(1, "remaining", rate_remaining) 26031 41800 67831
SA_HOOK(1, "remaining", rate_remaining) 51 25980 26031
SA_HOOK(1, "remaining", rate_remaining) 51 0 51
SA_HOOK(1, "remaining", rate_remaining) 51 0 51
SA_HOOK(1, "remaining", rate_remaining) 0 51 51
SA_HOOK(1, "remaining", rate_remaining) 51 0 51
1097 67780 ▶ SA_HOOK(1, "retry_after", rate_retry_after)
Branch: 6 branches
BranchTrueFalseTotal
SA_HOOK(1, "retry_after", rate_retry_after) 25980 41800 67780
SA_HOOK(1, "retry_after", rate_retry_after) 12 25968 25980
SA_HOOK(1, "retry_after", rate_retry_after) 12 0 12
SA_HOOK(1, "retry_after", rate_retry_after) 12 0 12
SA_HOOK(1, "retry_after", rate_retry_after) 0 12 12
SA_HOOK(1, "retry_after", rate_retry_after) 12 0 12
1098 67768 ▶ SA_HOOK(1, "estimate", cms_estimate)
Branch: 6 branches
BranchTrueFalseTotal
SA_HOOK(1, "estimate", cms_estimate) 25968 41800 67768
SA_HOOK(1, "estimate", cms_estimate) 51 25917 25968
SA_HOOK(1, "estimate", cms_estimate) 51 0 51
SA_HOOK(1, "estimate", cms_estimate) 51 0 51
SA_HOOK(1, "estimate", cms_estimate) 0 51 51
SA_HOOK(1, "estimate", cms_estimate) 51 0 51
1099 67717 ▶ SA_HOOK(1, "add", add)
Branch: 6 branches
BranchTrueFalseTotal
SA_HOOK(1, "add", add) 25917 41800 67717
SA_HOOK(1, "add", add) 257 25660 25917
SA_HOOK(1, "add", add) 257 0 257
SA_HOOK(1, "add", add) 257 0 257
SA_HOOK(1, "add", add) 0 257 257
SA_HOOK(1, "add", add) 257 0 257
1100 67460 ▶ SA_HOOK_AS(2, "add", add_n, add, sa_pp_meth_add)
Branch: 6 branches
BranchTrueFalseTotal
SA_HOOK_AS(2, "add", add_n, add, sa_pp_meth_add) 12329 55131 67460
SA_HOOK_AS(2, "add", add_n, add, sa_pp_meth_add) 23 12306 12329
SA_HOOK_AS(2, "add", add_n, add, sa_pp_meth_add) 23 0 23
SA_HOOK_AS(2, "add", add_n, add, sa_pp_meth_add) 23 0 23
SA_HOOK_AS(2, "add", add_n, add, sa_pp_meth_add) 0 23 23
SA_HOOK_AS(2, "add", add_n, add, sa_pp_meth_add) 23 0 23
1101 #undef SA_HOOK_AS
1102 #undef SA_HOOK
1103 }
1104  
1105 207975 static OP *sa_ck_entersub(pTHX_ OP *o) {
1106 207975 ▶ if (sa_prev_ck_entersub) o = sa_prev_ck_entersub(aTHX_ o);
Branch: 1 branch
BranchTrueFalseTotal
if (sa_prev_ck_entersub) o = sa_prev_ck_entersub(aTHX_ o); 207975 0 207975
1107 207975 sa_try_hook(aTHX_ o);
1108 207975 return o;
1109 }
1110  
1111 #endif /* SA_XOP_H */
« include/sa/sa_abi_impl.h ↑ Summary xs/abi.xs »