Hfs: Check duplicates more quickly

When there are a lot of input paths, the double for loop takes a long time. In our case a few thousand paths took over an hour.