At 08:02 AM 8/24/00 -0700, Larry Wall wrote:
>Bart Lateur writes:
>: On Thu, 24 Aug 2000 09:38:28 +0100, Hildo Biersma wrote:
>:
>: >> I expect that we'll get more compile-time benefit from
>: >>
>: >>     my HASH sub foo {
>: >>         ...
>: >>     }
>: >>
>: >>     %bar = foo();
>: >
>: >Ah, the Return Value Optimization so loved in C++...
>: >
>: >For those who haven't seen it before, you can optimize this by passing
>: >in a reference to %bar to foo() and then use that in the function.
>:
>: Just a remark: this is only safe if all other references to the hash
>: returned are abandoned. Otherwise you'd have an alias where you should
>: have gotten a copy.
>
>I wasn't actually considering the RVO optimization--I was only thinking
>about the fact that you can do more type inferencing at compile time
>from the function's signature.

That's OK--I was. :)

>However, you couldn't actually do the aliased return right now if you
>wanted to--at least, not without chicanery.

Chicanery's on the big To Do list. I'm really wanting to defer list 
flattening as long as possible, and skipping it all together.

In this case:

   sub bar {
     my %foo;
     return %foo;
   }

I was planning on pushing the whole %foo structure onto the return stack 
and only flattening it when needed. If bar() was used like so:

   %thing = bar();

then we wouldn't flatten--we'd either copy or alias, depending on how sure 
we were that the hash bar() returned was unreferenced elsewhere.


                                        Dan

--------------------------------------"it's like this"-------------------
Dan Sugalski                          even samurai
[EMAIL PROTECTED]                         have teddy bears and even
                                      teddy bears get drunk

Reply via email to