src/mds_buf.h

filter: Statementstmt 100% 4 / 4 Branchbran 55.9% 159 / 284 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 56.6% 163 / 288 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« src/simd/mds_simd_sse2.c ↑ Summary include/mds_abi_impl.h »
1 /* mds_buf.h — output buffer wrapping a Perl SV.
2 *
3 * Owns a cursor into SvPV so we avoid SvCUR/SvLEN roundtrips per write.
4 * Caller must call mds_buf_finalize() before the SV is consumed by Perl.
5 */
6 #ifndef MDS_BUF_H
7 #define MDS_BUF_H
8  
9 #include <stddef.h>
10 #include "EXTERN.h"
11 #include "perl.h"
12 #include "mds_compiler.h"
13  
14 typedef struct mds_buf {
15 SV* sv;
16 char* base; /* SvPVX(sv) */
17 char* cur; /* write cursor */
18 char* end; /* base + SvLEN(sv) - 1 (room for trailing NUL) */
19 } mds_buf;
20  
21 /* Attach to an existing SV, predict initial capacity. */
22 void mds_buf_init(pTHX_ mds_buf* b, SV* sv, size_t hint);
23  
24 /* Input-aware initial capacity. Samples the head of
25 * `input` for pipe density and picks 2.25\u00d7 for table-heavy inputs,
26 * 1.50\u00d7 for everything else. Falls back to mds_buf_init's prose
27 * default when input is NULL. */
28 void mds_buf_init_for_input(pTHX_ mds_buf* b, SV* sv,
29 const char* input, size_t hint);
30  
31 /* Ensure at least `need` bytes free; grows SV and refreshes cursor. */
32 void mds_buf_reserve(pTHX_ mds_buf* b, size_t need);
33  
34 /* Append n bytes. The grow check is the only branch; the common case
35 * (n bytes fit) compiles to a 2-instruction cursor bump + memcpy that
36 * the optimiser turns into a register store when n is a compile-time
37 * constant under 8. Marked always-inline so the constant-n cases at
38 * call sites (HTML tags via MDS_BUF_LIT) really do specialise. */
39 MDS_ALWAYS_INLINE static void mds_buf_write(pTHX_ mds_buf* b, const char* s, size_t n) {
40 80245416 ▶ if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n);
Branch: 142 branches
BranchTrueFalseTotal
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 9 991 1000
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 328 328
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 240 240
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 3 23 26
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 146 146
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 808338 808338
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 57 57
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 808077 808077
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 808077 808077
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 808077 808077
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 38 38
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 38 38
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 808077 808077
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 0 0
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 328 328
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 240 240
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 26 26
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 3 143 146
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 1 1
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 788123 788123
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 29 29
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 808338 808338
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 808338 808338
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 100 100
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 100 100
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 808338 808338
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 57 57
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 7 7
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 57 57
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 20200 787824 808024
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 808024 808024
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 767606 767606
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 3 808021 808024
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 808024 808024
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 808024 808024
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 0 0
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 30 30
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 0 0
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 6 6
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 117 117
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 37173957 37173957
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 8 8
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 16 16
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 57 57
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 282 282
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 19 19
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 4 13 17
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 24 24
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 0 0
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 0 0
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 59 59
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 18 18
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 3 56 59
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 59 59
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 12 12
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 12 12
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 12 12
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 21 21
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 21 21
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 21 21
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 27 27
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 27 27
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 27 27
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 2465348 2465348
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 72 72
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 0 0
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 20203 3274895 3295098
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 3 113 116
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 170 170
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 808023 808023
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 808023 808023
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 20200 787823 808023
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 40410 767613 808023
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 5 808018 808023
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 6 171 177
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 42 42
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 59 59
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 55 55
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 223 223
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 595 595
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 3 66 69
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 69 69
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 4 53 57
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 4 162 166
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 143 143
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 7 204 211
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 40409 40409
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 808021 808021
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 808024 808024
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 767606 767606
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 40406 767618 808024
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 808024 808024
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 20203 787821 808024
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 808024 808024
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 808024 808024
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 767606 767606
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 767606 767606
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 767606 767606
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 808024 808024
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 3 40412 40415
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 3 3
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 40418 40418
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 808274 808274
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 183 183
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 53 53
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 3295098 3295098
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 223 223
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 104 104
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 20 20
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 20 20
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 96 96
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 170 170
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 3 174 177
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 28 28
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 69 69
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 282 282
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 595 595
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 69 69
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 69 69
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 57 57
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 166 166
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 122 122
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 190 190
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 42 42
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 42 42
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 42 42
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 42 42
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 42 42
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 3 40406 40409
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 40418 40418
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 40418 40418
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 6 6
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 6 6
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 3 3
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 36 36
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 15 15
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 940 940
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 120 120
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 193 193
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 119 119
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 0 242 242
if (MDS_UNLIKELY(b->cur + n > b->end)) mds_buf_reserve(aTHX_ b, n); 60609 7257583 7318192
41 80245416 memcpy(b->cur, s, n);
42 80245416 b->cur += n;
43 80245416 }
44  
45 MDS_ALWAYS_INLINE static void mds_buf_putc(pTHX_ mds_buf* b, char c) {
46 if (MDS_UNLIKELY(b->cur + 1 > b->end)) mds_buf_reserve(aTHX_ b, 1);
47 *b->cur++ = c;
48 }
49  
50 /* Write a compile-time literal. */
51 #define MDS_BUF_LIT(b, lit) mds_buf_write(aTHX_ (b), "" lit, sizeof(lit) - 1)
52  
53 /* Splice bytes into already-written output at byte offset `at`, shifting the
54 * tail right. Used by the heading renderer, whose open tag carries an id that
55 * is only known once the heading's inline content has been rendered. `at` is
56 * an offset rather than a pointer because reserve can realloc the SV. */
57 void mds_buf_insert(pTHX_ mds_buf* b, size_t at, const char* src, size_t len);
58  
59 /* Commit cursor to SvCUR, NUL-terminate. */
60 void mds_buf_finalize(pTHX_ mds_buf* b);
61  
62 #endif
« src/simd/mds_simd_sse2.c ↑ Summary include/mds_abi_impl.h »