revset: improve head revset performance

Previously the head() revset would iterate over every item in the subset and
check if it was a head.  Since the subset is often the entire repo, this was
slow on large repos. Now we iterate over each item in the head list and check if
it's in the subset, which results in much less work.

hg log -r 'head()' on a large repo:
Before: 0.95s
After: 0.28s
revset: optimized sort method in lazyset class

We are taking advantage of the smartset classes sort method when it exists and
converting the set to a baseset otherwise.

--HG--
extra : rebase_source : 5078674ffb5ccdf45ba4ac6b3bff7451dc619833