Fix performance issues with end of file pattern