include/stencil_buf.h

filter: Statementstmt 100% 4 / 4 Branchbran 100% 2 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 100% 6 / 6 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« examples/plack.psgi ↑ Summary
1 #ifndef STENCIL_BUF_H
2 #define STENCIL_BUF_H
3  
4 /* SV-backed output buffer: the buffer IS the result SV, so a PSGI
5 * server can hand the rendered body back with zero copies. The grow
6 * path is out of line; the reserve fast path is a compare and fall
7 * through. Under ithreads the owning interpreter is captured at init
8 * so the escaper and VM can call through function pointers that carry
9 * no pTHX. */
10  
11 typedef struct stencil_buf {
12 SV *sv;
13 char *cur; /* write head */
14 char *end; /* last writable byte + 1 (the NUL slot is excluded) */
15 int utf8; /* set when any contributing source/value was UTF-8 */
16 int grew; /* the initial capacity was not enough: grow ran */
17 #ifdef PERL_IMPLICIT_CONTEXT
18 PerlInterpreter *perl;
19 #endif
20 } stencil_buf;
21  
22 void stencil_buf_init(pTHX_ stencil_buf *b, size_t hint);
23 void stencil_buf_grow(stencil_buf *b, size_t need); /* slow path */
24 SV *stencil_buf_done(stencil_buf *b);
25  
26 118187 STENCIL_INLINE void stencil_buf_reserve(stencil_buf *b, size_t n)
27 {
28 118187 ▶ if (STENCIL_UNLIKELY((size_t)(b->end - b->cur) < n))
Branch: 1 branch
BranchTrueFalseTotal
if (STENCIL_UNLIKELY((size_t)(b->end - b->cur) < n)) 254 117933 118187
29 254 stencil_buf_grow(b, n);
30 118187 }
31  
32 STENCIL_INLINE void stencil_buf_write(stencil_buf *b, const char *p, size_t n)
33 {
34 stencil_buf_reserve(b, n);
35 memcpy(b->cur, p, n);
36 b->cur += n;
37 }
38  
39 /* Single unaligned 8-byte store for short known strings (escape
40 * entities, the literal "{%"): pat8 points at 8 readable bytes, len is
41 * how far the head advances. Faster than memcpy(len) on every codegen
42 * we care about. */
43 STENCIL_INLINE void stencil_buf_write8(stencil_buf *b, const char *pat8,
44 size_t len)
45 {
46 stencil_buf_reserve(b, 8);
47 memcpy(b->cur, pat8, 8);
48 b->cur += len;
49 }
50  
51 #endif /* STENCIL_BUF_H */
« examples/plack.psgi ↑ Summary