[cfe-dev] blocks and lambdas
John McCall
rjmccall at apple.com
Wed Feb 9 10:08:22 PST 2011
On Feb 9, 2011, at 1:55 AM, David Chisnall wrote:
> On 9 Feb 2011, at 00:29, John McCall wrote:
>
>> On Feb 8, 2011, at 3:56 PM, David Chisnall wrote:
>>> Blocks are a cross-platform solution, they're just not well supported by other compilers yet[1], but they're quite useable on a variety of platforms.
>>>
>>> [1] Actually, they're not well supported by clang yet either - we allocate too many structures for __block variables.
>>
>> Can you clarify what you mean here? I'm not sure how to allocate fewer structures for __block variables, given how a single variable can be shared between multiple block objects.
>
> A __block variable can be shared between multiple blocks, but it often isn't. We really only need to allocate one block byref structure for each set of variable / block pairs, i.e. if two variables are only referenced by the same (set of) block(s) and no others, then they can be combined. There is a note in the spec to this effect. I looked at implementing it a while ago, but the effort-reward ratio was too high unless I actually find some code where the byref allocation time is a bottleneck. The simplest (and most common) case, where a group of __block variables is only referenced by a single block would be quite easy to improve though.
Ah yes, that's a good point. It would also be good to demote __block variables that aren't actually captured. Both of these would be easier if the variables listed the blocks that capture them.
John.
More information about the cfe-dev
mailing list