Closed sth closed 10 years ago
Nice! I'll look over this later.
My top concern here is that improvements in -A/-B/-C don't degrade performance elsewhere.
Normal, non-context searches should be basically not affected at all by these changes. Nearly all changes are not in the main code path, but inside if blocks that are only entered when a context search is done (if ($n_before_ctx_lines || $n_after_ctx_lines)
in current ack or if ($is_tracking_context)
with the changes of this PR).
There was one addtional function call per searched file and some unnecessary work that was done when --lines
was specified, but I moved that code also into if ($is_tracking_context)
blocks. Now these cases are also only executed when necessary and should cause basically no overhead otherwise.
For these checks for to work I had to make $is_tracking_context
a global variable. Maybe this could also be done better differently, but I'm not sure how.
@sth I haven't looked much, but I like what I've seen so far. I'm not crazy about the $is_tracking_context
global, but if it's unavoidable, that's how it is. I'll see about merging this in tomorrow.
Everything looks good to me here!
I did some changes to the context handling in ack to speed up searches with
-A
,-B
and-C
(see #487):Additionally I moved most of the context handling logic into a few specialized functions,
setup_line_context()
,setup_line_context_for_file()
andprint_line_if_context()
, making the rest of the code simpler.The diff is larger than I'd like, but the resulting code should be clearer and easier to understand. The tests pass. Speed, while not yet optimal, is significantly improved:
(In this table
2.14
is the current head of thedev
branch)