match.py match algorithm efficiency tweak

Since DB is now sorted, the matching algorithm now stop with the first
ancestor match it finds.