[Issue 12384] New: Improve optimization of nothrow code
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sun Mar 16 16:48:58 PDT 2014
https://d.puremagic.com/issues/show_bug.cgi?id=12384
Summary: Improve optimization of nothrow code
Product: D
Version: D2
Platform: All
OS/Version: All
Status: NEW
Severity: enhancement
Priority: P2
Component: DMD
AssignedTo: nobody at puremagic.com
ReportedBy: bugzilla at digitalmars.com
--- Comment #0 from Walter Bright <bugzilla at digitalmars.com> 2014-03-16 16:48:55 PDT ---
Consider:
----------------------------
import core.stdc.stdlib;
void fun() nothrow;
struct B {
int* p;
size_t x;
}
size_t fun4(ref B a) {
B b;
scope (exit) free(b.p);
fun();
return b.x + a.x;
}
----------------------------
This current sets up an exception handler to call free(b.p), even though no
exceptions can be thrown. Instead, the code rewrite should be:
---------------------
size_t fun4(ref B a) {
B b;
fun();
auto tmp = b.x + a.x;
free(b.p);
return tmp;
}
-----------------------
This will result in significant performance improvements. Currently, only one
such rewrite case is handled in TryFinallyStatement::semantic(). There's more
low hanging fruit, such as the return statement case above, that should be
handled there.
(scope-statements are rewritten as try-finally-statements.)
--
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list