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 #ifdef PERL_IMPLICIT_CONTEXT
17 PerlInterpreter *perl;
18 #endif
19 } stencil_buf;
20  
21 void stencil_buf_init(pTHX_ stencil_buf *b, size_t hint);
22 void stencil_buf_grow(stencil_buf *b, size_t need); /* slow path */
23 SV *stencil_buf_done(stencil_buf *b);
24  
25 118068 STENCIL_INLINE void stencil_buf_reserve(stencil_buf *b, size_t n)
26 {
27 118068 ▶ if (STENCIL_UNLIKELY((size_t)(b->end - b->cur) < n))
Branch: 1 branch
BranchTrueFalseTotal
if (STENCIL_UNLIKELY((size_t)(b->end - b->cur) < n)) 241 117827 118068
28 241 stencil_buf_grow(b, n);
29 118068 }
30  
31 STENCIL_INLINE void stencil_buf_write(stencil_buf *b, const char *p, size_t n)
32 {
33 stencil_buf_reserve(b, n);
34 memcpy(b->cur, p, n);
35 b->cur += n;
36 }
37  
38 /* Single unaligned 8-byte store for short known strings (escape
39 * entities, the literal "{%"): pat8 points at 8 readable bytes, len is
40 * how far the head advances. Faster than memcpy(len) on every codegen
41 * we care about. */
42 STENCIL_INLINE void stencil_buf_write8(stencil_buf *b, const char *pat8,
43 size_t len)
44 {
45 stencil_buf_reserve(b, 8);
46 memcpy(b->cur, pat8, 8);
47 b->cur += len;
48 }
49  
50 #endif /* STENCIL_BUF_H */
« examples/plack.psgi ↑ Summary