D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 7120 - Scope Delegates + Delegate Literals
Summary: Scope Delegates + Delegate Literals
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: Other Windows
: P2 normal
Assignee: No Owner
URL:
Keywords: patch, performance
Depends on:
Blocks:
 
Reported: 2011-12-16 11:23 UTC by David Simcha
Modified: 2012-01-06 10:41 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description David Simcha 2011-12-16 11:23:57 UTC
The following code apparently heap-allocates a closure even though doNothing() takes a scope delegate.  This happens when doNothing() is passed a delegate literal.  When it's passed the address of a named inner function, no heap allocation takes place.

import core.memory;

void main() {
    GC.disable();

    foreach(j; 0..1_000_000_000) {
        doIt();
    }
}

void doIt() {
    int i;
    doNothing(() { i++; });
}

void doNothing(scope void delegate() dg) {
    dg();
}