leptris 1.9.414.0-arm-linux → 1.9.416.0-arm-linux

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4864527e515d9dcdac57bb5a51886ccd6d094a462013e0e45fc1234220666b2f
4
- data.tar.gz: dc60156ea72506ec0d46394bc6f8d7be5a49039170d08c6813354ae2a4eaacf3
3
+ metadata.gz: 4c3936d53266d00e41017103cd020a9c9532b34890a25cd2bf471072384972aa
4
+ data.tar.gz: 0d20df50328eb150b13c6d420f8599388a35b987eedfdece10e2f164d2a06c08
5
5
  SHA512:
6
- metadata.gz: e21a19d9dd5f87abe5d0dc557a93c0ca57f10eb4c7a5747442e7bdb9d69fcb6e26416a141274c600d4ab79f78c0026991c1eeeb1dd3a273835c76d1029190980
7
- data.tar.gz: 8f7f1c41343e2bd3bd4ece424ebbc30124f957654303ce73b45ef5fb75b7c40a7276931dfcf5e7056eaa053e1659f95478a1c8571676eac412f44a401b50af8d
6
+ metadata.gz: eed647c5e390b4fc0b7b1c58deeab732aded11c00da9e29e45f3457d18aec9ae64be20484c8a1ea387c885cdf2167ecde9c8ea51798ce9e434caefe2cb315ba4
7
+ data.tar.gz: 84da4874579bf98b5034ce82c9cd39cd43b0bc6ef3e680ec5834d516254b8318dbd07bd79a9cd168f1fe150e3dba2334eb6b11704a26eaa488ac1f335662fa15
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.414"
11
+ LIBLEPTRIS_VERSION = "1.9.416"
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Leptris
4
- VERSION = "1.9.414.0"
4
+ VERSION = "1.9.416.0"
5
5
  end
data/lib/libleptris.so CHANGED
Binary file
data/vendor-src/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  Sources vendored in this gem (recompile rights; the ruby
2
2
  variant builds them at install via extconf.rb):
3
3
 
4
- - libleptris v1.9.414
4
+ - libleptris v1.9.416
5
5
  - utf8proc v2.11.0
6
6
 
7
7
  Rebuild by hand:
@@ -1,5 +1,29 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [1.9.416] - 2026-11-11
4
+ ## Performance
5
+
6
+ - **parse: the attribute dup-table stops rehashing small documents** (#1842 Track D). Growth was ×8, so an element with ≥14 attributes blew the 14-slot threshold inside a 16-slot table and every such document paid a 512B pool alloc + memset + full rehash on its first element; later elements memset 512B each. ×2 growth keeps the common ≤16-attr element at 32 slots (load ≤50%, ~1 probe step) with no growth, and wide elements still grow geometrically.
7
+ - **parse: the dup-probe fast path is inlined** in `dp_add_attr_inline` — the per-attribute out-of-line call (alloc/grow slow-paths stay out-of-line) was ~10% of the no-inline attrparse profile. Canonical CI bench: ~30-45 ns/doc on the attr-dense shape.
8
+
9
+ ## Benchmarks
10
+
11
+ - **The attrparse row is CI-gated and platform-split.** `bench_append_attr_pugixml` now runs in the Benchmark workflow on quiet GH runners (Release + LTO, min of 5) with a new ubuntu-24.04-arm leg. First gated rows: macos-latest **1.11x win** (1830.8 vs 2036.6 ns/doc); ubuntu-24.04-arm 1.13x behind (gcc-13 + glibc, mild); ubuntu-latest x86-64 1.46x behind — the extra ~30% is isolated as **x86-64-specific codegen of the fused scanner under gcc-13** (same toolchain family on arm64 is healthy; gcc-16/arm64 builds leptris faster than clang locally). Run-to-run CI variance is ~5-10%; all verdicts sit outside that band.
12
+ - The same run's `bench_parse_ab` names the next parse gaps with CI-gated shape data: text-shape parse 1.6x behind pugixml on macos and 3.3x on ubuntu-x86; documents at ~13MB collapse to 5.1-5.8x behind on macos (the arena reservation sums ~3x the input length — scratch + pristine + text-room are each len-sized). Full ledger in `TODO.max-perf/15` Track D.
13
+
14
+ ## Documentation
15
+
16
+ - README's attribute-dense section now reads from CI artifacts with the platform-split table; negative results ledgered so they are not re-attempted (inline 16B SIMD value scan = 20% regression at ~11-byte values; count3 small-doc skip dead-ends into an allocator-bin cliff; the interleaved lane is not faster below the small-doc threshold).
17
+
18
+ ## [1.9.415] - 2026-11-10
19
+ ## Performance
20
+
21
+ - **parse: single-pass attribute-name scan** (#1842 attrparse arc, agent-implemented). `dp_parse_attrs` classified the byte after every attribute name twice — the fused name scan stopped on a non-name-char with its chartype already in a register, then a second fused-classification call re-loaded and re-tested the same byte. The scan now captures the stop byte's full class (`DP_CT_NAME_CHAR` mirrors IS_NAME_CHAR's bits) and the `=` dispatch consumes it directly; whitespace continues inline; all error paths, hash order, colon tracking, and NUL discipline byte-identical. User-CPU on the attribute-dense attrparse workload: **−4.2% quiet / −1.8% interleaved-under-load**. Suite 2250/2250; two negative results from the same slice documented in the commit (a noise-level dup-probe skip, and a `need_dup_hash` loop-hoist that *regressed* 17% under LTO — reverted).
22
+
23
+ ## Benchmarks
24
+
25
+ - The attrparse comparison rows (v1.9.414) already use the corrected parse+read methodology; this release narrows the remaining gap to pugixml on that shape by ~4%.
26
+
3
27
  ## [1.9.414] - 2026-11-08
4
28
  ## Performance
5
29
 
@@ -3,7 +3,7 @@
3
3
  cmake_minimum_required(VERSION 3.20)
4
4
 
5
5
  project(leptris
6
- VERSION 1.9.414
6
+ VERSION 1.9.416
7
7
  DESCRIPTION "Fast XML parser and XPath evaluator in pure C"
8
8
  LANGUAGES C CXX
9
9
  )
@@ -1060,11 +1060,11 @@ attribute uniqueness rule.
1060
1060
  |Benchmark |Leptris |pugixml |Advantage
1061
1061
 
1062
1062
  |Append 10000 children (one parent)
1063
- |160 µs
1064
- |119 µs
1065
- |1.3× slower (measured; was 2.5× faster pre-attr-index — the doc-level
1066
- index bookkeeping is the cost of O(1) duplicate-rejecting
1067
- set_attribute at scale)
1063
+ |22.7 ns/child
1064
+ |36.0 ns/child
1065
+ |**1.6× faster** (fresh `bench_append_attr_pugixml` run; the
1066
+ doc-level index bookkeeping cost noted in earlier revisions was
1067
+ removed by the lane-18 append/attr work)
1068
1068
 
1069
1069
  |Set 2000 attributes (duplicate-rejecting)
1070
1070
  |347 µs
@@ -1082,6 +1082,66 @@ set_attribute at scale)
1082
1082
  |1.1× slower (measured; the two are at parity within run noise)
1083
1083
  |===
1084
1084
 
1085
+ ==== Attribute-dense parse+read (vs pugixml) — 2026-11 refresh
1086
+
1087
+ Numbers from `bench_append_attr_pugixml`, CI-gated since this
1088
+ revision: the bench runs in the Benchmark workflow on quiet GH
1089
+ runners (Release + LTO, min of 5) on ubuntu-latest, ubuntu-24.04-arm,
1090
+ and macos-latest — the rows below are those artifacts, not local
1091
+ runs. The bench's attrparse row is parse + free per document (20k
1092
+ docs, 4 elements x 16 attributes); the local parse+walk+read
1093
+ harness numbers are noted separately.
1094
+
1095
+ [cols="2,>1,>1,>1",options="header"]
1096
+ |===
1097
+ |Benchmark (parse + free, CI-gated) |Leptris |pugixml |Verdict
1098
+
1099
+ |macos-latest
1100
+ |1728.6 ns/doc
1101
+ |2182.9 ns/doc
1102
+ |**1.26x faster**
1103
+
1104
+ |ubuntu-latest (x86-64, gcc-13)
1105
+ |2798.6 ns/doc
1106
+ |1885.2 ns/doc
1107
+ |1.48x slower — platform anomaly under investigation (TODO.max-perf/15 Track D)
1108
+
1109
+ |Door A (skip dup + positions), ubuntu
1110
+ |2572.7 ns/doc
1111
+ |1885.2 ns/doc
1112
+ |1.37x slower
1113
+
1114
+ |Full-window CPU-clock head-to-head, 4M docs (local, LTO both sides)
1115
+ |5.45 s user
1116
+ |5.45 s user
1117
+ |equal — user-CPU parity
1118
+ |===
1119
+
1120
+ Findings carried in `TODO.max-perf/15` Track D (the follow-up arc to
1121
+ #1842): the ubuntu deficit is leptris-specific (pugixml runs FASTER
1122
+ on ubuntu than macos; gcc-16/arm64 builds leptris faster than clang,
1123
+ so the arm64/gcc dimension is healthy — the arm64-ubuntu CI lane
1124
+ splits gcc-13-x86 codegen from glibc); text-shape parse trails
1125
+ pugixml ~1.6x on macos; documents at ~13 MB collapse to ~5x behind
1126
+ (the arena reservation sums ~3x the input length: scratch + pristine
1127
+ + text room). The dup-table and dup-probe cuts above ship in this
1128
+ revision.
1129
+
1130
+ ==== Recent performance wins (v1.9.410-v1.9.414)
1131
+
1132
+ Each release-verified via ABBA with fresh RelWithDebInfo+LTO builds:
1133
+
1134
+ * **+29%** HTML parse (#1218 arena-span + tag-id slices)
1135
+ * **+6.4%** XPath scoreboard row — `//a | //b` unions fuse to one
1136
+ doc-ordered pass (v1.9.412)
1137
+ * **+3.5%** parse — loop-invariant parser fields hoisted to const
1138
+ locals (v1.9.413)
1139
+ * **+1-2%** parse — the pool string_cache created lazily on first
1140
+ intern instead of eagerly per document (v1.9.414)
1141
+ * **1.011x / 1.018x** — node-test hash pre-filter, fused
1142
+ name-scan+hash-split (v1.9.411-412)
1143
+
1144
+
1085
1145
  See also `benchmarks/README.md` for the decomposition benchmark
1086
1146
  (`benchmark_decomp`: isolates text/element/attr/text-node costs)
1087
1147
  and the SAX benchmark (`benchmark_sax`: leptris vs libxml2 SAX2 —
@@ -131,3 +131,110 @@ whole tree to assign ranks (#485 table).
131
131
  - #1218: arena estimates only ever grow.
132
132
 
133
133
  Refs #1842, serialbench-c#8.
134
+
135
+ ## Track D — attr-dense parse+read row (post-#1842 closure, 2026-11-11)
136
+
137
+ The row's CI gate was missing: `bench_append_attr_pugixml` was NOT in
138
+ the benchmark.yml binary list, so the attrparse row had no
139
+ quiet-runner arbiter (the 2026-11-09 numbers were local). NOW WIRED
140
+ (this commit): the binary joins the CI benchmark legs (ubuntu + macos,
141
+ Release + LTO, quiet GH runners). The row's verdict comes from those
142
+ artifacts.
143
+
144
+ Fresh profile (2026-11-11, no-inline attribution, attrparse shape 4x16
145
+ attrs): dp_parse_attrs 37% | dp_add_attr_inline 20% | dup table 10% |
146
+ strlen faces 10% | count3-neon 4.3% | attributes_raw 3.7% | map
147
+ mutex+TLS 2.7% | dp_nul 2%.
148
+
149
+ Cut ledger:
150
+ - [x] dup-table growth x8 -> x2 (16-attr elements no longer pay a
151
+ 512B rehash per doc).
152
+ - [x] dup-probe fast path INLINED in dp_add_attr_inline (~30-45
153
+ ns/doc; the per-attr out-of-line call was the cost).
154
+ - [x] REVERTED: inline 16B SIMD value scan (NEON/SSE2) — a 20%
155
+ REGRESSION for the ~11-byte values the shape has: one chunk of
156
+ 5x cmpeq + vpadd-ladder movemask loses to the branch-fused
157
+ scalar table loop at short lengths. The 48-byte inline probe
158
+ threshold was already tuned; do not re-attempt below ~64B.
159
+ - [ ] count3 small-doc inline: DEAD END — without the scan the
160
+ arena sizing needs len-derived upper bounds that over-reserve
161
+ ~3x and push small-doc arenas into bigger allocator bins
162
+ (the madvise teardown cost the slack floor already fights).
163
+ - [ ] A3d pristine-copy skip for newline-free docs (count3 gains a
164
+ 4th counter): PARKED — the declaration's version/encoding
165
+ views BORROW doc->xml_buffer; switching them to the scratch
166
+ needs the borrowed-pointer topology audited first.
167
+ - The interleaved lane (LEPTRIS_IL_MIN=0) is NOT faster on this
168
+ shape (measured; the small-doc threshold stands).
169
+
170
+ Local measurement discipline note: under parallel agent load,
171
+ leptris degrades ~20% while pugixml stays flat (leptris's scratch +
172
+ pristine + arena working set is far more cache-sensitive). Loaded
173
+ ratios are meaningless; the CI artifacts gate this row from here on.
174
+
175
+ ## Track D addendum — the first CI-gated numbers (2026-11-11, PR #2001)
176
+
177
+ bench_append_attr_pugixml's first quiet-runner rows SPLIT BY PLATFORM:
178
+ - macos-latest: leptris 1728.6 vs pugixml 2182.9 — leptris 1.26x WIN.
179
+ - ubuntu-latest: leptris 2798.6 vs pugixml 1885.2 — leptris 1.48x LOSS.
180
+
181
+ The ubuntu anomaly is NOT attr-specific: benchmark_parse (tiny/small/
182
+ medium, cold-start) shows pugixml ahead on BOTH legs at 0.52-0.65x
183
+ (macos) but 0.31-0.40x (ubuntu) — the ubuntu factor roughly DOUBLES
184
+ leptris's deficit on every small-parse shape. pugixml is FASTER on
185
+ ubuntu than macos (1885 vs 2183), so runner speed does not explain it.
186
+
187
+ Compiler dimension isolated locally: gcc-16/arm64 builds leptris
188
+ FASTER than clang (1428 vs 1500, same machine, same clang-built
189
+ pugixml dylib) — the arm64/gcc dimension is healthy. The suspect set
190
+ is gcc-13 x86-64 codegen on the fused scanner or a glibc interaction;
191
+ ubuntu-24.04-arm joins the benchmark matrix to split the dimension
192
+ (same gcc-13 + glibc, different arch+codegen).
193
+
194
+ Slack-floor shrink for small docs: DO NOT re-attempt — #1846
195
+ falsified it (the retained pool amortizes the reservation; measured
196
+ 0.9743x = negative).
197
+
198
+ ## Track D addendum 2 — the three parse-vs-pugixml gaps (CI-gated, 2026-11-11)
199
+
200
+ bench_parse_ab in the same CI run (shape-fair MB/s) splits the parse
201
+ deficit into three NAMED gaps, none attr-specific:
202
+
203
+ 1. **Text-shape scanner gap**: text 1.5/5MB = leptris 1290-1322 MB/s
204
+ vs pugixml 2086-2199 (1.6x) on macos; 573-577 vs 1896 (3.3x!) on
205
+ ubuntu. This is Track A's scanner surgery with a platform shape:
206
+ the text-run fused loop is where the ubuntu-x86 codegen collapses.
207
+ 2. **The 13MB collapse (macos)**: attr 502->139 MB/s, text 1290->362
208
+ as the doc grows to 13MB (5.1-5.8x behind). The arena reservation
209
+ sums ~3x len (scratch_bytes + pristine_bytes + text_room are EACH
210
+ len-sized, plus elem/attr/slack terms) -> ~40MB reserved + 2
211
+ full memcpys per parse. Levers: drop the pristine copy when the
212
+ input has no newlines (A3d, parked on the borrowed-pointer audit),
213
+ and fold text_room into scratch (text nodes are substrings of the
214
+ scratch; text_room's 64B/node overhead is the only true extra).
215
+ 3. **The ubuntu x-factor**: leptris 2798 vs its own macos 1728 on the
216
+ SAME source+flags (62% self-slowdown) while pugixml runs FASTER on
217
+ ubuntu (1885 vs 2183). gcc-16/arm64 local = healthy. The
218
+ ubuntu-24.04-arm CI lane (this PR) splits gcc-13-x86 codegen from
219
+ glibc. Candidate micro-levers once the dimension is known:
220
+ -fno-plt / mmap-threshold pinning (mallopt) / loop restructuring
221
+ where gcc-13 jump-threading bails.
222
+
223
+ ## Track D addendum 3 — the ubuntu dimension RESOLVED (2026-11-11, all three CI legs)
224
+
225
+ attrparse rows from the final three-leg CI run (same commit):
226
+ - macos-latest (clang arm64): leptris 1830.8 vs pugixml 2036.6 — WIN 1.11x.
227
+ - ubuntu-24.04-arm (gcc-13 + glibc, arm64): 2091.7 vs 1850.3 — loss 1.13x.
228
+ - ubuntu-latest (gcc-13 + glibc, x86-64): 2793.4 vs 1914.7 — loss 1.46x.
229
+
230
+ Decomposition: gcc-13+glibc on arm64 costs ~0.02-0.2x (mild); the
231
+ EXTRA ~30% penalty is x86-64-SPECIFIC codegen of the fused scanner
232
+ under gcc-13. The lever: gcc-13-x86 scanner codegen (jump-threading /
233
+ register allocation in direct_parse_internal), CI-leg-verified with
234
+ the x86 lane as the gate. pugixml again ran FASTER on ubuntu hardware
235
+ than macos on both linux legs — the hardware/allocator dimension
236
+ favors it; leptris's own linux penalty is the 1.13x arm number.
237
+
238
+ Also note run-to-run variance: the macos attrparse pair measured
239
+ 1728/2183 then 1831/2037 across runs (~5-10%) — treat sub-10% CI
240
+ deltas as noise bands; the win/loss verdicts above sit outside them.
@@ -49,6 +49,16 @@ extern "C" {
49
49
  /**
50
50
  * Parse XML string into document
51
51
  *
52
+ * Parsing is EAGER and SYNCHRONOUS: the full node tree is built
53
+ * before the call returns, so the first access costs the same as
54
+ * every later one (verified against the 2026-11-10 benchmark
55
+ * artifact where a no-touch loop was mistaken for deferred
56
+ * construction — the loop never re-entered the parser per
57
+ * iteration). Only two facets stay lazy by design INSIDE the
58
+ * built tree: predefined entity text (& < ...) materializes
59
+ * on first text read, and per-element namespace caches fill on
60
+ * first namespace query.
61
+ *
52
62
  * @param xml XML string (must be valid UTF-8)
53
63
  * @param length Length of XML string in bytes
54
64
  * @param status Output status code (can be NULL)
@@ -314,9 +314,17 @@ static LEPTRIS_ALWAYS_INLINE unsigned dp_class_after_ws(DParser* p) {
314
314
  * inline loop. */
315
315
  #if defined(__GNUC__)
316
316
  # define DP_UNLIKELY(x) __builtin_expect(!!(x), 0)
317
+ # define DP_LIKELY(x) __builtin_expect(!!(x), 1)
317
318
  #else
318
319
  # define DP_UNLIKELY(x) (x)
320
+ # define DP_LIKELY(x) (x)
319
321
  #endif
322
+ /* The name-char mask IS_NAME_CHAR tests, spelled out so the fused
323
+ * attr-name scan can keep the stop byte's FULL chartype class in a
324
+ * register (the delimiter byte after the name is whitespace or '=';
325
+ * its class is already in hand from the scan's table load — a
326
+ * dp_class_after_ws re-load of the same byte is pure overhead). */
327
+ #define DP_CT_NAME_CHAR (CT_NAME | CT_NAME_START | CT_UTF8)
320
328
  /* Round 6: value-scan stop tables. One table load + one test per
321
329
  * byte replaces the three-compare chain - pugixml's ct_parse_attr
322
330
  * loop shape. 0 = boring, 1 = this value's quote, 2 = '&', 3 = ws.
@@ -538,7 +546,13 @@ static int dp_dup_seen_or_add(DParser* p, uint32_t dh) {
538
546
  p->attr_dup_mask = 15;
539
547
  p->attr_dup_used = 0;
540
548
  } else if ((p->attr_dup_used + 1) * 8 >= (p->attr_dup_mask + 1) * 7) {
541
- size_t ncap = (p->attr_dup_mask + 1) * 8;
549
+ /* ×2 growth (was ×8): a 16-attr element hit the 14-slot
550
+ * threshold inside a 16-slot table, so EVERY such doc paid a
551
+ * 512B alloc + memset + full rehash on its first element, and
552
+ * every later element memset 512B. 32 slots (load ≤50% at 16
553
+ * attrs) keeps the probe at ~1 step; wide elements still grow
554
+ * geometrically. */
555
+ size_t ncap = (p->attr_dup_mask + 1) * 2;
542
556
  uint32_t* nt = (uint32_t*)leptris_pool_alloc(
543
557
  p->pool, ncap * sizeof(uint32_t));
544
558
  if (!nt) return 0;
@@ -689,10 +703,33 @@ static inline int dp_add_attr_inline(DParser* p, LeptrisElement elem,
689
703
  * only runs on genuine candidates. First definition wins
690
704
  * (libxml2 recover semantics, and the digest's first-wins
691
705
  * becomes official); the duplicate never enters the chain, it
692
- * costs its already-carved slot. */
706
+ * costs its already-carved slot.
707
+ *
708
+ * #1842 cut: the steady-state probe is INLINED here — the
709
+ * out-of-line call per attribute cost ~4-6 cycles of
710
+ * call/prologue on the attrparse row (dp_dup_seen_or_add was
711
+ * 10% of the no-inline profile). The table-miss fast path is
712
+ * five loads/stores; alloc/grow falls back to the function. */
693
713
  if (!(p->skip_flags & LEPTRIS_PARSE_SKIP_DUP_DETECTION)) {
694
714
  int dup = 0;
695
- if (dp_dup_seen_or_add(p, name_hash) &&
715
+ int seen = 0;
716
+ if (DP_LIKELY(p->attr_dup_slots) &&
717
+ DP_LIKELY((p->attr_dup_used + 1) * 8 <
718
+ (p->attr_dup_mask + 1) * 7)) {
719
+ uint32_t dh = name_hash ? name_hash : 1;
720
+ size_t i = dh & p->attr_dup_mask;
721
+ while (p->attr_dup_slots[i]) {
722
+ if (p->attr_dup_slots[i] == dh) { seen = 1; break; }
723
+ i = (i + 1) & p->attr_dup_mask;
724
+ }
725
+ if (!seen) {
726
+ p->attr_dup_slots[i] = dh;
727
+ p->attr_dup_used++;
728
+ }
729
+ } else {
730
+ seen = dp_dup_seen_or_add(p, name_hash);
731
+ }
732
+ if (seen &&
696
733
  elem->first_attribute_off != 0) {
697
734
  /* hash hit: confirm against the real chain (collision
698
735
  * or genuine duplicate) */
@@ -1097,27 +1134,33 @@ static int dp_parse_attrs(DParser* p, LeptrisElement elem) {
1097
1134
  const char* attr_colon =
1098
1135
  (name_start[0] == ':') ? name_start : NULL;
1099
1136
  p->pos++;
1137
+ /* Class of the byte that ended the name — captured from the
1138
+ * scan's own table loads (single-pass scan: the byte after
1139
+ * the name IS the delimiter, whitespace or '='). */
1140
+ unsigned delim;
1100
1141
  {
1101
1142
  char* s = p->pos;
1143
+ unsigned k = leptris_chartype_table[(unsigned char)s[0]];
1102
1144
  for (;;) {
1103
- char c0 = s[0];
1104
- if (DP_UNLIKELY(!IS_NAME_CHAR(c0))) break;
1105
- if (need_dup_hash) { dh ^= (unsigned char)c0; dh *= 16777619u; }
1106
- if (c0 == ':') attr_colon = s;
1107
- char c1 = s[1];
1108
- if (DP_UNLIKELY(!IS_NAME_CHAR(c1))) { s += 1; break; }
1109
- if (need_dup_hash) { dh ^= (unsigned char)c1; dh *= 16777619u; }
1110
- if (c1 == ':') attr_colon = s + 1;
1111
- char c2 = s[2];
1112
- if (DP_UNLIKELY(!IS_NAME_CHAR(c2))) { s += 2; break; }
1113
- if (need_dup_hash) { dh ^= (unsigned char)c2; dh *= 16777619u; }
1114
- if (c2 == ':') attr_colon = s + 2;
1115
- char c3 = s[3];
1116
- if (DP_UNLIKELY(!IS_NAME_CHAR(c3))) { s += 3; break; }
1117
- if (need_dup_hash) { dh ^= (unsigned char)c3; dh *= 16777619u; }
1118
- if (c3 == ':') attr_colon = s + 3;
1145
+ if (DP_UNLIKELY(!(k & DP_CT_NAME_CHAR))) break;
1146
+ if (need_dup_hash) { dh ^= (unsigned char)s[0]; dh *= 16777619u; }
1147
+ if (s[0] == ':') attr_colon = s;
1148
+ unsigned k1 = leptris_chartype_table[(unsigned char)s[1]];
1149
+ if (DP_UNLIKELY(!(k1 & DP_CT_NAME_CHAR))) { s += 1; k = k1; break; }
1150
+ if (need_dup_hash) { dh ^= (unsigned char)s[1]; dh *= 16777619u; }
1151
+ if (s[1] == ':') attr_colon = s + 1;
1152
+ unsigned k2 = leptris_chartype_table[(unsigned char)s[2]];
1153
+ if (DP_UNLIKELY(!(k2 & DP_CT_NAME_CHAR))) { s += 2; k = k2; break; }
1154
+ if (need_dup_hash) { dh ^= (unsigned char)s[2]; dh *= 16777619u; }
1155
+ if (s[2] == ':') attr_colon = s + 2;
1156
+ unsigned k3 = leptris_chartype_table[(unsigned char)s[3]];
1157
+ if (DP_UNLIKELY(!(k3 & DP_CT_NAME_CHAR))) { s += 3; k = k3; break; }
1158
+ if (need_dup_hash) { dh ^= (unsigned char)s[3]; dh *= 16777619u; }
1159
+ if (s[3] == ':') attr_colon = s + 3;
1119
1160
  s += 4;
1161
+ k = leptris_chartype_table[(unsigned char)s[0]];
1120
1162
  }
1163
+ delim = k;
1121
1164
  p->pos = s;
1122
1165
  }
1123
1166
  char* name_end = p->pos;
@@ -1126,10 +1169,19 @@ static int dp_parse_attrs(DParser* p, LeptrisElement elem) {
1126
1169
  /* Defer NUL-termination until after '=' is consumed — the
1127
1170
  * delimiter byte (whitespace or '=') is needed for the scan. */
1128
1171
 
1129
- /* Skip = and whitespace — the fused class test again: the
1130
- * stop byte after the name's trailing ws must be '='. NUL
1131
- * sentinel fails CT_ATTR_EQ. */
1132
- if (!(dp_class_after_ws(p) & CT_ATTR_EQ)) return -1;
1172
+ /* '=' must follow (possibly after whitespace). The stop byte's
1173
+ * class came out of the name scan — whitespace continues the
1174
+ * skip inline, '=' terminates the dispatch here; the former
1175
+ * dp_class_after_ws call re-loaded and re-tested the same byte
1176
+ * every attribute. NUL sentinel fails CT_ATTR_EQ exactly as
1177
+ * before. */
1178
+ if (delim & CT_WS) {
1179
+ p->pos = name_end + 1;
1180
+ while (leptris_chartype_table[(unsigned char)*p->pos] & CT_WS)
1181
+ p->pos++;
1182
+ delim = leptris_chartype_table[(unsigned char)*p->pos];
1183
+ }
1184
+ if (!(delim & CT_ATTR_EQ)) return -1;
1133
1185
  p->pos++;
1134
1186
  /* '=' consumed — the delimiter byte at name_end is no longer
1135
1187
  * needed. Safe to NUL-terminate the name in-place now. */
@@ -6,6 +6,7 @@
6
6
  #include "leptris/error.h"
7
7
 
8
8
  #include <cstring>
9
+ #include <cstdio>
9
10
  #include <cstdlib>
10
11
  #include <string>
11
12
 
@@ -441,6 +442,63 @@ TEST(AttributeNormalization, CleanValuesStayZeroCopy) {
441
442
  leptris_document_free(doc);
442
443
  }
443
444
 
445
+ /* The attr-value scan runs 16-byte SIMD chunks over the probe window
446
+ * (2016-11-11 #1842 cut): the opposite quote character is ORDINARY
447
+ * value data, and terminator positions must classify identically at
448
+ * every offset across the chunk boundary (bytes 15/16 straddle the
449
+ * SIMD→scalar-tail seam). Pins: opposite quote, boundary terminators,
450
+ * flag bytes adjacent to the terminator, >48-byte memchr tail. */
451
+ namespace {
452
+ void expect_attr(const char* xml, const char* name, const char* want) {
453
+ LeptrisStatus st = LEPTRIS_OK;
454
+ LeptrisDocument doc = leptris_parse_string(xml, std::strlen(xml), &st);
455
+ ASSERT_NE(doc, nullptr) << xml;
456
+ LeptrisElement root = leptris_document_root(doc);
457
+ const char* v = leptris_element_attribute(root, name);
458
+ ASSERT_NE(v, nullptr) << xml;
459
+ EXPECT_STREQ(v, want) << xml;
460
+ leptris_document_free(doc);
461
+ }
462
+ } // namespace
463
+
464
+ TEST(AttributeValueScan, OppositeQuoteIsData) {
465
+ expect_attr("<r a='it\"s ok'/>", "a", "it\"s ok");
466
+ expect_attr("<r a=\"it's ok\"/>", "a", "it's ok");
467
+ /* opposite quote inside the SIMD chunk AND at chunk edges */
468
+ expect_attr("<r a='x\"xxxxxxxxxxxxxxxxxxx\"y'/>", "a",
469
+ "x\"xxxxxxxxxxxxxxxxxxx\"y");
470
+ expect_attr("<r a=\"xxxxxxxxxxxxxxxxxxx'y\"/>", "a",
471
+ "xxxxxxxxxxxxxxxxxxx'y");
472
+ }
473
+
474
+ TEST(AttributeValueScan, TerminatorAtChunkBoundary) {
475
+ /* 11 filler bytes put the terminator at value offset 11..17 —
476
+ * spanning the 16-byte SIMD chunk end and the scalar tail. */
477
+ for (int n = 8; n <= 18; n++) {
478
+ char xml[128];
479
+ std::snprintf(xml, sizeof(xml), "<r a='%0*d'/>", n, 0);
480
+ char want[32];
481
+ std::snprintf(want, sizeof(want), "%0*d", n, 0);
482
+ expect_attr(xml, "a", want);
483
+ }
484
+ }
485
+
486
+ TEST(AttributeValueScan, FlagByteJustBeforeTerminator) {
487
+ expect_attr("<r a='abc&'/>", "a", "abc&");
488
+ expect_attr("<r a='ab\tc'/>", "a", "ab c");
489
+ expect_attr("<r a='ab&\tc'/>", "a", "ab& c");
490
+ expect_attr("<r a='&amp;tail'/>", "a", "&tail");
491
+ }
492
+
493
+ TEST(AttributeValueScan, LongValueMemchrTail) {
494
+ char xml[512];
495
+ std::snprintf(xml, sizeof(xml),
496
+ "<r a='%0200d&amp;end'/>", 0);
497
+ char want[256];
498
+ std::snprintf(want, sizeof(want), "%0200d&end", 0);
499
+ expect_attr(xml, "a", want);
500
+ }
501
+
444
502
  /* Issue #577: a PI in the epilog (after the document element) is
445
503
  * valid XML 1.0 — prolog and epilog both allow PIs. A dataless PI
446
504
  * additionally exposed a scan bug: the byte after the target name
@@ -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.414",
4
+ "version": "1.9.416",
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.414.0
4
+ version: 1.9.416.0
5
5
  platform: arm-linux
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-11-08 00:00:00.000000000 Z
11
+ date: 2026-11-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi