leptris 1.9.416.0 → 1.9.418.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Rakefile +1 -1
- data/lib/leptris/vendor/aarch64-linux/libleptris.so +0 -0
- data/lib/leptris/vendor/aarch64-linux-musl/libleptris.so +0 -0
- data/lib/leptris/vendor/arm-linux/libleptris.so +0 -0
- data/lib/leptris/vendor/arm-linux-musl/libleptris.so +0 -0
- data/lib/leptris/vendor/arm64-darwin/libleptris.dylib +0 -0
- data/lib/leptris/vendor/ppc64le-linux/libleptris.so +0 -0
- data/lib/leptris/vendor/s390x-linux-musl/libleptris.so +0 -0
- data/lib/leptris/vendor/x86_64-darwin/libleptris.dylib +0 -0
- data/lib/leptris/vendor/x86_64-linux/libleptris.so +0 -0
- data/lib/leptris/vendor/x86_64-linux-musl/libleptris.so +0 -0
- data/lib/leptris/version.rb +1 -1
- data/vendor-src/README.md +1 -1
- data/vendor-src/libleptris/CHANGELOG.md +30 -0
- data/vendor-src/libleptris/CMakeLists.txt +1 -1
- data/vendor-src/libleptris/README.adoc +60 -20
- data/vendor-src/libleptris/TODO.max-perf/15-c-face-vs-pugixml.md +167 -0
- data/vendor-src/libleptris/src/leptris/common/entities.c +5 -0
- data/vendor-src/libleptris/src/leptris/common/simd_text.c +20 -6
- data/vendor-src/libleptris/src/leptris/common/simd_text.h +17 -3
- data/vendor-src/libleptris/src/leptris/common/simd_text_avx2.c +64 -0
- data/vendor-src/libleptris/src/leptris/common/simd_text_neon.c +32 -2
- data/vendor-src/libleptris/src/leptris/dom/element_query.c +9 -1
- data/vendor-src/libleptris/src/leptris/flat/direct_parse.c +101 -17
- data/vendor-src/libleptris/test/CMakeLists.txt +1 -0
- data/vendor-src/libleptris/test/dom/test_dom.cpp +94 -0
- data/vendor-src/libleptris/test/parser/test_entity_decode.cpp +54 -0
- data/vendor-src/libleptris/test/parser/test_simd_count.cpp +38 -6
- data/vendor-src/libleptris/vcpkg.json +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 602afb776ae5cbc4da725de682f9b2ecaaa468203a7a08ebd282001c49abc5e1
|
|
4
|
+
data.tar.gz: 2c76c6063b0256865991082653d8cda99aa6dac330ccdd4378f108c5d5511810
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1e8e56d54bf1c223a62eef03612dab63d0bf1b44929ba3f8aa50f037738cc91f4e048593d1af87eeaa2421401e26e36bb3b891ec105a020d2d0c59fcd981e2ab
|
|
7
|
+
data.tar.gz: f1b83a111189aa6b620d0bf60deb5e871fd1ea1e8122c7d87e052b39e348a8f59081b5cb9c95cb9248e46a18ed85e6e9ecf170dbf1800fe61f9509e5ab87fd03
|
data/Rakefile
CHANGED
|
@@ -8,7 +8,7 @@ RSpec::Core::RakeTask.new(:spec)
|
|
|
8
8
|
# Pin for `rake compile` and the platform-gem builds. Keep in lockstep
|
|
9
9
|
# with .github/workflows/build.yml (which calls `rake compile`) and the
|
|
10
10
|
# CHANGELOG when libleptris releases.
|
|
11
|
-
LIBLEPTRIS_VERSION = "1.9.
|
|
11
|
+
LIBLEPTRIS_VERSION = "1.9.418"
|
|
12
12
|
# Vendored alongside libleptris for fn:normalize-unicode (TODO
|
|
13
13
|
# .restructure/20): built per platform with a RELOCATABLE @rpath
|
|
14
14
|
# install name, loaded by ffi.rb before libleptris so the
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
data/lib/leptris/version.rb
CHANGED
data/vendor-src/README.md
CHANGED
|
@@ -1,5 +1,35 @@
|
|
|
1
1
|
## [Unreleased]
|
|
2
2
|
|
|
3
|
+
## [1.9.418] - 2026-11-12
|
|
4
|
+
## Fixed
|
|
5
|
+
|
|
6
|
+
- **entities: unknown named entities preserve their terminating semicolon**. decode_entity's lenient unknown-entity branch consumed the `;` while copying the name — `©` came back as `©` (one character short) on every consumer of the decode face: the attribute accessor's lazy expansion, text content, and the bindings' decode calls. The semicolon is part of the literal spelling; it is now emitted. Pins: unknown entities byte-exact in attributes and text; mixed known/unknown decode (`&` decodes; `©`/` ` stay literal — HTML-only, not XML-predefined).
|
|
7
|
+
|
|
8
|
+
- **attributes: the bulk attribute-pairs export serves decoded values**. `leptris_element_attribute_pairs`' values column read the RAW view while the per-attribute getter decoded — every listing face that routes through the bulk export (the bindings' `attribute_pairs` and the native packet/pairs faces the adapters use) showed literals where the accessor decoded (lutaml/moxml#540: the XSD unicode-block pattern cases flipped to failing between trains). The values column now routes through the per-attribute getter (same decode, cached into the attribute — repeat bulk reads skip the work). The raw views remain on `leptris_element_attributes_raw` (#635).
|
|
9
|
+
|
|
10
|
+
## Tests
|
|
11
|
+
|
|
12
|
+
- New `test_entity_decode` battery: the unknown-entity byte-exactness contract, mixed known/unknown decode, and the bulk values column. Two pin drafts were discarded for wrong premises (attribute-name NUL behavior; `©`/` ` as XML-predefined — they are HTML-only).
|
|
13
|
+
|
|
14
|
+
## [1.9.417] - 2026-11-11
|
|
15
|
+
## Performance
|
|
16
|
+
|
|
17
|
+
- **parse: inline the no-attribute fast-out in the element-open path** (#1842 Track D). The text-shape profile showed `dp_parse_attrs` at ~5% of a document with zero attributes — the per-element call + reset prologue + dup-table memset paid even for `<e></e>`-class tags. `>` or `/` directly after the element name collapses to a few inline stores; whitespace falls through to the full parser unchanged. CI shape rows: ubuntu-x86 attr 13MB reached **parity (0.99x)**, text rows +52–54%, attr 1.5MB **ahead (0.72x)**.
|
|
18
|
+
|
|
19
|
+
- **parse: content-census-driven arena copy budget** (#2003). The count3 sizing pre-scan now also census-counts `&` and literal tab/LF/CR (the only content-copy sources: entity expansion, §3.3.3 normalization) in the same SIMD pass; documents carrying neither drop the len-sized copy reservation — arena ~3x len → ~2x len for the machine-generated single-line class.
|
|
20
|
+
|
|
21
|
+
- **parse: skip the pristine buffer carve for newline-free documents** (#2005, A3d). The pristine copy existed for the lazy line table; a newline-free document loses no newlines to `dp_nul`, so the carve and its full-buffer memcpy drop and `xml_buffer` repoints at the doc-owned scratch. macos attr-13MB +189%.
|
|
22
|
+
|
|
23
|
+
- **simd: count3_high gains an AVX2 kernel** (#2006). x86 machines ran the sizing pre-scan SCALAR; five counters in one 32-byte-chunk pass. The ubuntu-x86 text rows moved 3.4–3.5x behind → 1.38–1.46x.
|
|
24
|
+
|
|
25
|
+
## Benchmarks
|
|
26
|
+
|
|
27
|
+
- The attrparse row is now win/parity on all three CI legs (macos 1.10x, ubuntu-x86 1.04x, ubuntu-arm 0.84). The macos 13MB shape rows were re-classified as runner noise (4.8x swings across runs of near-identical code) — verdicts there require repeated-run medians. Full arc and the remaining lever (the fused scanner loop on the arm legs) ledgered in `TODO.max-perf/15` Track D addenda 1–6b.
|
|
28
|
+
|
|
29
|
+
## Documentation
|
|
30
|
+
|
|
31
|
+
- README's shape table refreshes with the noise classification; negative results ledgered (the interleaved-lane default flip measured 1.72x slower on element-dense shapes — the opt-in gate stands).
|
|
32
|
+
|
|
3
33
|
## [1.9.416] - 2026-11-11
|
|
4
34
|
## Performance
|
|
5
35
|
|
|
@@ -1096,20 +1096,20 @@ harness numbers are noted separately.
|
|
|
1096
1096
|
|===
|
|
1097
1097
|
|Benchmark (parse + free, CI-gated) |Leptris |pugixml |Verdict
|
|
1098
1098
|
|
|
1099
|
-
|macos-latest
|
|
1100
|
-
|
|
|
1101
|
-
|
|
|
1102
|
-
|
|
1099
|
+
|macos-latest (clang, arm64)
|
|
1100
|
+
|1512.4 ns/doc
|
|
1101
|
+
|1492.4 ns/doc
|
|
1102
|
+
|parity (1.01x)
|
|
1103
1103
|
|
|
1104
1104
|
|ubuntu-latest (x86-64, gcc-13)
|
|
1105
|
-
|
|
|
1106
|
-
|
|
|
1107
|
-
|
|
1105
|
+
|1709.6 ns/doc
|
|
1106
|
+
|1891.3 ns/doc
|
|
1107
|
+
|**1.10x faster**
|
|
1108
1108
|
|
|
1109
|
-
|
|
|
1110
|
-
|
|
|
1111
|
-
|
|
|
1112
|
-
|1.
|
|
1109
|
+
|ubuntu-24.04-arm (gcc-13, glibc)
|
|
1110
|
+
|2222.4 ns/doc
|
|
1111
|
+
|1850.2 ns/doc
|
|
1112
|
+
|1.20x slower
|
|
1113
1113
|
|
|
1114
1114
|
|Full-window CPU-clock head-to-head, 4M docs (local, LTO both sides)
|
|
1115
1115
|
|5.45 s user
|
|
@@ -1117,15 +1117,55 @@ harness numbers are noted separately.
|
|
|
1117
1117
|
|equal — user-CPU parity
|
|
1118
1118
|
|===
|
|
1119
1119
|
|
|
1120
|
-
|
|
1121
|
-
#
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1120
|
+
The shape-fair parse rows (`bench_parse_ab`, same CI run) after the
|
|
1121
|
+
content-census copy budget (#2003), the pristine-copy skip for
|
|
1122
|
+
newline-free documents (#2005), and the AVX2 sizing pre-scan
|
|
1123
|
+
(#2006):
|
|
1124
|
+
|
|
1125
|
+
[cols="2,>1,>1,>1",options="header"]
|
|
1126
|
+
|===
|
|
1127
|
+
|Row (MB/s, leptris vs pugixml) |Before the cuts |After |Delta
|
|
1128
|
+
|
|
1129
|
+
|ubuntu-x86 text 1.5/5/13 MB
|
|
1130
|
+
|3.4-3.5x behind
|
|
1131
|
+
|1.16-1.46x behind
|
|
1132
|
+
|+181-276%
|
|
1133
|
+
|
|
1134
|
+
|ubuntu-x86 attr 1.5 MB
|
|
1135
|
+
|1.37x behind
|
|
1136
|
+
|**ahead (0.72x)**
|
|
1137
|
+
|+176%
|
|
1138
|
+
|
|
1139
|
+
|ubuntu-x86 attr 5 MB
|
|
1140
|
+
|1.36x behind
|
|
1141
|
+
|near-parity (0.90x)
|
|
1142
|
+
|+118%
|
|
1143
|
+
|
|
1144
|
+
|ubuntu-x86 attr 13 MB
|
|
1145
|
+
|1.36x behind
|
|
1146
|
+
|parity (0.99x)
|
|
1147
|
+
|+103%
|
|
1148
|
+
|
|
1149
|
+
|macos text 1.5/5/13 MB
|
|
1150
|
+
|1.66-1.87x behind
|
|
1151
|
+
|1.57-2.01x (runner-noise band; see note)
|
|
1152
|
+
|single-run macos 13MB rows swing 4.8x between runs — medians required
|
|
1153
|
+
|
|
1154
|
+
|macos attr 13 MB
|
|
1155
|
+
|5.14x behind
|
|
1156
|
+
|unstable (104-504 MB/s across runs)
|
|
1157
|
+
|the row is runner noise; verdicts from repeated-run medians only
|
|
1158
|
+
|===
|
|
1159
|
+
|
|
1160
|
+
The macos 13MB rows oscillate up to 4.8x between runs of
|
|
1161
|
+
near-identical code (139/174/504/104 MB/s across this arc) — the
|
|
1162
|
+
macos lane needs repeated-run medians before any single-run verdict
|
|
1163
|
+
there. The stable legs (ubuntu-x86, ubuntu-arm) carry the verdicts.
|
|
1164
|
+
|
|
1165
|
+
Run-to-run CI variance is ~5-10%; all verdicts sit outside that band
|
|
1166
|
+
except the macos parity row. Findings and the remaining honest tail
|
|
1167
|
+
(the fused scanner loop on the arm legs) live in `TODO.max-perf/15`
|
|
1168
|
+
Track D.
|
|
1129
1169
|
|
|
1130
1170
|
==== Recent performance wins (v1.9.410-v1.9.414)
|
|
1131
1171
|
|
|
@@ -238,3 +238,170 @@ favors it; leptris's own linux penalty is the 1.13x arm number.
|
|
|
238
238
|
Also note run-to-run variance: the macos attrparse pair measured
|
|
239
239
|
1728/2183 then 1831/2037 across runs (~5-10%) — treat sub-10% CI
|
|
240
240
|
deltas as noise bands; the win/loss verdicts above sit outside them.
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
## Track D addendum 4 — the arena cut LANDED (PR #2003, 2026-11-11)
|
|
244
|
+
|
|
245
|
+
Content-census copy budget (count3_high amp/valws outputs): macos
|
|
246
|
+
13MB collapse CONFIRMED as the reservation — CI-gated bench_parse_ab
|
|
247
|
+
before/after: text 13MB 361.6 -> 794.2 MB/s (+120%), attr 13MB
|
|
248
|
+
139.4 -> 174.4 (+25%); the 13MB gaps halved (5.8x -> 2.57x text,
|
|
249
|
+
5.14x -> 3.84x attr). macos attr-5MB measured -32% in the same run —
|
|
250
|
+
single-datapoint between-run variance on that row (two runs only);
|
|
251
|
+
watch it on the next run before treating as real.
|
|
252
|
+
|
|
253
|
+
Remaining 13MB terms: scratch (len, required) + pristine (len, A3d
|
|
254
|
+
parked on the borrowed-decl audit). NEXT LEVER CANDIDATES, in order:
|
|
255
|
+
(a) A3d pristine skip — needs the decl-views audit (direct_parse.c
|
|
256
|
+
borrowed version/encoding point INTO xml_buffer);
|
|
257
|
+
(b) parse-path arena reuse (thread-local spare-span recycle, the
|
|
258
|
+
#1846 warm-span idea applied to fresh parse arenas — amortizes the
|
|
259
|
+
per-doc mmap/fault churn that dominates large-doc create/free
|
|
260
|
+
loops);
|
|
261
|
+
(c) ubuntu-x86 scanner codegen (gcc-13; the 1.35-3.7x rows there are
|
|
262
|
+
now the widest platform gap).
|
|
263
|
+
|
|
264
|
+
## Track D addendum 5 — A3d (PR #2005) + AVX2 pre-scan (PR #2006) LANDED
|
|
265
|
+
|
|
266
|
+
A3d (pristine skip for the newline-free class), macos CI verdicts:
|
|
267
|
+
attr 13MB 174.4 -> 503.7 MB/s (+189%), text 13MB 794.2 -> 1366.9
|
|
268
|
+
(+72%); 13MB gaps 5.14x -> 2.18x attr, 5.80x -> 1.87x text across
|
|
269
|
+
the two cuts (#2003 census + #2005 pristine). The attr-5MB -32% from
|
|
270
|
+
addendum 4 was between-run variance (+78% this run). ubuntu ratios
|
|
271
|
+
held (that leg itself ran slower; pugixml moved with it).
|
|
272
|
+
|
|
273
|
+
count3_high's AVX2 kernel (#2006) TRANSFORMED the ubuntu-x86 lane —
|
|
274
|
+
the SCALAR sizing pre-scan was the dominant tax there, NOT scanner
|
|
275
|
+
codegen: attr 1.5MB 286.5 -> 582.7 MB/s (NOW AHEAD: 0.75x), attr
|
|
276
|
+
5MB 1.36x -> 0.93x, attr 13MB 1.36x -> 1.03x (parity), text
|
|
277
|
+
1.5/5/13MB 3.41x/3.37x/3.50x -> 1.45x/1.38x/1.69x. Runner variance
|
|
278
|
+
caveat noted (pugixml's rows moved too); the deltas are far outside
|
|
279
|
+
those bands.
|
|
280
|
+
|
|
281
|
+
Soundness note for A3d: parse_string frees the caller's buffer by
|
|
282
|
+
contract — the skip repoints xml_buffer at the doc-owned SCRATCH
|
|
283
|
+
(newline-free: no dp_nul clobber can lose a newline), never the
|
|
284
|
+
caller's const buffer. Teeth: NewlineTerminatedNameNeedsPristine
|
|
285
|
+
parses `a\n='1'` (whitespace before '=' is legal; an attr NAME can
|
|
286
|
+
be newline-terminated) — RED under unconditional skip, GREEN gated.
|
|
287
|
+
Two pin drafts discarded for wrong premises (element names are not
|
|
288
|
+
NUL'd; `<e a b='1'>` is malformed XML). Also learned: the eager
|
|
289
|
+
line-breaks table in direct_parse_internal is OOM-path-only; the
|
|
290
|
+
live resolver is node_public.c's lazy table off xml_buffer.
|
|
291
|
+
|
|
292
|
+
REMAINING (the honest tail): ubuntu-x86 text 1.38-1.69x, attr
|
|
293
|
+
0.75-1.03x (parity-to-ahead!), arm text ~1.9-2.1x, macos text 13MB
|
|
294
|
+
1.87x — the fused scanner loop is the one lever left, and the
|
|
295
|
+
platform picture is now win/parity-adjacent everywhere instead of
|
|
296
|
+
2-5x behind.
|
|
297
|
+
|
|
298
|
+
## Track D addendum 6 — the text-shape profile + the IL-default rejection (PR #2009)
|
|
299
|
+
|
|
300
|
+
Fresh no-inline text-shape attribution (300k elements, 19MB, classic
|
|
301
|
+
lane): direct_parse_internal own body 34% | text_scan_run_neon 17% |
|
|
302
|
+
dp_wire_child 9% | memmove (scratch copy) 8.2% | count3_neon 7.9% |
|
|
303
|
+
dp_text_create 7.4% | dp_parse_attrs 5% | pos journal 3.3% | edge
|
|
304
|
+
encode 3%.
|
|
305
|
+
|
|
306
|
+
LANDED: the no-attribute fast-out (dp_parse_attrs' 5% on a zero-attr
|
|
307
|
+
doc = per-element call + prologue + dup memset).
|
|
308
|
+
|
|
309
|
+
REJECTED BY MEASUREMENT: flipping LEPTRIS_INTERLEAVED's default on —
|
|
310
|
+
the IL lane measured 1.72x SLOWER user-CPU on the element-dense-
|
|
311
|
+
with-text 19MB fixture (the record pass + replay outweigh the fused
|
|
312
|
+
copy on this shape). The opt-in gate + 64KB threshold stand; the
|
|
313
|
+
lane's large-doc wins are shape-specific. (Second finding: the lane
|
|
314
|
+
is env-gated OFF in CI rows — every published bench_parse_ab number
|
|
315
|
+
is the classic lane.)
|
|
316
|
+
|
|
317
|
+
THE REMAINING ARC (unchanged): direct_parse_internal's own body —
|
|
318
|
+
the per-tag dispatch, name scan, close-tag match, and per-node
|
|
319
|
+
bookkeeping spread across wire/pos/edge-create. Instruction-level,
|
|
320
|
+
multi-session. The per-node bookkeeping share (wire 9% + text_create
|
|
321
|
+
7.4% + pos 3.3% + edge 3% = ~23%) is the largest coherent block;
|
|
322
|
+
a layout-level pass (fewer, wider stores per node) is the shape of
|
|
323
|
+
the next slice if the campaign continues.
|
|
324
|
+
|
|
325
|
+
## Track D addendum 6b — the fast-out's CI verdict + the macos-noise proof (PR #2009)
|
|
326
|
+
|
|
327
|
+
The no-attribute fast-out delivered on the stable legs: ubuntu-x86
|
|
328
|
+
attr 5/13MB +31-32% (13MB now PARITY at 0.99x), attr 1.5MB 0.72x
|
|
329
|
+
(win deepening), text 1.5/5/13MB +52/53/54% (1.27x/1.16x/1.46x);
|
|
330
|
+
ubuntu-arm text rows all up (937->978, 939->984, 872->906).
|
|
331
|
+
|
|
332
|
+
THE MACOS 13MB ROWS ARE RUNNER NOISE: attr-13MB measured
|
|
333
|
+
139.4 -> 174.4 -> 503.7 -> 104.3 MB/s across runs of
|
|
334
|
+
near-identical code (the cuts only ADD work-free fast paths) —
|
|
335
|
+
a 4.8x swing on one leg. Single-run macos attr/text-13MB datapoints
|
|
336
|
+
MUST NOT drive verdicts; the macos lane needs repeated-run medians
|
|
337
|
+
before any row there is called a regression or a win.
|
|
338
|
+
|
|
339
|
+
## Track D addendum 7 — the scanner arc OPENED (2026-11-11 evening)
|
|
340
|
+
|
|
341
|
+
Post-all-cuts text-shape samples (300k-element fixture, no-inline
|
|
342
|
+
build): direct_parse_internal's own body dominates the parse at
|
|
343
|
+
34-73% across samples — the per-tag dispatch loop (open scan, close
|
|
344
|
+
scan+match, text-run dispatch, elem carve/zero) is THE remaining
|
|
345
|
+
arc, exactly as the ledger predicted. The region split needs
|
|
346
|
+
inFunction attribution: the sample tool cannot see inside one frame,
|
|
347
|
+
so the next session's opening move is the noinline region-wrap probe
|
|
348
|
+
(close-tag region first — biggest single suspect; needs the
|
|
349
|
+
goto/label surgery threaded through DParser).
|
|
350
|
+
|
|
351
|
+
INSTRUMENT LAWS learned tonight: (1) `git checkout main -- <file>`
|
|
352
|
+
on a worktree branch copies from the STALE LOCAL main — always
|
|
353
|
+
`git checkout HEAD --` or origin/<ref>; it silently reverted the
|
|
354
|
+
fast-out mid-profile and produced one void sample. (2) The Bash tool
|
|
355
|
+
shell layers make `$!`/pgrep -f unreliable for backgrounding a
|
|
356
|
+
sample target — pgrep -x with the binary name + the process printing
|
|
357
|
+
its own getpid() is the reliable pattern. (3) Sample files written
|
|
358
|
+
into the wt/ worktree dirs vanished between commands (sandbox
|
|
359
|
+
sweep class) — write samples into the main repo tree and extract in
|
|
360
|
+
the same command.
|
|
361
|
+
|
|
362
|
+
ALSO this session: the interleaved-lane default flip REJECTED
|
|
363
|
+
(1.72x slower on element-dense text; addendum 6), and the
|
|
364
|
+
no-attribute fast-out SHIPPED (PR #2009, ubuntu-x86 attr-13MB to
|
|
365
|
+
parity). Release trains v1.9.416 + v1.9.417 sealed, all registries.
|
|
366
|
+
|
|
367
|
+
## Track D addendum 8 — the region split MEASURED (probe branch probe/close-region)
|
|
368
|
+
|
|
369
|
+
The close-tag region extracted NOINLINE (dp_close_tag_probe — the
|
|
370
|
+
instrument lives on probe/close-region, DO NOT MERGE) and sampled on
|
|
371
|
+
the post-fast-out text shape (~1250 in-frame samples):
|
|
372
|
+
|
|
373
|
+
- loop residual (open-tag scan + dispatch + elem carve/zero): 21%
|
|
374
|
+
- text-run family (scan_run_neon 17% + scalar wrapper 2.2% +
|
|
375
|
+
dp_text_create 8.5% + set_content 1.5%): ~29%
|
|
376
|
+
- wiring (dp_wire_child 9% + int32 encode 5.8% + edge_idx 0.7%): ~15%
|
|
377
|
+
- CLOSE-TAG REGION (probe 7.2% + pos_close_at 4.4%): 11.6%
|
|
378
|
+
- positions journal (pos_record 6.6% + the close_at share above): ~11%
|
|
379
|
+
- count3 pre-scan: 5.8%
|
|
380
|
+
|
|
381
|
+
Next-cut ranking by (size x boundedness):
|
|
382
|
+
1. text_scan_run's NEON residual (17% in-kernel — the chunk loop +
|
|
383
|
+
flag handling; an AVX2 mirror also lands for x86).
|
|
384
|
+
2. The loop residual's elem carve/zeroing (memset per 64-element
|
|
385
|
+
chunk vs explicit-init stores).
|
|
386
|
+
3. The positions journal (12% combined; SKIP_SOURCE_POSITIONS
|
|
387
|
+
already opts out — the default-on cost is the conformance/positions
|
|
388
|
+
faces' price).
|
|
389
|
+
The close-tag region (11.6%) has no obvious algorithmic cut — memcmp
|
|
390
|
+
fast paths already cover it.
|
|
391
|
+
|
|
392
|
+
## Track D addendum 8b — the scan-kernel analysis (2026-11-11, ranked cut #1 CLOSED as structural)
|
|
393
|
+
|
|
394
|
+
The text_scan_run NEON kernel read + analysis: the 17% in-kernel
|
|
395
|
+
share for the fixture-class run lengths (30-64B) is dominated by
|
|
396
|
+
PER-RUN FIXED COST — the call, the 3 needle vdup setups, the
|
|
397
|
+
accumulator zeroing, and one vmaxvq reduction per 16B chunk — not
|
|
398
|
+
per-byte throughput. The batched-reduction redesign (8 chunks
|
|
399
|
+
reduction-free, then chunk-rescan on hit) only wins runs >128B;
|
|
400
|
+
the bench-class runs break even or lose. The cut that actually
|
|
401
|
+
moves this block = merging the run scan INTO the caller's loop
|
|
402
|
+
(killing the per-run call+setup for short runs entirely), which is
|
|
403
|
+
the loop-body surgery slice — it inherits the region-wrap probe
|
|
404
|
+
(the text branch wraps the same way the close-tag region did).
|
|
405
|
+
|
|
406
|
+
RANKED CUT #1 therefore moves to the loop-surgery slice with the
|
|
407
|
+
scan-merge as its first step. Nothing ships from the kernel alone.
|
|
@@ -147,6 +147,11 @@ size_t decode_entity(const char* input, char* output, size_t outlen) {
|
|
|
147
147
|
while (input[in_pos]) {
|
|
148
148
|
char c = input[in_pos];
|
|
149
149
|
if (c == ';') {
|
|
150
|
+
/* The ';' belongs to the literal entity —
|
|
151
|
+
* emit it or the preserved spelling loses
|
|
152
|
+
* its terminator (© came back as
|
|
153
|
+
* ©). */
|
|
154
|
+
if (out_pos < outlen - 1) output[out_pos++] = ';';
|
|
150
155
|
in_pos++; /* Skip ';' */
|
|
151
156
|
break;
|
|
152
157
|
}
|
|
@@ -108,7 +108,7 @@ static void (*g_count3_fn)(const char*, size_t, char, char, char,
|
|
|
108
108
|
size_t*, size_t*, size_t*) = NULL;
|
|
109
109
|
static void (*g_count3_high_fn)(const char*, size_t, char, char, char,
|
|
110
110
|
size_t*, size_t*, size_t*,
|
|
111
|
-
int*) = NULL;
|
|
111
|
+
int*, size_t*, size_t*) = NULL;
|
|
112
112
|
static void (*g_copy3_fn)(char*, const char*, size_t, char, char, char,
|
|
113
113
|
size_t*, size_t*, size_t*) = NULL;
|
|
114
114
|
static int (*g_utf8_fn)(const char*, size_t) = NULL;
|
|
@@ -157,10 +157,16 @@ static void dispatch_init(void);
|
|
|
157
157
|
int leptris_utf8_valid_scalar(const char* s, size_t len);
|
|
158
158
|
int leptris_utf8_valid_avx2(const char* s, size_t len);
|
|
159
159
|
int leptris_utf8_valid_neon(const char* s, size_t len);
|
|
160
|
+
void leptris_text_count3_high_avx2(const char* s, size_t len,
|
|
161
|
+
char c0, char c1, char c2,
|
|
162
|
+
size_t* n0, size_t* n1, size_t* n2,
|
|
163
|
+
int* saw_high, size_t* amp_count,
|
|
164
|
+
size_t* valws_count);
|
|
160
165
|
static void count3_high_scalar(const char* s, size_t len,
|
|
161
166
|
char c0, char c1, char c2,
|
|
162
167
|
size_t* n0, size_t* n1, size_t* n2,
|
|
163
|
-
int* saw_high
|
|
168
|
+
int* saw_high, size_t* amp_count,
|
|
169
|
+
size_t* valws_count);
|
|
164
170
|
|
|
165
171
|
#if defined(_MSC_VER)
|
|
166
172
|
# pragma section(".CRT$XCU", read)
|
|
@@ -182,7 +188,7 @@ static void dispatch_init(void) {
|
|
|
182
188
|
g_contains_fn = leptris_text_contains_avx2;
|
|
183
189
|
g_find3_fn = leptris_text_find3_avx2;
|
|
184
190
|
g_count_fn = leptris_text_count_char_avx2;
|
|
185
|
-
g_count3_high_fn =
|
|
191
|
+
g_count3_high_fn = leptris_text_count3_high_avx2;
|
|
186
192
|
g_scan_run_fn = leptris_text_scan_run_avx2;
|
|
187
193
|
g_utf8_fn = leptris_utf8_valid_avx2;
|
|
188
194
|
return;
|
|
@@ -219,29 +225,37 @@ static void dispatch_init(void) {
|
|
|
219
225
|
static void count3_high_scalar(const char* s, size_t len,
|
|
220
226
|
char c0, char c1, char c2,
|
|
221
227
|
size_t* n0, size_t* n1, size_t* n2,
|
|
222
|
-
int* saw_high
|
|
228
|
+
int* saw_high, size_t* amp_count,
|
|
229
|
+
size_t* valws_count) {
|
|
223
230
|
size_t a = 0, b = 0, c = 0;
|
|
224
231
|
int h = 0;
|
|
232
|
+
size_t amp = 0, vws = 0;
|
|
225
233
|
for (size_t i = 0; i < len; i++) {
|
|
226
234
|
unsigned char ch = (unsigned char)s[i];
|
|
227
235
|
if (ch == (unsigned char)c0) a++;
|
|
228
236
|
if (ch == (unsigned char)c1) b++;
|
|
229
237
|
if (ch == (unsigned char)c2) c++;
|
|
230
238
|
if (ch & 0x80) h = 1;
|
|
239
|
+
if (ch == '&') amp++;
|
|
240
|
+
if (ch == 9 || ch == 10 || ch == 13) vws++;
|
|
231
241
|
}
|
|
232
242
|
*n0 = a;
|
|
233
243
|
*n1 = b;
|
|
234
244
|
*n2 = c;
|
|
235
245
|
*saw_high = h;
|
|
246
|
+
*amp_count = amp;
|
|
247
|
+
*valws_count = vws;
|
|
236
248
|
}
|
|
237
249
|
|
|
238
250
|
void leptris_text_count3_high(const char* s, size_t len,
|
|
239
251
|
char c0, char c1, char c2,
|
|
240
252
|
size_t* n0, size_t* n1, size_t* n2,
|
|
241
|
-
int* saw_high
|
|
253
|
+
int* saw_high, size_t* amp_count,
|
|
254
|
+
size_t* valws_count) {
|
|
242
255
|
if (!g_count3_high_fn) dispatch_init();
|
|
243
256
|
if (!g_count3_high_fn) g_count3_high_fn = count3_high_scalar;
|
|
244
|
-
g_count3_high_fn(s, len, c0, c1, c2, n0, n1, n2, saw_high
|
|
257
|
+
g_count3_high_fn(s, len, c0, c1, c2, n0, n1, n2, saw_high,
|
|
258
|
+
amp_count, valws_count);
|
|
245
259
|
}
|
|
246
260
|
|
|
247
261
|
int leptris_text_contains(const char* s, size_t len, char c) {
|
|
@@ -51,11 +51,19 @@ void leptris_text_count3(const char* s, size_t len,
|
|
|
51
51
|
/* count3 + "any byte >= 0x80" in one pass (#1842): the parser's
|
|
52
52
|
* sizing pre-scan doubles as the UTF-8 fast gate — pure-ASCII input
|
|
53
53
|
* is valid UTF-8 by construction. Falls back to the scalar loop
|
|
54
|
-
* where no SIMD path is compiled.
|
|
54
|
+
* where no SIMD path is compiled.
|
|
55
|
+
*
|
|
56
|
+
* *amp / *valws (#1842 Track D): counts of '&' and of literal
|
|
57
|
+
* tab/LF/CR — the two sources of content COPIES during parse
|
|
58
|
+
* (entity expansion, §3.3.3 attribute-value normalization). When
|
|
59
|
+
* both are zero the parser can drop the len-sized copy reservation
|
|
60
|
+
* from the arena estimate: a single-line entity-free document
|
|
61
|
+
* copies nothing. */
|
|
55
62
|
void leptris_text_count3_high(const char* s, size_t len,
|
|
56
63
|
char c0, char c1, char c2,
|
|
57
64
|
size_t* n0, size_t* n1, size_t* n2,
|
|
58
|
-
int* saw_high
|
|
65
|
+
int* saw_high, size_t* amp,
|
|
66
|
+
size_t* valws);
|
|
59
67
|
|
|
60
68
|
/* Returns 1 when [s, s+len) is valid UTF-8, 0 otherwise. SIMD
|
|
61
69
|
* boundary-vector validation (the Lemire/Steagall construction) with
|
|
@@ -139,7 +147,13 @@ void leptris_text_count3_neon(const char* s, size_t len,
|
|
|
139
147
|
void leptris_text_count3_high_neon(const char* s, size_t len,
|
|
140
148
|
char a, char b, char c,
|
|
141
149
|
size_t* ca, size_t* cb, size_t* cc,
|
|
142
|
-
int* saw_high
|
|
150
|
+
int* saw_high, size_t* amp,
|
|
151
|
+
size_t* valws);
|
|
152
|
+
void leptris_text_count3_high_avx2(const char* s, size_t len,
|
|
153
|
+
char a, char b, char c,
|
|
154
|
+
size_t* ca, size_t* cb, size_t* cc,
|
|
155
|
+
int* saw_high, size_t* amp,
|
|
156
|
+
size_t* valws);
|
|
143
157
|
void leptris_copy_count3_neon(char* dst, const char* src, size_t len,
|
|
144
158
|
char a, char b, char c,
|
|
145
159
|
size_t* ca, size_t* cb, size_t* cc);
|
|
@@ -110,6 +110,70 @@ size_t leptris_text_count_char_avx2(const char* s, size_t len, char c) {
|
|
|
110
110
|
return n;
|
|
111
111
|
}
|
|
112
112
|
|
|
113
|
+
/* count3_high — the parser's sizing pre-scan (TODO 183/#1842) with
|
|
114
|
+
* the Track D copy-census ('&' + tab/LF/CR). x86 previously fell
|
|
115
|
+
* back to the SCALAR kernel here (only the NEON TU had a SIMD
|
|
116
|
+
* count3_high), making the pre-scan one of the ubuntu lane's extra
|
|
117
|
+
* full-buffer passes. Five counters in one pass: three cmpeq+mask
|
|
118
|
+
* for c0/c1/c2, one for '&', and one for the OR of the three
|
|
119
|
+
* whitespace bytes (the trio is disjoint, so one popcount of the
|
|
120
|
+
* OR mask is the exact sum). */
|
|
121
|
+
void leptris_text_count3_high_avx2(const char* s, size_t len,
|
|
122
|
+
char c0, char c1, char c2,
|
|
123
|
+
size_t* n0, size_t* n1, size_t* n2,
|
|
124
|
+
int* saw_high, size_t* amp_count,
|
|
125
|
+
size_t* valws_count) {
|
|
126
|
+
const char* p = s;
|
|
127
|
+
const char* end = s + len;
|
|
128
|
+
const __m256i k0 = _mm256_set1_epi8(c0);
|
|
129
|
+
const __m256i k1 = _mm256_set1_epi8(c1);
|
|
130
|
+
const __m256i k2 = _mm256_set1_epi8(c2);
|
|
131
|
+
const __m256i kamp = _mm256_set1_epi8('&');
|
|
132
|
+
const __m256i kt = _mm256_set1_epi8('\t');
|
|
133
|
+
const __m256i kn = _mm256_set1_epi8('\n');
|
|
134
|
+
const __m256i kr = _mm256_set1_epi8('\r');
|
|
135
|
+
size_t a = 0, b = 0, c = 0, amp = 0, vws = 0;
|
|
136
|
+
int h = 0;
|
|
137
|
+
|
|
138
|
+
while (end - p >= 32) {
|
|
139
|
+
__m256i v = _mm256_loadu_si256((const __m256i*)p);
|
|
140
|
+
a += (size_t)LEPTRIS_POPCOUNT32((unsigned)_mm256_movemask_epi8(
|
|
141
|
+
_mm256_cmpeq_epi8(v, k0)));
|
|
142
|
+
b += (size_t)LEPTRIS_POPCOUNT32((unsigned)_mm256_movemask_epi8(
|
|
143
|
+
_mm256_cmpeq_epi8(v, k1)));
|
|
144
|
+
c += (size_t)LEPTRIS_POPCOUNT32((unsigned)_mm256_movemask_epi8(
|
|
145
|
+
_mm256_cmpeq_epi8(v, k2)));
|
|
146
|
+
amp += (size_t)LEPTRIS_POPCOUNT32((unsigned)_mm256_movemask_epi8(
|
|
147
|
+
_mm256_cmpeq_epi8(v, kamp)));
|
|
148
|
+
__m256i ws = _mm256_or_si256(
|
|
149
|
+
_mm256_or_si256(_mm256_cmpeq_epi8(v, kt),
|
|
150
|
+
_mm256_cmpeq_epi8(v, kn)),
|
|
151
|
+
_mm256_cmpeq_epi8(v, kr));
|
|
152
|
+
vws += (size_t)LEPTRIS_POPCOUNT32((unsigned)_mm256_movemask_epi8(ws));
|
|
153
|
+
/* any byte >= 0x80: sign bits via the packed-compare trick —
|
|
154
|
+
* movemask of the sign bits of v (cmp with 0 keeps them) */
|
|
155
|
+
h |= (_mm256_movemask_epi8(_mm256_cmpgt_epi8(
|
|
156
|
+
_mm256_setzero_si256(), v)) != 0);
|
|
157
|
+
p += 32;
|
|
158
|
+
}
|
|
159
|
+
while (p < end) {
|
|
160
|
+
unsigned char ch = (unsigned char)*p;
|
|
161
|
+
if (ch == (unsigned char)c0) a++;
|
|
162
|
+
if (ch == (unsigned char)c1) b++;
|
|
163
|
+
if (ch == (unsigned char)c2) c++;
|
|
164
|
+
if (ch == '&') amp++;
|
|
165
|
+
if (ch == 9 || ch == 10 || ch == 13) vws++;
|
|
166
|
+
if (ch & 0x80) h = 1;
|
|
167
|
+
p++;
|
|
168
|
+
}
|
|
169
|
+
*n0 = a;
|
|
170
|
+
*n1 = b;
|
|
171
|
+
*n2 = c;
|
|
172
|
+
*saw_high = h;
|
|
173
|
+
*amp_count = amp;
|
|
174
|
+
*valws_count = vws;
|
|
175
|
+
}
|
|
176
|
+
|
|
113
177
|
#endif /* LEPTRIS_ARCH_X86 && __AVX2__ */
|
|
114
178
|
|
|
115
179
|
/* #1842: one-pass text-run scan — AVX2 mirror of the NEON kernel:
|
|
@@ -151,35 +151,61 @@ void leptris_text_count3_neon(const char* s, size_t len,
|
|
|
151
151
|
void leptris_text_count3_high_neon(const char* s, size_t len,
|
|
152
152
|
char c0, char c1, char c2,
|
|
153
153
|
size_t* n0, size_t* n1, size_t* n2,
|
|
154
|
-
int* saw_high
|
|
154
|
+
int* saw_high, size_t* amp_count,
|
|
155
|
+
size_t* valws_count) {
|
|
155
156
|
const char* p = s;
|
|
156
157
|
const char* end = s + len;
|
|
157
158
|
const uint8x16_t k0 = vdupq_n_u8((uint8_t)c0);
|
|
158
159
|
const uint8x16_t k1 = vdupq_n_u8((uint8_t)c1);
|
|
159
160
|
const uint8x16_t k2 = vdupq_n_u8((uint8_t)c2);
|
|
161
|
+
/* '&' + the §3.3.3 value-whitespace trio: content-copy census
|
|
162
|
+
* for the arena budget (Track D). tab|lf|cr as ONE accumulator:
|
|
163
|
+
* the budget only asks "any present?", not the exact count —
|
|
164
|
+
* but the counter stays exact to keep the kernel contract
|
|
165
|
+
* uniform with the scalar oracle. */
|
|
166
|
+
const uint8x16_t kamp = vdupq_n_u8('&');
|
|
160
167
|
size_t a = 0, b = 0, c = 0;
|
|
161
168
|
uint16x8_t a0 = vdupq_n_u16(0), a1 = vdupq_n_u16(0), a2 = vdupq_n_u16(0);
|
|
169
|
+
uint16x8_t amp_acc = vdupq_n_u16(0);
|
|
170
|
+
uint16x8_t both_acc = vdupq_n_u16(0);
|
|
162
171
|
uint8x16_t hi = vdupq_n_u8(0);
|
|
163
172
|
size_t since_flush = 0;
|
|
173
|
+
size_t amp = 0, vws = 0;
|
|
164
174
|
|
|
165
175
|
while (end - p >= 16) {
|
|
166
176
|
uint8x16_t v = vld1q_u8((const uint8_t*)p);
|
|
167
177
|
a0 = vpadalq_u8(a0, vshrq_n_u8(vceqq_u8(v, k0), 7));
|
|
168
178
|
a1 = vpadalq_u8(a1, vshrq_n_u8(vceqq_u8(v, k1), 7));
|
|
169
179
|
a2 = vpadalq_u8(a2, vshrq_n_u8(vceqq_u8(v, k2), 7));
|
|
180
|
+
{
|
|
181
|
+
uint8x16_t mamp = vshrq_n_u8(vceqq_u8(v, kamp), 7);
|
|
182
|
+
uint8x16_t mws = vshrq_n_u8(vorrq_u8(
|
|
183
|
+
vorrq_u8(vceqq_u8(v, vdupq_n_u8(9)),
|
|
184
|
+
vceqq_u8(v, vdupq_n_u8(10))),
|
|
185
|
+
vceqq_u8(v, vdupq_n_u8(13))), 7);
|
|
186
|
+
both_acc = vpadalq_u8(both_acc, vorrq_u8(mamp, mws));
|
|
187
|
+
amp_acc = vpadalq_u8(amp_acc, mamp);
|
|
188
|
+
}
|
|
170
189
|
hi = vorrq_u8(hi, vshrq_n_u8(v, 7));
|
|
171
190
|
p += 16;
|
|
172
191
|
if (++since_flush == 1024) {
|
|
173
192
|
a += (size_t)vaddvq_u16(a0);
|
|
174
193
|
b += (size_t)vaddvq_u16(a1);
|
|
175
194
|
c += (size_t)vaddvq_u16(a2);
|
|
176
|
-
|
|
195
|
+
amp += (size_t)vaddvq_u16(amp_acc);
|
|
196
|
+
vws += (size_t)vaddvq_u16(both_acc)
|
|
197
|
+
- (size_t)vaddvq_u16(amp_acc);
|
|
198
|
+
uint16x8_t zero = vdupq_n_u16(0);
|
|
199
|
+
a0 = a1 = a2 = zero;
|
|
200
|
+
amp_acc = both_acc = zero;
|
|
177
201
|
since_flush = 0;
|
|
178
202
|
}
|
|
179
203
|
}
|
|
180
204
|
a += (size_t)vaddvq_u16(a0);
|
|
181
205
|
b += (size_t)vaddvq_u16(a1);
|
|
182
206
|
c += (size_t)vaddvq_u16(a2);
|
|
207
|
+
amp += (size_t)vaddvq_u16(amp_acc);
|
|
208
|
+
vws += (size_t)vaddvq_u16(both_acc) - (size_t)vaddvq_u16(amp_acc);
|
|
183
209
|
int h = vmaxvq_u8(hi) != 0;
|
|
184
210
|
while (p < end) {
|
|
185
211
|
unsigned char ch = (unsigned char)*p;
|
|
@@ -187,12 +213,16 @@ void leptris_text_count3_high_neon(const char* s, size_t len,
|
|
|
187
213
|
if (ch == (unsigned char)c1) b++;
|
|
188
214
|
if (ch == (unsigned char)c2) c++;
|
|
189
215
|
if (ch & 0x80) h = 1;
|
|
216
|
+
if (ch == '&') amp++;
|
|
217
|
+
if (ch == 9 || ch == 10 || ch == 13) vws++;
|
|
190
218
|
p++;
|
|
191
219
|
}
|
|
192
220
|
*n0 = a;
|
|
193
221
|
*n1 = b;
|
|
194
222
|
*n2 = c;
|
|
195
223
|
*saw_high = h;
|
|
224
|
+
*amp_count = amp;
|
|
225
|
+
*valws_count = vws;
|
|
196
226
|
}
|
|
197
227
|
|
|
198
228
|
/* Fused copy + three counters in ONE memory pass (TODO 188). The
|
|
@@ -1526,7 +1526,15 @@ LEPTRIS_API size_t leptris_element_attribute_pairs(
|
|
|
1526
1526
|
a; a = leptris_attr_next(a)) {
|
|
1527
1527
|
if (written >= max_count) break;
|
|
1528
1528
|
if (out_names) out_names[written] = attr_cname(a);
|
|
1529
|
-
|
|
1529
|
+
/* The values column serves the SAME view the per-attribute
|
|
1530
|
+
* getter does — decoded (XML 1.0 §4.6: character references
|
|
1531
|
+
* decode in attribute values exactly as in content). The
|
|
1532
|
+
* raw views belong to leptris_element_attributes_raw
|
|
1533
|
+
* (#635). Decoding caches into the attribute (the entities
|
|
1534
|
+
* flag clears), so repeat bulk reads skip the work. The
|
|
1535
|
+
* element's pool carries the decoded copies. */
|
|
1536
|
+
if (out_values) out_values[written] =
|
|
1537
|
+
leptris_attribute_get_value(elem, (LeptrisAttribute)a);
|
|
1530
1538
|
if (out_attrs) out_attrs[written] = (LeptrisAttribute)a;
|
|
1531
1539
|
written++;
|
|
1532
1540
|
}
|
|
@@ -1518,7 +1518,9 @@ static struct leptris_document* direct_parse_internal(char* buf, size_t len,
|
|
|
1518
1518
|
int recover,
|
|
1519
1519
|
size_t lt_count_in,
|
|
1520
1520
|
size_t dq_count_in,
|
|
1521
|
-
size_t sq_count_in
|
|
1521
|
+
size_t sq_count_in,
|
|
1522
|
+
size_t amp_count_in,
|
|
1523
|
+
size_t valws_count_in) {
|
|
1522
1524
|
|
|
1523
1525
|
/* 2. Create arena-backed pool (TODO 183 Phase 3).
|
|
1524
1526
|
*
|
|
@@ -1561,6 +1563,28 @@ static struct leptris_document* direct_parse_internal(char* buf, size_t len,
|
|
|
1561
1563
|
* pre-scan doubles as the UTF-8 fast gate there — #1842). */
|
|
1562
1564
|
size_t lt_count = lt_count_in, dq_count = dq_count_in,
|
|
1563
1565
|
sq_count = sq_count_in;
|
|
1566
|
+
/* Track D: '&' and literal tab/LF/CR are the ONLY sources of
|
|
1567
|
+
* content copies at parse time (entity expansion, §3.3.3
|
|
1568
|
+
* attribute-value normalization). A document carrying neither
|
|
1569
|
+
* copies nothing — the len-sized copy reservation below drops
|
|
1570
|
+
* to zero for that class (machine-generated single-line XML,
|
|
1571
|
+
* the serialbench/bench shapes), taking arena_size from
|
|
1572
|
+
* ~3x len to ~2x len. Any '&' or any of the three whitespace
|
|
1573
|
+
* bytes keeps the full worst-case bound: tab/newline/CR
|
|
1574
|
+
* structural use (pretty-printed docs) conservatively re-arms
|
|
1575
|
+
* it, and CR-only line endings keep it armed. */
|
|
1576
|
+
int has_copy_sources = (amp_count_in != 0 || valws_count_in != 0);
|
|
1577
|
+
/* Track D A3d: the pristine copy exists so doc->xml_buffer stays
|
|
1578
|
+
* byte-identical to the input — the lazy line table (#223)
|
|
1579
|
+
* counts '\n' against it, and dp_nul may clobber a newline that
|
|
1580
|
+
* TERMINATES a name or value. A document with NO literal
|
|
1581
|
+
* tab/LF/CR (valws census == 0) has no newlines to lose and no
|
|
1582
|
+
* line breaks to resolve: the scratch itself answers every line
|
|
1583
|
+
* query (line 1 everywhere), so the carve + full-buffer memcpy
|
|
1584
|
+
* drop for that class. doc->encoding/xml_version are
|
|
1585
|
+
* heap-strdup'd at finalize (the comment below was stale — they
|
|
1586
|
+
* never borrow xml_buffer at rest), so nothing else reads it. */
|
|
1587
|
+
int can_skip_pristine = (valws_count_in == 0);
|
|
1564
1588
|
pristine = buf; /* owns_buffer == 0: caller's buffer — never
|
|
1565
1589
|
* written, never freed. const_input overwrites
|
|
1566
1590
|
* this below with the arena-carved copy. */
|
|
@@ -1582,7 +1606,7 @@ static struct leptris_document* direct_parse_internal(char* buf, size_t len,
|
|
|
1582
1606
|
* at item 4144/5000 with 38 bytes left when this term was
|
|
1583
1607
|
* missing). */
|
|
1584
1608
|
size_t node_overhead = est_elems * 64;
|
|
1585
|
-
size_t text_room = len + node_overhead;
|
|
1609
|
+
size_t text_room = (has_copy_sources ? len : 0) + node_overhead;
|
|
1586
1610
|
/* Mutation headroom + floor. The 64KB floor kept small parsed
|
|
1587
1611
|
* documents mutation-ready, but it also pushed EVERY small-doc
|
|
1588
1612
|
* span into the allocator's medium bin - the teardown pays
|
|
@@ -1607,7 +1631,9 @@ static struct leptris_document* direct_parse_internal(char* buf, size_t len,
|
|
|
1607
1631
|
size_t pos_bytes = (est_elems + 8) * sizeof(struct leptris_elem_pos_entry);
|
|
1608
1632
|
size_t scratch_bytes = (len + 1 + 64 + 15u) & ~(size_t)15u;
|
|
1609
1633
|
size_t pristine_bytes =
|
|
1610
|
-
const_input
|
|
1634
|
+
(const_input && !can_skip_pristine)
|
|
1635
|
+
? ((len + 1 + 15u) & ~(size_t)15u)
|
|
1636
|
+
: 0u;
|
|
1611
1637
|
/* Round 10: the owning pool struct carves the arena head. */
|
|
1612
1638
|
size_t pool_bytes =
|
|
1613
1639
|
(sizeof(LeptrisMemoryPool) + 15u) & ~(size_t)15u;
|
|
@@ -1633,7 +1659,7 @@ static struct leptris_document* direct_parse_internal(char* buf, size_t len,
|
|
|
1633
1659
|
memcpy(scratch, buf, len);
|
|
1634
1660
|
scratch[len] = '\0';
|
|
1635
1661
|
memset(scratch + len + 1, 0, 64);
|
|
1636
|
-
if (const_input) {
|
|
1662
|
+
if (const_input && !can_skip_pristine) {
|
|
1637
1663
|
pristine = (char*)leptris_pool_alloc(pool, len + 1);
|
|
1638
1664
|
if (!pristine) {
|
|
1639
1665
|
leptris_pool_destroy(pool);
|
|
@@ -1643,6 +1669,14 @@ static struct leptris_document* direct_parse_internal(char* buf, size_t len,
|
|
|
1643
1669
|
pristine[len] = '\0';
|
|
1644
1670
|
}
|
|
1645
1671
|
buf = scratch;
|
|
1672
|
+
/* A3d skip: xml_buffer must remain DOC-OWNED (parse_string's
|
|
1673
|
+
* contract frees the caller's buffer right after the call —
|
|
1674
|
+
* the lazy line table reads xml_buffer for the document's
|
|
1675
|
+
* lifetime). With the pristine carve skipped, the doc reads
|
|
1676
|
+
* the scratch: byte-different from the input at dp_nul points,
|
|
1677
|
+
* but a newline-free document loses no newlines, so every line
|
|
1678
|
+
* query still answers exactly. */
|
|
1679
|
+
if (const_input && can_skip_pristine) pristine = scratch;
|
|
1646
1680
|
|
|
1647
1681
|
/* 3. Bulk-allocate element + attribute blocks as ONE contiguous
|
|
1648
1682
|
* arena bump. Layout: [ elem_block | attr_block ]
|
|
@@ -2122,9 +2156,34 @@ static struct leptris_document* direct_parse_internal(char* buf, size_t len,
|
|
|
2122
2156
|
p.pos = dp_scan_name_fused(p.pos, &name_hash, &name_colon,
|
|
2123
2157
|
&name_len);
|
|
2124
2158
|
|
|
2125
|
-
/*
|
|
2126
|
-
|
|
2127
|
-
|
|
2159
|
+
/* No-attribute fast-out (Track D, text-shape profile
|
|
2160
|
+
* 2026-11-11: dp_parse_attrs was 5% of a ZERO-attr
|
|
2161
|
+
* document — the call + reset prologue + dup-table memset
|
|
2162
|
+
* per element). '>' or '/' directly after the name means
|
|
2163
|
+
* no attributes: two stores instead of the call. Any
|
|
2164
|
+
* other delimiter (whitespace, '?', unexpected bytes)
|
|
2165
|
+
* falls through to the full parser. */
|
|
2166
|
+
unsigned elem_delim =
|
|
2167
|
+
leptris_chartype_table[(unsigned char)*p.pos];
|
|
2168
|
+
int self_closing;
|
|
2169
|
+
if (elem_delim & (CT_ATTR_GT | CT_ATTR_SLASH)) {
|
|
2170
|
+
p.current_elem_last_attr = NULL;
|
|
2171
|
+
p.current_elem_last_ns = NULL;
|
|
2172
|
+
p.raw_last = NULL;
|
|
2173
|
+
p.cur_elem_cache = NULL;
|
|
2174
|
+
p.attr_dup_used = 0; /* no adds: stale slots unprobed */
|
|
2175
|
+
if (elem_delim & CT_ATTR_GT) {
|
|
2176
|
+
p.pos++;
|
|
2177
|
+
self_closing = 0;
|
|
2178
|
+
} else {
|
|
2179
|
+
if (p.pos[1] != '>') goto fail;
|
|
2180
|
+
p.pos += 2;
|
|
2181
|
+
self_closing = 1;
|
|
2182
|
+
}
|
|
2183
|
+
} else {
|
|
2184
|
+
self_closing = dp_parse_attrs(&p, elem);
|
|
2185
|
+
if (self_closing < 0) goto fail;
|
|
2186
|
+
}
|
|
2128
2187
|
if (ho_line_offsets_ok &&
|
|
2129
2188
|
!(p.skip_flags & LEPTRIS_PARSE_SKIP_SOURCE_POSITIONS)) {
|
|
2130
2189
|
uint32_t ste = (uint32_t)(p.pos - p.buf);
|
|
@@ -2613,8 +2672,9 @@ static struct leptris_document* direct_parse_internal(char* buf, size_t len,
|
|
|
2613
2672
|
leptris_dtd_apply_attribute_defaults(doc);
|
|
2614
2673
|
doc->had_declaration = p.had_declaration;
|
|
2615
2674
|
doc->standalone = p.standalone;
|
|
2616
|
-
/* encoding
|
|
2617
|
-
*
|
|
2675
|
+
/* encoding/xml_version arrive as scratch views; they are
|
|
2676
|
+
* heap-strdup'd here (doc_free LEPTRIS_FREEs them) — nothing
|
|
2677
|
+
* borrows xml_buffer for them at rest. */
|
|
2618
2678
|
if (p.encoding) {
|
|
2619
2679
|
doc->encoding = strdup(p.encoding);
|
|
2620
2680
|
if (!doc->encoding) goto fail;
|
|
@@ -3116,7 +3176,15 @@ static struct leptris_document* dp_il_build(
|
|
|
3116
3176
|
uint32_t* brks = (uint32_t*)malloc(cap * sizeof(uint32_t));
|
|
3117
3177
|
if (!brks) goto oom_pool;
|
|
3118
3178
|
for (size_t q = 0; q < len; q++) {
|
|
3119
|
-
|
|
3179
|
+
/* PRISTINE, not scratch: dp_nul may have overwritten a
|
|
3180
|
+
* newline that terminated a name/value in the scratch —
|
|
3181
|
+
* the table must count the INPUT's newlines (the
|
|
3182
|
+
* NewlineTerminatedNameNeedsPristine pin caught the
|
|
3183
|
+
* scratch scan: <t/> after a newline-terminated name
|
|
3184
|
+
* resolved one line low). With the A3d skip (valws==0)
|
|
3185
|
+
* pristine aliases the scratch and holds no newlines,
|
|
3186
|
+
* so the table is empty and every query answers line 1. */
|
|
3187
|
+
if (scratch[q] != '\n') continue; /* FALSIFICATION */
|
|
3120
3188
|
if (n_ == cap) {
|
|
3121
3189
|
cap *= 2;
|
|
3122
3190
|
uint32_t* g = (uint32_t*)realloc(
|
|
@@ -3459,6 +3527,8 @@ int leptris_il_run(const char* xml, size_t len, int drop_ws,
|
|
|
3459
3527
|
size_t toff, tlen;
|
|
3460
3528
|
if (!leptris_il_scan(scratch, len, drop_ws, c, root_out, &toff,
|
|
3461
3529
|
&tlen)) {
|
|
3530
|
+
if (getenv("LEPTRIS_PROBE_IL"))
|
|
3531
|
+
fprintf(stderr, "IL FALLBACK: il_scan rejected len=%zu\n", len);
|
|
3462
3532
|
leptris_il_run_free(c, scratch);
|
|
3463
3533
|
return 0;
|
|
3464
3534
|
}
|
|
@@ -3566,7 +3636,12 @@ static struct leptris_document* dp_il_try(const char* xml, size_t len,
|
|
|
3566
3636
|
* overrides (bytes; 0 = no threshold) for hosts and for the
|
|
3567
3637
|
* parity gates, which force it to 0 so the lane stays covered
|
|
3568
3638
|
* by the suite at fixture sizes. */
|
|
3569
|
-
if (len < dp_env_memo.min_len)
|
|
3639
|
+
if (len < dp_env_memo.min_len) {
|
|
3640
|
+
if (getenv("LEPTRIS_PROBE_IL"))
|
|
3641
|
+
fprintf(stderr, "IL SKIP: below min_len=%zu len=%zu\n",
|
|
3642
|
+
dp_env_memo.min_len, len);
|
|
3643
|
+
return NULL;
|
|
3644
|
+
}
|
|
3570
3645
|
|
|
3571
3646
|
/* Scratch is built UP FRONT (slice 2): il_scan reads it with
|
|
3572
3647
|
* the NUL-sentinel discipline, and dp_il_build reuses the same
|
|
@@ -3704,8 +3779,10 @@ struct leptris_document* direct_parse(const char* xml, size_t len) {
|
|
|
3704
3779
|
if (!xml || len == 0) return NULL;
|
|
3705
3780
|
size_t lt_count, dq_count, sq_count;
|
|
3706
3781
|
int saw_high = 0;
|
|
3782
|
+
size_t amp_count, valws_count;
|
|
3707
3783
|
leptris_text_count3_high(xml, len, '<', '"', '\'',
|
|
3708
|
-
<_count, &dq_count, &sq_count, &saw_high
|
|
3784
|
+
<_count, &dq_count, &sq_count, &saw_high,
|
|
3785
|
+
&_count, &valws_count);
|
|
3709
3786
|
/* A declared non-UTF-8 encoding is EXEMPT from validation
|
|
3710
3787
|
* (dp_declares_non_utf8 == 1: its bytes are legitimate in the
|
|
3711
3788
|
* declared encoding and transcode downstream — leptris-ruby#514).
|
|
@@ -3718,7 +3795,8 @@ struct leptris_document* direct_parse(const char* xml, size_t len) {
|
|
|
3718
3795
|
if (d) return d;
|
|
3719
3796
|
}
|
|
3720
3797
|
return direct_parse_internal((char*)xml, len, 0, 2, 0, 0, 0, 0,
|
|
3721
|
-
lt_count, dq_count, sq_count
|
|
3798
|
+
lt_count, dq_count, sq_count,
|
|
3799
|
+
amp_count, valws_count);
|
|
3722
3800
|
}
|
|
3723
3801
|
|
|
3724
3802
|
/* Public flagged entry (LEPTRIS_PARSE_DROP_WS_TEXT et al.). */
|
|
@@ -3727,8 +3805,10 @@ struct leptris_document* direct_parse_flags(const char* xml, size_t len,
|
|
|
3727
3805
|
if (!xml || len == 0) return NULL;
|
|
3728
3806
|
size_t lt_count, dq_count, sq_count;
|
|
3729
3807
|
int saw_high = 0;
|
|
3808
|
+
size_t amp_count, valws_count;
|
|
3730
3809
|
leptris_text_count3_high(xml, len, '<', '"', '\'',
|
|
3731
|
-
<_count, &dq_count, &sq_count, &saw_high
|
|
3810
|
+
<_count, &dq_count, &sq_count, &saw_high,
|
|
3811
|
+
&_count, &valws_count);
|
|
3732
3812
|
/* RECOVER keeps the #1660 best-effort contract (never NULL for
|
|
3733
3813
|
* malformed input); the fatal encoding check is strict-lane. */
|
|
3734
3814
|
if (!(parse_flags & LEPTRIS_PARSE_RECOVER) &&
|
|
@@ -3758,7 +3838,8 @@ struct leptris_document* direct_parse_flags(const char* xml, size_t len,
|
|
|
3758
3838
|
? 1 : 0,
|
|
3759
3839
|
(parse_flags & LEPTRIS_PARSE_RECOVER)
|
|
3760
3840
|
? 1 : 0,
|
|
3761
|
-
lt_count, dq_count, sq_count
|
|
3841
|
+
lt_count, dq_count, sq_count,
|
|
3842
|
+
amp_count, valws_count);
|
|
3762
3843
|
}
|
|
3763
3844
|
|
|
3764
3845
|
/* Public: parse a caller-owned writable buffer without copying. */
|
|
@@ -3766,8 +3847,10 @@ struct leptris_document* direct_parse_inplace(char* buf, size_t len) {
|
|
|
3766
3847
|
if (!buf || len == 0) return NULL;
|
|
3767
3848
|
size_t lt_count, dq_count, sq_count;
|
|
3768
3849
|
int saw_high = 0;
|
|
3850
|
+
size_t amp_count, valws_count;
|
|
3769
3851
|
leptris_text_count3_high(buf, len, '<', '"', '\'',
|
|
3770
|
-
<_count, &dq_count, &sq_count, &saw_high
|
|
3852
|
+
<_count, &dq_count, &sq_count, &saw_high,
|
|
3853
|
+
&_count, &valws_count);
|
|
3771
3854
|
/* Declared non-UTF-8 is exempt (see direct_parse). */
|
|
3772
3855
|
if (!dp_declares_non_utf8(buf, len) && saw_high &&
|
|
3773
3856
|
!dp_utf8_valid(buf, len))
|
|
@@ -3777,5 +3860,6 @@ struct leptris_document* direct_parse_inplace(char* buf, size_t len) {
|
|
|
3777
3860
|
* INSIDE the buffer; an exactly-sized caller trips ASAN, and
|
|
3778
3861
|
* bindings hand read-only views). The scanner takes `len`. */
|
|
3779
3862
|
return direct_parse_internal(buf, len, 0, 0, 0, 0, 0, 0,
|
|
3780
|
-
lt_count, dq_count, sq_count
|
|
3863
|
+
lt_count, dq_count, sq_count,
|
|
3864
|
+
amp_count, valws_count);
|
|
3781
3865
|
}
|
|
@@ -119,6 +119,7 @@ leptris_add_test(test_parser parser/test_parser.cpp)
|
|
|
119
119
|
leptris_add_test(test_large_docs parser/test_large_documents.cpp)
|
|
120
120
|
leptris_add_test(test_encoding parser/test_encoding.cpp)
|
|
121
121
|
leptris_add_test(test_utf8_simd parser/test_utf8_simd.cpp)
|
|
122
|
+
leptris_add_test(test_entity_decode parser/test_entity_decode.cpp)
|
|
122
123
|
leptris_add_test(test_dom dom/test_dom.cpp)
|
|
123
124
|
leptris_add_test(test_element_children dom/test_element_children.cpp)
|
|
124
125
|
leptris_add_test(test_entity_refs dom/test_entity_refs.cpp)
|
|
@@ -1698,6 +1698,100 @@ TEST(NodeLine, ReportsOneBasedLineOfParsedNodes) {
|
|
|
1698
1698
|
leptris_document_free(doc);
|
|
1699
1699
|
}
|
|
1700
1700
|
|
|
1701
|
+
/* A3d (Track D): a document with no literal tab/LF/CR skips the
|
|
1702
|
+
* pristine buffer carve entirely — the scratch answers every line
|
|
1703
|
+
* query (line 1 everywhere). The declaration fields must survive
|
|
1704
|
+
* (they are heap-strdup'd at finalize, never borrowed from the
|
|
1705
|
+
* pristine at rest), line resolution must stay exact, and a
|
|
1706
|
+
* malformed single-line document must still report line 1. */
|
|
1707
|
+
TEST(NodeLine, NewlineFreeDocSkipsPristineButKeepsContract) {
|
|
1708
|
+
/* > 4 KB so the parse takes the classic lane at a realistic
|
|
1709
|
+
* size; declaration present; attributes dense; zero newlines. */
|
|
1710
|
+
std::string xml =
|
|
1711
|
+
"<?xml version=\"1.0\" encoding=\"UTF-8\"?><r>";
|
|
1712
|
+
for (int i = 0; i < 300; i++) {
|
|
1713
|
+
xml += "<e id='";
|
|
1714
|
+
xml += std::to_string(i);
|
|
1715
|
+
xml += "' name='item' type='widget' stock='7' price='1.50'/>";
|
|
1716
|
+
}
|
|
1717
|
+
xml += "</r>";
|
|
1718
|
+
LeptrisStatus st = LEPTRIS_OK;
|
|
1719
|
+
LeptrisDocument doc =
|
|
1720
|
+
leptris_parse_string(xml.data(), xml.size(), &st);
|
|
1721
|
+
ASSERT_NE(doc, nullptr);
|
|
1722
|
+
LeptrisElement root = leptris_document_root(doc);
|
|
1723
|
+
ASSERT_NE(root, nullptr);
|
|
1724
|
+
/* Every node resolves to line 1 through the scratch line table. */
|
|
1725
|
+
EXPECT_EQ(leptris_node_line(leptris_element_as_node(root)), 1);
|
|
1726
|
+
LeptrisElement a = leptris_element_first_child_any(root);
|
|
1727
|
+
ASSERT_NE(a, nullptr);
|
|
1728
|
+
LeptrisElement last = a;
|
|
1729
|
+
int count = 0;
|
|
1730
|
+
for (LeptrisElement c = a; c;
|
|
1731
|
+
c = leptris_element_next_sibling_any(c)) {
|
|
1732
|
+
EXPECT_EQ(leptris_node_line(leptris_element_as_node(c)), 1);
|
|
1733
|
+
last = c;
|
|
1734
|
+
count++;
|
|
1735
|
+
}
|
|
1736
|
+
EXPECT_EQ(count, 300);
|
|
1737
|
+
/* Deep attribute read still works off the scratch views. */
|
|
1738
|
+
EXPECT_STREQ(leptris_element_attribute(last, "name"), "item");
|
|
1739
|
+
/* Declaration fields survive the skipped carve. */
|
|
1740
|
+
EXPECT_STREQ(leptris_document_encoding(doc), "UTF-8");
|
|
1741
|
+
leptris_document_free(doc);
|
|
1742
|
+
}
|
|
1743
|
+
|
|
1744
|
+
TEST(NodeLine, NewlineTerminatedNameNeedsPristine) {
|
|
1745
|
+
/* THE clobber case: an ATTRIBUTE NAME terminated directly by a
|
|
1746
|
+
* newline (`a` ends at the newline before `b`). dp_nul
|
|
1747
|
+
* overwrites that newline with NUL in the scratch when the
|
|
1748
|
+
* attribute parses — the lazy line table (built from
|
|
1749
|
+
* doc->xml_buffer on first query) must still count the INPUT's
|
|
1750
|
+
* newline, or every node after it resolves one line low. True
|
|
1751
|
+
* lines: <r>=1, <e=2, text=3 (its tag ends line 3? no — the
|
|
1752
|
+
* element's line is its '<'; text sits on line 3), <t/>=4. */
|
|
1753
|
+
/* Legal XML: whitespace between an attribute name and '='.
|
|
1754
|
+
* The attr name `a` terminates at the newline (dp_nul clobbers
|
|
1755
|
+
* it when `a` parses); everything after resolves against the
|
|
1756
|
+
* INPUT's newline set via doc->xml_buffer. */
|
|
1757
|
+
const char xml[] =
|
|
1758
|
+
"<r>\n<e a\n='1'>text</e>\n<t/>\n</r>\n";
|
|
1759
|
+
LeptrisStatus st = LEPTRIS_OK;
|
|
1760
|
+
LeptrisDocument doc = leptris_parse_string(xml, std::strlen(xml), &st);
|
|
1761
|
+
ASSERT_NE(doc, nullptr);
|
|
1762
|
+
LeptrisElement root = leptris_document_root(doc);
|
|
1763
|
+
LeptrisElement e = leptris_element_first_child_any(root);
|
|
1764
|
+
ASSERT_NE(e, nullptr);
|
|
1765
|
+
EXPECT_EQ(leptris_node_line(leptris_element_as_node(root)), 1);
|
|
1766
|
+
EXPECT_EQ(leptris_node_line(leptris_element_as_node(e)), 2);
|
|
1767
|
+
LeptrisNodeRef text = leptris_node_first_child(
|
|
1768
|
+
leptris_element_as_node(e));
|
|
1769
|
+
ASSERT_NE(text, nullptr);
|
|
1770
|
+
EXPECT_EQ(leptris_node_get_type(text), LEPTRIS_NODE_TYPE_TEXT);
|
|
1771
|
+
/* Lines: \n@3 ends line 1; \n@6 (the clobbered one — `a`'s
|
|
1772
|
+
* terminator) ends line 2; text's offset is past @6, before @17
|
|
1773
|
+
* → line 3. A scratch-derived table loses @6 and answers 2. */
|
|
1774
|
+
EXPECT_EQ(leptris_node_line(text), 3)
|
|
1775
|
+
<< "text must resolve against the INPUT's newlines";
|
|
1776
|
+
LeptrisElement t = leptris_element_next_sibling_any(e);
|
|
1777
|
+
ASSERT_NE(t, nullptr);
|
|
1778
|
+
EXPECT_EQ(leptris_node_line(leptris_element_as_node(t)), 4);
|
|
1779
|
+
leptris_document_free(doc);
|
|
1780
|
+
}
|
|
1781
|
+
|
|
1782
|
+
TEST(NodeLine, NewlineFreeMalformedDocReportsLineOne) {
|
|
1783
|
+
const char xml[] =
|
|
1784
|
+
"<?xml version=\"1.0\" encoding=\"UTF-8\"?><r><a></r>";
|
|
1785
|
+
LeptrisStatus st = LEPTRIS_OK;
|
|
1786
|
+
LeptrisDocument doc =
|
|
1787
|
+
leptris_parse_string(xml, std::strlen(xml), &st);
|
|
1788
|
+
EXPECT_EQ(doc, nullptr);
|
|
1789
|
+
EXPECT_NE(st, LEPTRIS_OK);
|
|
1790
|
+
int line = -1, col = -1;
|
|
1791
|
+
leptris_last_error_position(&line, &col);
|
|
1792
|
+
EXPECT_EQ(line, 1);
|
|
1793
|
+
}
|
|
1794
|
+
|
|
1701
1795
|
TEST(NodeSourcePosition, ReportsParserRecordedElementColumns) {
|
|
1702
1796
|
const char xml[] =
|
|
1703
1797
|
"<root><a x='1'/><b>text</b><multi\n"
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// Entity decode: unknown named entities preserved byte-exact in
|
|
2
|
+
// lenient mode (libxml2/pugixml semantics). The decode_entity core
|
|
3
|
+
// consumed the terminating ';' without emitting it — unknown refs
|
|
4
|
+
// came back one character short (© 2026). Found via the
|
|
5
|
+
// lutaml/moxml#540 investigation (the binding faces route unknown
|
|
6
|
+
// entities through this same core).
|
|
7
|
+
#include <leptris.h>
|
|
8
|
+
#include <leptris/dom/document.h>
|
|
9
|
+
#include <gtest/gtest.h>
|
|
10
|
+
#include <cstring>
|
|
11
|
+
|
|
12
|
+
TEST(EntityDecode, UnknownNamedEntityPreservesSemicolon) {
|
|
13
|
+
const char* xml = "<r a=\"© 2026\">x © y</r>";
|
|
14
|
+
LeptrisStatus st = LEPTRIS_OK;
|
|
15
|
+
LeptrisDocument doc =
|
|
16
|
+
leptris_parse_string(xml, std::strlen(xml), &st);
|
|
17
|
+
ASSERT_NE(doc, nullptr);
|
|
18
|
+
LeptrisElement root = leptris_document_root(doc);
|
|
19
|
+
EXPECT_STREQ(leptris_element_attribute(root, "a"), "© 2026");
|
|
20
|
+
LeptrisNodeRef t =
|
|
21
|
+
leptris_node_first_child(leptris_element_as_node(root));
|
|
22
|
+
ASSERT_NE(t, nullptr);
|
|
23
|
+
EXPECT_STREQ(leptris_text_node_get_content(t), "x © y");
|
|
24
|
+
leptris_document_free(doc);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
TEST(EntityDecode, UnknownEntityMixedWithKnownDecodesBoth) {
|
|
28
|
+
/* © and are HTML-only — in XML they are unknown
|
|
29
|
+
* entities and stay literal (byte-exact, semicolons included);
|
|
30
|
+
* only the five predefined entities decode. */
|
|
31
|
+
const char* xml =
|
|
32
|
+
"<r v=\"& © <\">&<</r>";
|
|
33
|
+
LeptrisStatus st = LEPTRIS_OK;
|
|
34
|
+
LeptrisDocument doc =
|
|
35
|
+
leptris_parse_string(xml, std::strlen(xml), &st);
|
|
36
|
+
ASSERT_NE(doc, nullptr);
|
|
37
|
+
LeptrisElement root = leptris_document_root(doc);
|
|
38
|
+
EXPECT_STREQ(leptris_element_attribute(root, "v"),
|
|
39
|
+
"& © <");
|
|
40
|
+
EXPECT_STREQ(
|
|
41
|
+
leptris_text_node_get_content(
|
|
42
|
+
leptris_node_first_child(leptris_element_as_node(root))),
|
|
43
|
+
"&<");
|
|
44
|
+
|
|
45
|
+
/* The bulk pairs export serves the decoded values column too —
|
|
46
|
+
* the binding's listing faces route through it (moxml#540). */
|
|
47
|
+
const char* names[4];
|
|
48
|
+
const char* values[4];
|
|
49
|
+
size_t n = leptris_element_attribute_pairs(
|
|
50
|
+
root, names, values, NULL, 4);
|
|
51
|
+
ASSERT_EQ(n, 1u);
|
|
52
|
+
EXPECT_STREQ(values[0], "& © <");
|
|
53
|
+
leptris_document_free(doc);
|
|
54
|
+
}
|
|
@@ -6,6 +6,10 @@
|
|
|
6
6
|
extern "C" {
|
|
7
7
|
void leptris_text_count3(const char* s, size_t len, char c0, char c1,
|
|
8
8
|
char c2, size_t* n0, size_t* n1, size_t* n2);
|
|
9
|
+
void leptris_text_count3_high(const char* s, size_t len, char c0,
|
|
10
|
+
char c1, char c2, size_t* n0, size_t* n1,
|
|
11
|
+
size_t* n2, int* saw_high, size_t* amp,
|
|
12
|
+
size_t* valws);
|
|
9
13
|
void leptris_copy_count3(char* dst, const char* src, size_t len,
|
|
10
14
|
char c0, char c1, char c2,
|
|
11
15
|
size_t* n0, size_t* n1, size_t* n2);
|
|
@@ -76,29 +80,31 @@ TEST(Count3Kernels, LargeMixedInput) {
|
|
|
76
80
|
* Counts must match text_count3 EXACTLY at every length (the same
|
|
77
81
|
* arena-sizing contract), including across the SIMD body / scalar
|
|
78
82
|
* tail boundary and with high bytes straddling it. */
|
|
79
|
-
extern "C" {
|
|
80
|
-
void leptris_text_count3_high(const char* s, size_t len, char c0,
|
|
81
|
-
char c1, char c2, size_t* n0, size_t* n1,
|
|
82
|
-
size_t* n2, int* saw_high);
|
|
83
|
-
}
|
|
84
83
|
|
|
85
84
|
namespace {
|
|
86
85
|
|
|
87
86
|
void expect_high(const char* s, size_t len) {
|
|
88
87
|
size_t e0 = 0, e1 = 0, e2 = 0, ehi = 0;
|
|
88
|
+
size_t eamp = 0, evws = 0;
|
|
89
89
|
for (size_t i = 0; i < len; i++) {
|
|
90
90
|
if (s[i] == '<') e0++;
|
|
91
91
|
if (s[i] == '"') e1++;
|
|
92
92
|
if (s[i] == '\'') e2++;
|
|
93
93
|
if ((unsigned char)s[i] >= 0x80) ehi++;
|
|
94
|
+
if (s[i] == '&') eamp++;
|
|
95
|
+
if (s[i] == '\t' || s[i] == '\n' || s[i] == '\r') evws++;
|
|
94
96
|
}
|
|
95
97
|
size_t a = 1, b = 1, c = 1;
|
|
96
98
|
int hi = -1;
|
|
97
|
-
|
|
99
|
+
size_t amp = 1, vws = 1;
|
|
100
|
+
leptris_text_count3_high(s, len, '<', '"', '\'', &a, &b, &c, &hi,
|
|
101
|
+
&, &vws);
|
|
98
102
|
EXPECT_EQ(a, e0) << "count3_high c0 len=" << len;
|
|
99
103
|
EXPECT_EQ(b, e1) << "count3_high c1 len=" << len;
|
|
100
104
|
EXPECT_EQ(c, e2) << "count3_high c2 len=" << len;
|
|
101
105
|
EXPECT_EQ(hi, ehi > 0 ? 1 : 0) << "count3_high saw_high len=" << len;
|
|
106
|
+
EXPECT_EQ(amp, eamp) << "count3_high amp len=" << len;
|
|
107
|
+
EXPECT_EQ(vws, evws) << "count3_high valws len=" << len;
|
|
102
108
|
// cross-check against the plain kernel
|
|
103
109
|
size_t p0 = 0, p1 = 0, p2 = 0;
|
|
104
110
|
leptris_text_count3(s, len, '<', '"', '\'', &p0, &p1, &p2);
|
|
@@ -135,4 +141,30 @@ TEST(SimdCountHigh, EmptyAndTiny) {
|
|
|
135
141
|
const char* h = "\xc3\xa9";
|
|
136
142
|
expect_high(h, 2);
|
|
137
143
|
}
|
|
144
|
+
|
|
145
|
+
/* The amp/valws counters feed the parse arena's content-copy budget
|
|
146
|
+
* (TODO Track D): amp_count == 0 AND valws_count == 0 lets the
|
|
147
|
+
* parser drop the len-sized copy reservation (entity expansion and
|
|
148
|
+
* §3.3.3 value normalization are the only copy sources). Exactness
|
|
149
|
+
* at the chunk boundaries is the contract, same as the byte
|
|
150
|
+
* counters. */
|
|
151
|
+
TEST(SimdCountHigh, AmpAndValueWsAtEveryBoundary) {
|
|
152
|
+
// '&' / '\t' / '\n' / '\r' walked across every position relative
|
|
153
|
+
// to the 16-byte SIMD body and the scalar tail
|
|
154
|
+
const char inserts[] = {'&', '\t', '\n', '\r'};
|
|
155
|
+
for (char ins : inserts) {
|
|
156
|
+
for (size_t pad = 0; pad < 40; pad++) {
|
|
157
|
+
std::string s(pad, 'y');
|
|
158
|
+
s += ins;
|
|
159
|
+
s += "<x a='1' b=\"2\">t</x>";
|
|
160
|
+
expect_high(s.data(), s.size());
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
TEST(SimdCountHigh, CleanOneLinerHasZeroAmpValws) {
|
|
166
|
+
// the machine-generated class the arena copy-budget keys on
|
|
167
|
+
const char s[] = "<r><e a0='value-0-xyz' a1='value-1-xyz'/></r>";
|
|
168
|
+
expect_high(s, sizeof(s) - 1);
|
|
169
|
+
}
|
|
138
170
|
} // namespace
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://raw.githubusercontent.com/microsoft/vcpkg/master/scripts/vcpkg.schema.json",
|
|
3
3
|
"name": "leptris",
|
|
4
|
-
"version": "1.9.
|
|
4
|
+
"version": "1.9.418",
|
|
5
5
|
"description": "High-performance XML parser and XPath 1.0 engine in C (libleptris)",
|
|
6
6
|
"homepage": "https://github.com/leptris/leptris",
|
|
7
7
|
"license": "MIT",
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: leptris
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.9.
|
|
4
|
+
version: 1.9.418.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ribose Inc.
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-11-
|
|
11
|
+
date: 2026-11-12 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: ffi
|
|
@@ -889,6 +889,7 @@ files:
|
|
|
889
889
|
- vendor-src/libleptris/test/memory/test_pool.cpp
|
|
890
890
|
- vendor-src/libleptris/test/memory/test_pool_arena.cpp
|
|
891
891
|
- vendor-src/libleptris/test/parser/test_encoding.cpp
|
|
892
|
+
- vendor-src/libleptris/test/parser/test_entity_decode.cpp
|
|
892
893
|
- vendor-src/libleptris/test/parser/test_interleaved.cpp
|
|
893
894
|
- vendor-src/libleptris/test/parser/test_large_documents.cpp
|
|
894
895
|
- vendor-src/libleptris/test/parser/test_parser.cpp
|