Compare nodes in on_path instead of indexes.

This saves some code and effectively does the same thing.
Fail early when processing (test) nodes.

If a certain segment yields no nodes the on_path() method should not process any
following segments.