Opened 7 years ago

Last modified 6 years ago

#11663 assigned Feature Requests

No way to query file extension without allocating memory

Reported by: matthew.chaplain@… Owned by: Beman Dawes
Milestone: To Be Determined Component: filesystem
Version: Boost 1.57.0 Severity: Optimization
Keywords: Cc:

Description

the function .extension() returns an fs::path, containing a fresh string that contains the extension. On certain library implementations that don't implement the SSO -- or, I guess, for files with very long extensions -- there will be a memory allocation each time the function is called.

That means that for solutions implementing search-by-extension such as is written in:

http://stackoverflow.com/questions/11140483/how-to-get-list-of-files-with-a-specific-extension-in-a-given-folder

there could be hundreds of memory allocations for just iterating a directory structure. IMO, there really shouldn't be.

I propose adding the function bool path::has_extension(string const&) which can compare the extension in a memory-friendly way.

Change History (2)

comment:1 by Beman Dawes, 7 years ago

Status: newassigned

The broader problem is that neither Boost.Filesystem nor the C++ Filesystem Library TS supports globbing. See https://en.wikipedia.org/wiki/Glob_%28programming%29

So rather than tackling your suggested change, I'll take a look the more general glob match problem.

Thanks,

--Beman

comment:2 by daniel.kruegler@…, 6 years ago

I have doubts regarding the practical usefulness of that feature (modulo globbing as pointed out by Beman): At least on Windows systems, path names are handled case-insensitive, so if you want to check whether a given path has a .pdf extension, you would need to check against all uppercase and lowercase character combinations of .pdf (.Pdf, .pDf, .pdF, ...). Note that this wouldn't be solved by has_extension() internally because all other existing lexical comparison functions of filesystem do compare *exactly* and for consistency reasons this function would need to do the same.

Note: See TracTickets for help on using tickets.