Speed up hashTree function

It is still several times slower than native, but on my system does tens
of stats plus a few readdirs in a millisecond. I think this is acceptable
for now.