Commit f33c37a
Refactor XPath evaluation, fix memory leaks, and resolve all clippy warnings
* Fix memory leaks, connection overload, and Rust best practice issues
Memory leak fixes:
- StreamingParser: buffer, events, and complete_elements vecs never
shrank after drain operations, causing unbounded growth in long-lived
parsers. Added shrink_to() calls matching StreamingSaxParser behavior.
- StructuralIndex: shrink_to_fit() existed but was never called after
building. Initial capacity estimates over-allocate by 2-3x; now
reclaimed immediately after build_children_from_parents().
- DocumentAccumulator: reduced default pre-allocation from 64KB to 4KB.
The old 64KB multiplied quickly across concurrent accumulators.
Connection/contention fix:
- XPath cache: replaced deep CompiledExpr cloning with Arc<CompiledExpr>.
Every cache hit previously cloned all Vec<Op>, Strings, and
Box<CompiledExpr> recursively. Now it's a cheap Arc pointer bump.
Correctness + memory fix:
- compare_values in XPath eval: was using format!("{}", node_id) to
compare nodes, which compared raw u32 IDs as strings — both wrong
per XPath 1.0 spec and wasteful (O(n*m) String allocations). Now
uses actual document text content via node_string_value().
- Consolidated duplicated get_node_text_content/collect_text_content
from lib.rs into shared dom::node_string_value().
Safety fix:
- empty_binary: replaced .unwrap() on OwnedBinary::new(0) with match
to avoid potential NIF panic.
Best practices:
- Added #[must_use] to evaluate(), evaluate_from_node(), compile(),
validate_strict(), and XPathValue type.
https://claude.ai/code/session_015igpdCrNYKuoPrHWZ5RXYc
* Fix XPath string-value semantics, optimize NodeSet comparison, resolve all clippy warnings
- Fix XPathValue::to_string_value() to return empty string for NodeSets
instead of misleading format!("[node:{}]", id) — callers with document
access now use dom::node_string_value() per XPath 1.0 spec
- Add resolve_string() helper to XPath functions for proper NodeSet-to-string
conversion; pass document access to all 8 string functions
- Replace duplicated get_string_value/collect_text with dom::node_string_value
- Remove residual get_node_text_content wrapper from NIF layer
- Optimize NodeSet-vs-NodeSet comparison from O(n*m) to O(n+m) by
pre-computing right-side string values
- Fix streaming parser shrink_to() reallocation churn with 4x threshold
- Remove redundant #[must_use] on compile() (Result already has it)
- Remove dead inherent methods on XmlDocument duplicated by DocumentAccess trait
- Remove unused XmlAttribute re-export from dom/mod.rs
- Fix len_zero clippy warnings in unified_scanner tests
- Add #[expect(clippy::ptr_arg)] to intern_cow (needs Cow for zero-copy optimization)
- Add 4 correctness tests for NodeSet equality and string function semantics
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* Eliminate panic risk in NIF paths, fix NodeSet relational comparisons
- Replace expect() in XPath parser peek() with match + defensive Eof
fallback — eliminates BEAM VM crash risk if invariant is violated
- Replace expect() in XPath lexer read_string() with unwrap_or
defensive fallback — same rationale
- Thread document access into compare_numbers() so relational operators
(< <= > >=) properly resolve NodeSet text content before numeric
conversion — fixes silent wrong results for expressions like
/r/price > 10 where <price>42.5</price>
- Add resolve_number() helper mirroring resolve_string() pattern
- Add test for relational operators on NodeSets
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 6eeddf3 commit f33c37a
File tree
13 files changed
+325
-220
lines changed- native/rustyxml/src
- core
- dom
- index
- strategy
- xpath
13 files changed
+325
-220
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
630 | 630 | | |
631 | 631 | | |
632 | 632 | | |
633 | | - | |
| 633 | + | |
634 | 634 | | |
635 | 635 | | |
636 | 636 | | |
| |||
650 | 650 | | |
651 | 651 | | |
652 | 652 | | |
653 | | - | |
| 653 | + | |
654 | 654 | | |
655 | 655 | | |
656 | 656 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | 55 | | |
71 | 56 | | |
72 | 57 | | |
| 58 | + | |
| 59 | + | |
73 | 60 | | |
74 | 61 | | |
75 | 62 | | |
| |||
432 | 419 | | |
433 | 420 | | |
434 | 421 | | |
435 | | - | |
436 | | - | |
437 | | - | |
438 | | - | |
439 | | - | |
440 | | - | |
441 | | - | |
442 | | - | |
443 | | - | |
444 | | - | |
445 | | - | |
446 | | - | |
447 | | - | |
448 | | - | |
449 | | - | |
450 | | - | |
451 | | - | |
452 | | - | |
453 | | - | |
454 | | - | |
455 | 422 | | |
456 | 423 | | |
457 | 424 | | |
| |||
463 | 430 | | |
464 | 431 | | |
465 | 432 | | |
466 | | - | |
467 | | - | |
468 | | - | |
469 | | - | |
470 | | - | |
471 | | - | |
472 | | - | |
473 | | - | |
474 | | - | |
475 | | - | |
476 | | - | |
477 | | - | |
478 | | - | |
479 | | - | |
480 | | - | |
481 | | - | |
482 | | - | |
483 | | - | |
484 | | - | |
485 | | - | |
486 | | - | |
487 | | - | |
488 | 433 | | |
489 | 434 | | |
490 | 435 | | |
| |||
629 | 574 | | |
630 | 575 | | |
631 | 576 | | |
| 577 | + | |
632 | 578 | | |
633 | 579 | | |
634 | 580 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
16 | | - | |
17 | 15 | | |
18 | 16 | | |
19 | 17 | | |
| |||
80 | 78 | | |
81 | 79 | | |
82 | 80 | | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
59 | 64 | | |
60 | 65 | | |
61 | 66 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
234 | 234 | | |
235 | 235 | | |
236 | 236 | | |
237 | | - | |
| 237 | + | |
238 | 238 | | |
239 | 239 | | |
240 | 240 | | |
| |||
276 | 276 | | |
277 | 277 | | |
278 | 278 | | |
279 | | - | |
| 279 | + | |
280 | 280 | | |
281 | 281 | | |
282 | 282 | | |
| |||
365 | 365 | | |
366 | 366 | | |
367 | 367 | | |
368 | | - | |
| 368 | + | |
369 | 369 | | |
370 | 370 | | |
371 | 371 | | |
| |||
394 | 394 | | |
395 | 395 | | |
396 | 396 | | |
397 | | - | |
| 397 | + | |
398 | 398 | | |
399 | 399 | | |
400 | 400 | | |
| |||
407 | 407 | | |
408 | 408 | | |
409 | 409 | | |
410 | | - | |
411 | | - | |
412 | | - | |
413 | | - | |
414 | | - | |
415 | | - | |
416 | | - | |
417 | | - | |
418 | | - | |
419 | | - | |
420 | | - | |
421 | | - | |
422 | | - | |
423 | | - | |
424 | | - | |
425 | | - | |
426 | | - | |
427 | | - | |
428 | | - | |
429 | | - | |
430 | | - | |
431 | | - | |
432 | | - | |
433 | | - | |
434 | | - | |
435 | | - | |
436 | | - | |
437 | | - | |
438 | | - | |
439 | | - | |
440 | | - | |
441 | | - | |
442 | | - | |
443 | | - | |
444 | | - | |
445 | | - | |
446 | | - | |
447 | | - | |
448 | | - | |
449 | | - | |
450 | | - | |
451 | 410 | | |
452 | 411 | | |
453 | 412 | | |
| |||
1352 | 1311 | | |
1353 | 1312 | | |
1354 | 1313 | | |
1355 | | - | |
1356 | | - | |
| 1314 | + | |
| 1315 | + | |
| 1316 | + | |
| 1317 | + | |
| 1318 | + | |
1357 | 1319 | | |
1358 | 1320 | | |
1359 | 1321 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
275 | 275 | | |
276 | 276 | | |
277 | 277 | | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
278 | 281 | | |
279 | | - | |
| 282 | + | |
280 | 283 | | |
281 | 284 | | |
282 | 285 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
173 | 173 | | |
174 | 174 | | |
175 | 175 | | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
176 | 183 | | |
177 | 184 | | |
178 | 185 | | |
| |||
382 | 389 | | |
383 | 390 | | |
384 | 391 | | |
385 | | - | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
386 | 398 | | |
387 | 399 | | |
388 | 400 | | |
| |||
393 | 405 | | |
394 | 406 | | |
395 | 407 | | |
396 | | - | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
397 | 414 | | |
398 | 415 | | |
399 | 416 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
| 9 | + | |
10 | 10 | | |
11 | | - | |
12 | | - | |
13 | | - | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
14 | 16 | | |
15 | 17 | | |
16 | 18 | | |
| |||
217 | 219 | | |
218 | 220 | | |
219 | 221 | | |
220 | | - | |
221 | | - | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
222 | 227 | | |
223 | 228 | | |
224 | 229 | | |
225 | 230 | | |
226 | 231 | | |
227 | | - | |
| 232 | + | |
228 | 233 | | |
229 | 234 | | |
230 | 235 | | |
231 | 236 | | |
232 | 237 | | |
233 | 238 | | |
234 | | - | |
| 239 | + | |
235 | 240 | | |
236 | 241 | | |
237 | 242 | | |
238 | 243 | | |
239 | | - | |
| 244 | + | |
240 | 245 | | |
241 | 246 | | |
242 | 247 | | |
| |||
0 commit comments