leptris 1.9.458.0-arm-linux → 1.9.460.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 +4 -4
- data/CHANGELOG.md +22 -0
- data/CONTEXT.md +9 -3
- data/README.adoc +28 -17
- data/Rakefile +1 -1
- data/lib/leptris/version.rb +1 -1
- data/lib/leptris/xml/document.rb +75 -48
- data/lib/leptris/xml/ffi.rb +8 -0
- data/lib/libleptris.so +0 -0
- data/vendor-src/README.md +1 -1
- data/vendor-src/libleptris/CHANGELOG.md +42 -0
- data/vendor-src/libleptris/CMakeLists.txt +1 -1
- data/vendor-src/libleptris/README.adoc +19 -0
- data/vendor-src/libleptris/benchmarks/CMakeLists.txt +23 -2
- data/vendor-src/libleptris/benchmarks/README.adoc +15 -0
- data/vendor-src/libleptris/benchmarks/README.md +17 -4
- data/vendor-src/libleptris/benchmarks/comprehensive/benchmark_decomp.cpp +2 -1
- data/vendor-src/libleptris/benchmarks/comprehensive/benchmark_first_access.cpp +2 -1
- data/vendor-src/libleptris/benchmarks/comprehensive/benchmark_many_attrs.cpp +2 -1
- data/vendor-src/libleptris/benchmarks/comprehensive/benchmark_memory.cpp +2 -1
- data/vendor-src/libleptris/benchmarks/comprehensive/benchmark_parse.cpp +2 -2
- data/vendor-src/libleptris/benchmarks/comprehensive/benchmark_parse_ops.cpp +8 -4
- data/vendor-src/libleptris/benchmarks/comprehensive/benchmark_write.cpp +4 -2
- data/vendor-src/libleptris/benchmarks/dom/dom_benchmark_v2.cpp +8 -4
- data/vendor-src/libleptris/benchmarks/fixtures/serialbench_users_medium.xml +13004 -0
- data/vendor-src/libleptris/benchmarks/matrix/bench_matrix.cpp +21 -76
- data/vendor-src/libleptris/benchmarks/matrix/bench_matrix_fused.cpp +31 -0
- data/vendor-src/libleptris/benchmarks/matrix/bench_rows.h +94 -0
- data/vendor-src/libleptris/benchmarks/modification/bench_append_attr_pugixml.cpp +2 -1
- data/vendor-src/libleptris/benchmarks/parse/bench_parse_ab.cpp +2 -1
- data/vendor-src/libleptris/benchmarks/twins/generation_users.sh +49 -0
- data/vendor-src/libleptris/benchmarks/twins/generation_users_fixture.h +78 -0
- data/vendor-src/libleptris/benchmarks/twins/generation_users_leptris.c +122 -0
- data/vendor-src/libleptris/benchmarks/twins/generation_users_pugixml.cpp +231 -0
- data/vendor-src/libleptris/benchmarks/twins/parse_pugixml.cpp +1 -1
- data/vendor-src/libleptris/benchmarks/twins/parse_users_ab.cpp +158 -0
- data/vendor-src/libleptris/benchmarks/workflows/bench_pipeline_shapes.cpp +12 -4
- data/vendor-src/libleptris/benchmarks/xpath/bench_pugixml.cpp +2 -1
- data/vendor-src/libleptris/cli/CLI_ARCHITECTURE.md +9 -1
- data/vendor-src/libleptris/cli/commands/diff.c +26 -28
- data/vendor-src/libleptris/cli/commands/format.c +3 -1
- data/vendor-src/libleptris/cli/commands/parse.c +3 -1
- data/vendor-src/libleptris/cli/commands/validate.c +22 -24
- data/vendor-src/libleptris/cli/commands/xpath.c +9 -1
- data/vendor-src/libleptris/cli/commands/xquery.c +12 -3
- data/vendor-src/libleptris/cli/commands/xslt.c +24 -8
- data/vendor-src/libleptris/cli/error.c +91 -0
- data/vendor-src/libleptris/cli/error.h +84 -0
- data/vendor-src/libleptris/cli/man/leptris-parse.1.adoc +21 -10
- data/vendor-src/libleptris/cli/man/leptris.1.adoc +19 -0
- data/vendor-src/libleptris/cli/output.c +18 -9
- data/vendor-src/libleptris/cli/output.h +17 -0
- data/vendor-src/libleptris/src/CMakeLists.txt +3 -0
- data/vendor-src/libleptris/src/include/leptris/types.h +25 -1
- data/vendor-src/libleptris/src/include/leptris/xquery/xquery.h +9 -1
- data/vendor-src/libleptris/src/include/leptris.h +48 -3
- data/vendor-src/libleptris/src/leptris/common/entities.c +2 -2
- data/vendor-src/libleptris/src/leptris/common/entities.h +8 -2
- data/vendor-src/libleptris/src/leptris/common/port.h +62 -0
- data/vendor-src/libleptris/src/leptris/common/uri_base.c +284 -0
- data/vendor-src/libleptris/src/leptris/common/uri_base.h +62 -0
- data/vendor-src/libleptris/src/leptris/core.c +33 -2
- data/vendor-src/libleptris/src/leptris/dom/compact.h +51 -0
- data/vendor-src/libleptris/src/leptris/dom/element.c +18 -0
- data/vendor-src/libleptris/src/leptris/dom/element.h +201 -12
- data/vendor-src/libleptris/src/leptris/dom/element_modify.c +611 -210
- data/vendor-src/libleptris/src/leptris/dom/element_query.c +72 -1
- data/vendor-src/libleptris/src/leptris/dom/name_intern.c +3 -1
- data/vendor-src/libleptris/src/leptris/dtd/model.c +13 -0
- data/vendor-src/libleptris/src/leptris/dtd/model.h +95 -6
- data/vendor-src/libleptris/src/leptris/dtd/resolver.c +302 -215
- data/vendor-src/libleptris/src/leptris/flat/direct_parse.c +801 -294
- data/vendor-src/libleptris/src/leptris/leptris.c +20 -5
- data/vendor-src/libleptris/src/leptris/leptris_internal.h +68 -22
- data/vendor-src/libleptris/src/leptris/serialize/serialize.c +289 -57
- data/vendor-src/libleptris/src/leptris/xinclude/xinclude.c +14 -125
- data/vendor-src/libleptris/src/leptris/xpath/evaluator.c +3 -0
- data/vendor-src/libleptris/src/leptris/xpath/evaluator_path.c +11 -8
- data/vendor-src/libleptris/src/leptris/xpath/functions_ext31.c +188 -24
- data/vendor-src/libleptris/src/leptris/xpath/vm.c +3 -1
- data/vendor-src/libleptris/src/leptris/xquery/xquery.c +5 -0
- data/vendor-src/libleptris/src/leptris/xsd/compile.c +59 -20
- data/vendor-src/libleptris/src/leptris/xsd/validate.c +291 -168
- data/vendor-src/libleptris/test/CMakeLists.txt +28 -0
- data/vendor-src/libleptris/test/abi/test_public_surface.cpp +37 -0
- data/vendor-src/libleptris/test/cli/test_cli.cpp +228 -0
- data/vendor-src/libleptris/test/common/hang_guard.h +179 -0
- data/vendor-src/libleptris/test/dom/test_compact.cpp +46 -0
- data/vendor-src/libleptris/test/dom/test_mut_append_contracts.cpp +173 -0
- data/vendor-src/libleptris/test/dom/test_mut_set_attr_contracts.cpp +771 -7
- data/vendor-src/libleptris/test/fixtures/entity_limits/good.xml +100 -0
- data/vendor-src/libleptris/test/fixtures/entity_limits/good_attr.xml +100 -0
- data/vendor-src/libleptris/test/fixtures/entity_limits/lol_classic.xml +51 -0
- data/vendor-src/libleptris/test/fixtures/entity_limits/lol_ig_attr.xml +23 -0
- data/vendor-src/libleptris/test/fixtures/entity_limits/lol_ig_content.xml +23 -0
- data/vendor-src/libleptris/test/fixtures/entity_limits/lol_long_name.xml +23 -0
- data/vendor-src/libleptris/test/memory/test_oom_injection.cpp +63 -0
- data/vendor-src/libleptris/test/parser/test_entity_limits.cpp +404 -0
- data/vendor-src/libleptris/test/parser/test_parser.cpp +126 -0
- data/vendor-src/libleptris/test/serializer/test_serialize.cpp +491 -0
- data/vendor-src/libleptris/test/xpath/test_base_uri.cpp +368 -0
- data/vendor-src/libleptris/test/xpath/test_xpath.cpp +86 -0
- data/vendor-src/libleptris/test/xsd/test_xsd11_base_uri.cpp +145 -0
- data/vendor-src/libleptris/test/xsd/test_xsd11_conformance.cpp +23 -5
- data/vendor-src/libleptris/test/xsd/test_xsd11_cta_context.cpp +385 -0
- data/vendor-src/libleptris/test/xsd/xsd11-all/all-restrict.xsd +3 -2
- data/vendor-src/libleptris/test/xsd/xsd11-all/all-wildcard.xsd +3 -2
- data/vendor-src/libleptris/test/xsd/xsd11-cases/MANIFEST.tsv +19 -2
- data/vendor-src/libleptris/test/xsd/xsd11-cases/saxonData/CTA/cta0003.n01.xml +5 -0
- data/vendor-src/libleptris/test/xsd/xsd11-cases/saxonData/CTA/cta0003.v01.xml +4 -0
- data/vendor-src/libleptris/test/xsd/xsd11-cases/saxonData/CTA/cta0003.xsd +46 -0
- data/vendor-src/libleptris/test/xsd/xsd11-cases/saxonData/CTA/cta0006.v01.xml +6 -0
- data/vendor-src/libleptris/test/xsd/xsd11-cases/saxonData/CTA/cta0006.xsd +83 -0
- data/vendor-src/libleptris/test/xsd/xsd11-cases/saxonData/CTA/cta0017.v01.xml +3 -0
- data/vendor-src/libleptris/test/xsd/xsd11-cases/saxonData/CTA/cta0017.xsd +36 -0
- data/vendor-src/libleptris/test/xsd/xsd11-cases/saxonData/CTA/cta0021.n01.xml +3 -0
- data/vendor-src/libleptris/test/xsd/xsd11-cases/saxonData/CTA/cta0021.v01.xml +3 -0
- data/vendor-src/libleptris/test/xsd/xsd11-cases/saxonData/CTA/cta0021.xsd +36 -0
- data/vendor-src/libleptris/test/xsd/xsd11-cases/saxonData/CTA/cta0023.v01.xml +3 -0
- data/vendor-src/libleptris/test/xsd/xsd11-cases/saxonData/CTA/cta0024.xsd +40 -0
- data/vendor-src/libleptris/test/xsd/xsd11-dispositions/README.md +67 -0
- data/vendor-src/libleptris/vcpkg.json +1 -1
- metadata +35 -2
|
@@ -34,6 +34,7 @@ typedef struct leptris_xsd_schema* LeptrisXsdSchema;
|
|
|
34
34
|
|
|
35
35
|
#include "node.h"
|
|
36
36
|
#include "../common/string_view.h"
|
|
37
|
+
#include "../common/port.h" /* LEPTRIS_CTZ64 — the S9 word window */
|
|
37
38
|
#include "compact.h" /* Compressed pointer types */
|
|
38
39
|
|
|
39
40
|
/* Forward decl: LeptrisMemoryPool is defined in memory/pool.h. */
|
|
@@ -144,6 +145,106 @@ int32_t ns_cache_off;
|
|
|
144
145
|
#endif
|
|
145
146
|
#define LEPTRIS_ATTR_VALUE_MAX_INLINE 7
|
|
146
147
|
|
|
148
|
+
/* S9 short-string scan (#2274 set-attr). The mutation insert path needs
|
|
149
|
+
* three facts about a caller's short string — its length, whether it
|
|
150
|
+
* carries a ':', and a probe key for the attr index — and paid three
|
|
151
|
+
* byte passes for them (len16's loop, memchr, the FNV loop). One
|
|
152
|
+
* unrolled scan gathers the first 8 bytes into a word when the string
|
|
153
|
+
* ends inside them, and the word answers all three.
|
|
154
|
+
*
|
|
155
|
+
* Soundness for every caller's C string: the scan is byte-wise and
|
|
156
|
+
* STOPS at the terminator — it never reads past the string (the parser
|
|
157
|
+
* can afford slack-backed probe windows because it owns the buffer's
|
|
158
|
+
* slack; the public API cannot assume it, and a literal or a 5-byte
|
|
159
|
+
* heap buffer ends right there — ASAN flags any wider load as an
|
|
160
|
+
* object over-read, which is exactly what the first cut's 8-byte
|
|
161
|
+
* window tripped on "k"). The word arrives zero-padded past the NUL:
|
|
162
|
+
* a key hashes exactly the string, and a copy stores exactly the
|
|
163
|
+
* string, with no bytes of the caller's buffer riding along. */
|
|
164
|
+
static inline int leptris_cstr_word8(const char* s, uint64_t* w) {
|
|
165
|
+
uint64_t acc = 0;
|
|
166
|
+
for (size_t i = 0; i < 8; i++) {
|
|
167
|
+
unsigned char c = (unsigned char)s[i]; /* legal: s[i-1] != 0 */
|
|
168
|
+
if (c == 0) {
|
|
169
|
+
*w = acc; /* bytes [0..i), NUL-padded */
|
|
170
|
+
return 1;
|
|
171
|
+
}
|
|
172
|
+
acc |= (uint64_t)c << (8 * i);
|
|
173
|
+
}
|
|
174
|
+
*w = acc;
|
|
175
|
+
return 0; /* 8+ bytes: scan on */
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/* The word's zero-byte mask: a set bit 7 marks a zero byte (the
|
|
179
|
+
* classic haszero — exact for zero bytes). */
|
|
180
|
+
static inline uint64_t leptris_word8_zero_mask(uint64_t w) {
|
|
181
|
+
return (w - 0x0101010101010101ULL) & ~w & 0x8080808080808080ULL;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/* Length of the scanned string: the NUL's position (the first zero
|
|
185
|
+
* byte of a word leptris_cstr_word8 returned 1 for). */
|
|
186
|
+
static inline size_t leptris_word8_len(uint64_t w) {
|
|
187
|
+
uint64_t m = leptris_word8_zero_mask(w);
|
|
188
|
+
return m ? (size_t)(LEPTRIS_CTZ64(m) >> 3) : (size_t)-1;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/* 1 when byte `c` (ASCII) occurs before the word's NUL. */
|
|
192
|
+
static inline int leptris_word8_has(uint64_t w, uint8_t c) {
|
|
193
|
+
size_t len = leptris_word8_len(w);
|
|
194
|
+
uint64_t live = (len == (size_t)-1)
|
|
195
|
+
? ~(uint64_t)0
|
|
196
|
+
: (((uint64_t)1 << (len * 8)) - 1);
|
|
197
|
+
uint64_t x = w ^ (0x0101010101010101ULL * (uint64_t)c);
|
|
198
|
+
return ((x - 0x0101010101010101ULL) & ~x & 0x8080808080808080ULL &
|
|
199
|
+
live) != 0;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/* The word <-> string boundary (the endian law of this family).
|
|
203
|
+
*
|
|
204
|
+
* The word's layout is LOGICAL: string byte i occupies bits
|
|
205
|
+
* [8i, 8i+8) — the shifts in leptris_cstr_word8 build it that way, and
|
|
206
|
+
* the zero-mask / length / ':' helpers above read it that way on every
|
|
207
|
+
* host. The MEMORY image of that word is the host's own, so a raw
|
|
208
|
+
* memcpy between word and string is string order only on little-endian:
|
|
209
|
+
* on a big-endian host the bytes reverse and the zero padding lands
|
|
210
|
+
* FIRST — an inline value reads back empty and the serializer truncates
|
|
211
|
+
* at the attribute (leptris-ruby#699, the genuinely-emulated s390x leg;
|
|
212
|
+
* parse-built attributes were fine because they never take this path).
|
|
213
|
+
*
|
|
214
|
+
* Every word<->string copy goes through this pair, which converts at
|
|
215
|
+
* the boundary. LEPTRIS_HOST_BIG_ENDIAN is a compile-time 0/1, so on
|
|
216
|
+
* little-endian the swap is not emitted and the store stays a single
|
|
217
|
+
* plain word store — the codegen this family was written for. */
|
|
218
|
+
static inline uint64_t leptris_word8_swap_if(uint64_t w, int big_endian) {
|
|
219
|
+
return big_endian ? LEPTRIS_BSWAP64(w) : w;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/* Store `w`'s bytes in string order. The explicit `big_endian`
|
|
223
|
+
* parameter is the testability seam: the spec drives both dialects on
|
|
224
|
+
* one machine and proves the pair inverts in each (see
|
|
225
|
+
* MutationSetAttrWordWindow.WordStoreLoadAreEndianCorrectBothDialects). */
|
|
226
|
+
static inline void leptris_word8_store_order(char dst[8], uint64_t w,
|
|
227
|
+
int big_endian) {
|
|
228
|
+
uint64_t mem = leptris_word8_swap_if(w, big_endian);
|
|
229
|
+
memcpy(dst, &mem, sizeof(mem));
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/* Load a logical word from bytes in string order — the exact inverse. */
|
|
233
|
+
static inline uint64_t leptris_word8_load_order(const char src[8],
|
|
234
|
+
int big_endian) {
|
|
235
|
+
uint64_t mem;
|
|
236
|
+
memcpy(&mem, src, sizeof(mem));
|
|
237
|
+
return leptris_word8_swap_if(mem, big_endian);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
static inline void leptris_word8_store(char dst[8], uint64_t w) {
|
|
241
|
+
leptris_word8_store_order(dst, w, LEPTRIS_HOST_BIG_ENDIAN);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
static inline uint64_t leptris_word8_load(const char src[8]) {
|
|
245
|
+
return leptris_word8_load_order(src, LEPTRIS_HOST_BIG_ENDIAN);
|
|
246
|
+
}
|
|
247
|
+
|
|
147
248
|
static inline LeptrisStringView leptris_attr_value_sv(
|
|
148
249
|
const struct leptris_attribute* a) {
|
|
149
250
|
if (a->value.heap.length & LEPTRIS_ATTR_VALUE_INLINE_BIT) {
|
|
@@ -169,6 +270,24 @@ static inline void leptris_attr_value_set_inline(
|
|
|
169
270
|
a->value.heap.length = LEPTRIS_ATTR_VALUE_INLINE_BIT | len;
|
|
170
271
|
}
|
|
171
272
|
|
|
273
|
+
/* #2274 set-attr: the scanned-word form (leptris_cstr_word8 above)
|
|
274
|
+
* — the caller already holds the value's bytes, and every inline-able
|
|
275
|
+
* length (LEPTRIS_ATTR_VALUE_MAX_INLINE + 1 == 8) ends inside the
|
|
276
|
+
* scan, so the copy is one store of the zero-padded word and the NUL
|
|
277
|
+
* rides along. `len` must be the word's own NUL position and
|
|
278
|
+
* <= MAX_INLINE; gate on CAN_INLINE like the pointer form (the 8-byte
|
|
279
|
+
* store overlaps the heap view's length word on ILP32).
|
|
280
|
+
*
|
|
281
|
+
* The store goes through leptris_word8_store: the word is LOGICAL, its
|
|
282
|
+
* memory image is the host's, and a raw memcpy reversed the bytes on
|
|
283
|
+
* big-endian (leptris-ruby#699). */
|
|
284
|
+
static inline void leptris_attr_value_set_inline_word(
|
|
285
|
+
struct leptris_attribute* a, uint64_t w, size_t len) {
|
|
286
|
+
leptris_word8_store(a->value.inline_value, w);
|
|
287
|
+
a->value.inline_value[len] = '\0';
|
|
288
|
+
a->value.heap.length = LEPTRIS_ATTR_VALUE_INLINE_BIT | len;
|
|
289
|
+
}
|
|
290
|
+
|
|
172
291
|
static inline int leptris_attr_value_is_inline(
|
|
173
292
|
const struct leptris_attribute* a) {
|
|
174
293
|
return (a->value.heap.length & LEPTRIS_ATTR_VALUE_INLINE_BIT) != 0;
|
|
@@ -202,7 +321,7 @@ static inline const char* attr_cvalue(const struct leptris_attribute* a) {
|
|
|
202
321
|
static inline struct leptris_attribute* leptris_attr_next(
|
|
203
322
|
const struct leptris_attribute* a) {
|
|
204
323
|
return (a)
|
|
205
|
-
? (struct leptris_attribute*)
|
|
324
|
+
? (struct leptris_attribute*)leptris_compact_ptr16_decode_inline(
|
|
206
325
|
(const void*)a, a->next_cp, 3, &a->next_cp)
|
|
207
326
|
: NULL;
|
|
208
327
|
}
|
|
@@ -210,7 +329,7 @@ static inline struct leptris_attribute* leptris_attr_next(
|
|
|
210
329
|
static inline void leptris_attr_set_next(struct leptris_attribute* a,
|
|
211
330
|
struct leptris_attribute* next) {
|
|
212
331
|
if (!a) return;
|
|
213
|
-
a->next_cp =
|
|
332
|
+
a->next_cp = leptris_compact_ptr16_encode_inline(a, next, 3, &a->next_cp);
|
|
214
333
|
}
|
|
215
334
|
|
|
216
335
|
/* 15-bit FNV-1a of a name (round 19). Single source of truth for
|
|
@@ -220,16 +339,23 @@ static inline void leptris_attr_set_next(struct leptris_attribute* a,
|
|
|
220
339
|
* low bits sit under the multiply's carry chain; the upper half
|
|
221
340
|
* mixes better). Returns nonzero: 0 maps to 1 so the "uncomputed"
|
|
222
341
|
* sentinel stays unambiguous. */
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
342
|
+
/* Round-20 finalizer, full width: raw FNV truncation (h>>16) mapped
|
|
343
|
+
* names differing in their last digit to hashes exactly 256
|
|
344
|
+
* apart — arithmetic progressions that collide onto one open-
|
|
345
|
+
* addressing chain at every cap ≤ 256. A murmur-style avalanche
|
|
346
|
+
* step breaks the progression before the cut. Shared by the 15-bit
|
|
347
|
+
* attr field hash below and the mutation index's FNV key for names
|
|
348
|
+
* past the word window (element_modify.c attr_index_key) — one
|
|
349
|
+
* finalizer, so the two hashes can never drift apart. */
|
|
350
|
+
static inline uint32_t attr_hash32_finish(uint32_t h) {
|
|
229
351
|
h ^= h >> 16;
|
|
230
352
|
h *= 0x7FEB352Du;
|
|
231
353
|
h ^= h >> 15;
|
|
232
|
-
|
|
354
|
+
return h;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
static inline uint16_t attr_hash15_finish(uint32_t h) {
|
|
358
|
+
uint16_t h15 = (uint16_t)(attr_hash32_finish(h) & 0x7FFFu);
|
|
233
359
|
return h15 ? h15 : 1;
|
|
234
360
|
}
|
|
235
361
|
|
|
@@ -280,6 +406,9 @@ static inline int leptris_memeq_short(const char* a, const char* b,
|
|
|
280
406
|
return 1;
|
|
281
407
|
}
|
|
282
408
|
|
|
409
|
+
/* The S9 word-window helpers live above the value accessors, which
|
|
410
|
+
* use them (leptris_attr_value_set_inline_word). */
|
|
411
|
+
|
|
283
412
|
/* Internal: hash-prefiltered attribute find with the caller's
|
|
284
413
|
* already-computed name length (element.c). */
|
|
285
414
|
struct leptris_attribute* leptris_dom_attr_find(LeptrisElement elem,
|
|
@@ -502,6 +631,12 @@ int leptris_elem_pos_lookup(const struct leptris_document* doc,
|
|
|
502
631
|
|
|
503
632
|
struct leptris_document* leptris_element_get_document(LeptrisElement elem);
|
|
504
633
|
|
|
634
|
+
/* #2278: the base URI of a node — the document URI resolved through
|
|
635
|
+
* every xml:base on the root-to-node chain (XML Base; element_query.c).
|
|
636
|
+
* A malloc'd string (free()); "" when the document carries no URI and
|
|
637
|
+
* no xml:base applies. */
|
|
638
|
+
char* leptris_node_base_uri(LeptrisNodeRef nd);
|
|
639
|
+
|
|
505
640
|
/* #487: the KIND-SAFE document resolver for non-element nodes
|
|
506
641
|
* (text/cdata/comment/pi) — reads each struct's own owner_doc
|
|
507
642
|
* field instead of element-form views. get_document routes
|
|
@@ -526,6 +661,29 @@ LeptrisMemoryPool* leptris_element_get_pool(LeptrisElement elem);
|
|
|
526
661
|
* tombstones in the index and lookups stay correct. */
|
|
527
662
|
#define LEPTRIS_ATTR_INDEXED_FLAG 0x20u
|
|
528
663
|
|
|
664
|
+
/* #2294: header.flags bit 4 — "namespace explicitly cleared" — set by
|
|
665
|
+
* leptris_element_set_namespace(elem, "") (the #817 detach), cleared
|
|
666
|
+
* whenever the element gains a namespace again. Unlike an explicit
|
|
667
|
+
* xmlns="" DECLARATION (which is dropped at call time when no
|
|
668
|
+
* non-empty default is in scope, #1040), the intent must survive a
|
|
669
|
+
* later attachment: an element explicitly detached from namespaces
|
|
670
|
+
* and then parented under a default-namespaced element would
|
|
671
|
+
* otherwise be silently captured by that default. The serializer
|
|
672
|
+
* emits xmlns="" for a flagged element under a non-empty in-scope
|
|
673
|
+
* default, and leptris_element_get_namespace_uri reports no
|
|
674
|
+
* namespace. Parsed declarations never set it. */
|
|
675
|
+
#define LEPTRIS_NS_CLEARED_FLAG 0x10u
|
|
676
|
+
|
|
677
|
+
static inline int leptris_elem_ns_cleared(const LeptrisElement e) {
|
|
678
|
+
return (e->header.flags & LEPTRIS_NS_CLEARED_FLAG) != 0;
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
static inline void leptris_elem_set_ns_cleared(LeptrisElement e, int on) {
|
|
682
|
+
if (!e) return;
|
|
683
|
+
if (on) e->header.flags |= LEPTRIS_NS_CLEARED_FLAG;
|
|
684
|
+
else e->header.flags &= (uint8_t)(~LEPTRIS_NS_CLEARED_FLAG & 0xFFu);
|
|
685
|
+
}
|
|
686
|
+
|
|
529
687
|
static inline int leptris_elem_has_namebp(const LeptrisElement e) {
|
|
530
688
|
return (e->header.flags & LEPTRIS_NAMEBP_FLAG) != 0;
|
|
531
689
|
}
|
|
@@ -543,13 +701,44 @@ static inline struct leptris_document* leptris_elem_namebp_doc(
|
|
|
543
701
|
|
|
544
702
|
|
|
545
703
|
/* Compute 16-bit FNV-1a hash of an element name string. Used
|
|
546
|
-
* together with
|
|
547
|
-
* axis lookups. TODO 159: fast child-name matching.
|
|
704
|
+
* together with elem_name_hash() for fast pre-filtering in child-
|
|
705
|
+
* axis lookups. TODO 159: fast child-name matching.
|
|
706
|
+
*
|
|
707
|
+
* #2255: the result is never 0 — 0 is the element's lazy-hash
|
|
708
|
+
* sentinel (see elem_name_hash). Every inline copy of this chain
|
|
709
|
+
* (name_intern.c, element_modify.c's set-name scan, the IL lane's
|
|
710
|
+
* dp_split_hash_name) applies the same 0 -> 1 mapping at its store. */
|
|
711
|
+
static inline uint16_t leptris_name_hash_compute(const char* name) {
|
|
548
712
|
uint16_t h = 0x811C;
|
|
549
713
|
for (const char* c = name; *c; c++) {
|
|
550
714
|
h ^= (unsigned char)*c;
|
|
551
715
|
h *= 0x0193;
|
|
552
716
|
}
|
|
717
|
+
return h ? h : 1;
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
/* Lazy element-name hash (#2255, the attributes' round-19 pattern):
|
|
721
|
+
* name_hash == 0 means "not computed yet". The parse lanes no longer
|
|
722
|
+
* fold the FNV chain into every element name scan — the catalog-5000
|
|
723
|
+
* profile put that chain at ~4.7% of the parse (one dependent
|
|
724
|
+
* multiply per name byte on the critical path of every open tag) —
|
|
725
|
+
* and XPath name tests probe a small subset of a tree's elements,
|
|
726
|
+
* so the first probe per element computes and caches instead. Every
|
|
727
|
+
* eager writer stores a nonzero value (leptris_name_hash_compute maps
|
|
728
|
+
* 0 to 1), so a nameless element (name_off == 0) is the only case
|
|
729
|
+
* that leaves the sentinel in place — and no name test can match it.
|
|
730
|
+
*
|
|
731
|
+
* Thread-safety as attr_name_hash: racy writes are idempotent (two
|
|
732
|
+
* threads store the same value); documents are single-threaded by
|
|
733
|
+
* contract. */
|
|
734
|
+
static inline uint16_t elem_name_hash(struct leptris_element* e) {
|
|
735
|
+
uint16_t h = e->name_hash;
|
|
736
|
+
if (h == 0) {
|
|
737
|
+
if (e->name_off == 0) return 0;
|
|
738
|
+
char* n = elem_name(e);
|
|
739
|
+
h = leptris_name_hash_compute(n);
|
|
740
|
+
e->name_hash = h;
|
|
741
|
+
}
|
|
553
742
|
return h;
|
|
554
743
|
}
|
|
555
744
|
|
|
@@ -558,7 +747,7 @@ static inline struct leptris_document* leptris_elem_namebp_doc(
|
|
|
558
747
|
* names in ~1ns vs ~5ns for strcmp on short names. */
|
|
559
748
|
static inline int leptris_elem_name_is(LeptrisElement e, const char* name,
|
|
560
749
|
uint16_t target_hash) {
|
|
561
|
-
if (!e || e
|
|
750
|
+
if (!e || elem_name_hash(e) != target_hash) return 0;
|
|
562
751
|
char* n = elem_name(e);
|
|
563
752
|
if (!n) return 0;
|
|
564
753
|
return strcmp(n, name) == 0;
|