Commit b5706aa
Add child_count getter to CSSNode for efficient child counting (#197)
## Summary
Added a new `child_count` getter to the `CSSNode` class that efficiently
counts children without allocating an intermediate array, along with
comprehensive test coverage.
## Key Changes
- **New `child_count` getter**: Implements an efficient child counting
mechanism by iterating through siblings using the arena's internal
methods rather than materializing the full children array
- **Test coverage**: Added three test cases covering:
- Counting children in a block declaration (3 properties)
- Returning 0 for nodes with no children
- Verifying consistency with the existing `children.length` property
## Implementation Details
The `child_count` getter uses a simple loop that traverses the sibling
chain starting from the first child, incrementing a counter until
reaching the end (index 0). This approach avoids the memory overhead of
creating an intermediate array when only the count is needed, making it
more efficient for performance-sensitive code paths.
https://claude.ai/code/session_01JZ7KyHoubj42U8DN2GRv7n
Co-authored-by: Claude <noreply@anthropic.com>1 parent f01c6fa commit b5706aa
2 files changed
+31
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
74 | 74 | | |
75 | 75 | | |
76 | 76 | | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
77 | 97 | | |
78 | 98 | | |
79 | 99 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
584 | 584 | | |
585 | 585 | | |
586 | 586 | | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
587 | 598 | | |
588 | 599 | | |
589 | 600 | | |
| |||
0 commit comments