-
Notifications
You must be signed in to change notification settings - Fork 641
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SWEEP: Add string overloads to eliminate unnecessary allocations of FileInfo and DirectoryInfo objects #832
Comments
@NightOwl888, what do you think creating a new struct type (named 'FilePath') which is implicitly convertible from FileInfo and String, but only implicitly convertible to String? That's a strategy I've used in the past to simplify API migrations like this. It does have the downside of not being runtime compatible, so any consumers of the updated API will need to recompile. |
We have considered that approach for char sequences. In Java, However, being that we are only passing in That being said, |
In Java it is common to use the
File
orPath
object as a parameter to methods, as they are accepted as parameters of stream constructors and many other places.However, in .NET, the corresponding objects (
TextWriter
,Stream
,StreamWriter
, etc) don't accept aFileInfo
as a parameter, they accept strings. As such, we are commonly newing up theseFileInfo
objects, passing them through our API and reading the original string back asFileInfo.FullName
. TheFileInfo
object is not even used in many cases.To keep the API the same as Lucene, we should keep the overloads that accept
FileInfo
, but add overloads that are identical in every way except that they accept astring
for a file name instead of aFileInfo
. TheFileInfo
overloads can then just passFileInfo.FullName
to the string overloads.For example, we currently have
And we should change it to
There are several places throughout the project where we are instantiating and then discarding
FileInfo
objects without even making use of their functionality (example). Some could instead use static methods (i.e.File.Exists
). In some other cases, theseFileInfo
andDirectoryInfo
instances are appropriate.The text was updated successfully, but these errors were encountered: