MCPcopy Create free account
hub / github.com/ScriptedAlchemy/tracedecay / push_children

Function push_children

src/extraction/complexity.rs:177–191  ·  view source on GitHub ↗

Pushes the direct children of `parent` onto `stack` in reverse order, so a LIFO pop reproduces left-to-right traversal. Iterates via a `TreeCursor` — sibling walks are O(1) each, vs. O(i) for `parent.child(i)`. Skipping this matters: high-fanout nodes (1 K+ children, common in switch-heavy C files like `kernel/bpf/verifier.c`) turn `for i in 0..N { child(i) }` into an O(N²) trap that dominated ind

(stack: &mut Vec<(TsNode<'a>, u32)>, parent: TsNode<'a>, depth: u32)

Source from the content-addressed store, hash-verified

175/// C files like `kernel/bpf/verifier.c`) turn `for i in 0..N { child(i) }`
176/// into an O(N²) trap that dominated indexing time before this helper.
177fn push_children<'a>(stack: &mut Vec<(TsNode<'a>, u32)>, parent: TsNode<'a>, depth: u32) {
178 let start = stack.len();
179 let mut cursor = parent.walk();
180 if cursor.goto_first_child() {
181 loop {
182 stack.push((cursor.node(), depth));
183 if !cursor.goto_next_sibling() {
184 break;
185 }
186 }
187 }
188 // Reverse the slice we just appended so the next `pop()` sees the
189 // first child first.
190 stack[start..].reverse();
191}
192
193/// Extracts the method/function name from a call expression node.
194///

Callers 1

count_complexityFunction · 0.85

Calls 1

pushMethod · 0.80

Tested by

no test coverage detected