filestats() changed to return a smart pointer.
The return value from filestats() will be cached on first access if the file is opened read only. The function takes O(n) time relative to the file size, but is fast enough that performance will only be noticeable on really huge files, Also, the open itself has a similar scan of all indices. So calling filestats() will always take significantly less time than the open.
If you worry about taking a performance hit the first time the information is actually used then just do a dummy call to filestats() in the same function that opens the file.