Thread overview | |||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
September 27, 2014 [Issue 13544] calls to std.file.FileException are idup-ing their string arguments | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=13544 hsteoh@quickfur.ath.cx changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |hsteoh@quickfur.ath.cx --- Comment #1 from hsteoh@quickfur.ath.cx --- A better solution is to use to!string, which is a no-op if the source and destination types are identical. -- |
September 28, 2014 [Issue 13544] calls to std.file.FileException are idup-ing their string arguments | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=13544 Vladimir Panteleev <thecybershadow@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |thecybershadow@gmail.com --- Comment #2 from Vladimir Panteleev <thecybershadow@gmail.com> --- (In reply to Walter Bright from comment #0) > The signature for functions like std.file.copy() takes "in char[]" so it can > be called with both mutable and immutable strings. If an exception gets > thrown, the conservative assumption is that the source may get changed > so the string is duplicated. > > The problem, again, is bloat. > > The solution is to add two overloads for FileException, one taking string and one taking const(char)[]. Doesn't that mean that we'd also need to add overloads to std.file.copy (and many other std.file functions)? (In reply to hsteoh from comment #1) > A better solution is to use to!string, which is a no-op if the source and destination types are identical. That won't work for "in char[]", will it? It would only work by making the constructor templated. -- |
September 29, 2014 [Issue 13544] calls to std.file.FileException are idup-ing their string arguments | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=13544 Martin Nowak <code@dawg.eu> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |code@dawg.eu --- Comment #3 from Martin Nowak <code@dawg.eu> --- Well is that really a problem for hopefully rare case that an exception is thrown? If you add an overload you duplicate the function and the source code. When you templatize it instead you'll add template code bloat to every user of that function. -- |
September 29, 2014 [Issue 13544] calls to std.file.FileException are idup-ing their string arguments | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=13544 --- Comment #4 from Walter Bright <bugzilla@digitalmars.com> --- (In reply to hsteoh from comment #1) > A better solution is to use to!string, which is a no-op if the source and destination types are identical. It has the same problem - the copying is done at the call site, when it should be done by the callee (in order to reduce code bloat). -- |
September 29, 2014 [Issue 13544] calls to std.file.FileException are idup-ing their string arguments | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=13544 --- Comment #5 from Walter Bright <bugzilla@digitalmars.com> --- (In reply to Vladimir Panteleev from comment #2) > Doesn't that mean that we'd also need to add overloads to std.file.copy (and many other std.file functions)? No, the idea is to get the copy operation into the callee, not the caller. -- |
September 29, 2014 [Issue 13544] calls to std.file.FileException are idup-ing their string arguments | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=13544 --- Comment #6 from Vladimir Panteleev <thecybershadow@gmail.com> --- (In reply to Walter Bright from comment #5) > (In reply to Vladimir Panteleev from comment #2) > > Doesn't that mean that we'd also need to add overloads to std.file.copy (and many other std.file functions)? > > No, the idea is to get the copy operation into the callee, not the caller. So I understand that you want to force all callees to pass in an immutable string, even though an immutable string is needed only for the rare case of when an exception occurs. I don't see how that would be an improvement. -- |
October 04, 2014 [Issue 13544] calls to std.file.FileException are idup-ing their string arguments | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=13544 --- Comment #7 from Walter Bright <bugzilla@digitalmars.com> --- (In reply to Vladimir Panteleev from comment #6) > (In reply to Walter Bright from comment #5) > > (In reply to Vladimir Panteleev from comment #2) > > > Doesn't that mean that we'd also need to add overloads to std.file.copy (and many other std.file functions)? > > > > No, the idea is to get the copy operation into the callee, not the caller. > > So I understand that you want to force all callees to pass in an immutable string, even though an immutable string is needed only for the rare case of when an exception occurs. I don't see how that would be an improvement. No, I suggested adding two overloads for FileException, one taking string and one taking const(char)[]. Only the latter would ever call .idup, and the .idup would only happen when an exception was thrown, and would only have code generated once for it in the entire code base. -- |
October 04, 2014 [Issue 13544] calls to std.file.FileException are idup-ing their string arguments | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=13544 --- Comment #8 from Vladimir Panteleev <thecybershadow@gmail.com> --- Oh, sorry, I finally get it now. For some reason I kept thinking you were trying to get rid of the .idup when the user passes a string to copy. Thanks for elaborating. -- |
October 05, 2014 [Issue 13544] calls to std.file.FileException are idup-ing their string arguments | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=13544 --- Comment #9 from Vladimir Panteleev <thecybershadow@gmail.com> --- BTW, std.file.copy is not a very good example, because really it should be fixed as to what exception message it's using. Right now it's doing: if (!result) throw new FileException(to.idup); However, if the source file or path does not exist, this generates an entirely misleading message. The exception message should contain both the "from" and "to" parameters, because we can't know which path the problem occurred with. Yes, in this case, this means more bloat. But it needs to be fixed. -- |
January 05, 2020 [Issue 13544] calls to std.file.FileException are idup-ing their string arguments | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=13544 berni44 <bugzilla@d-ecke.de> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |bugzilla@d-ecke.de Hardware|x86_64 |All OS|Windows |All -- |
Copyright © 1999-2021 by the D Language Foundation