phalcon/cphalcon — pull request #1075 by sjinks (2013-08-13 02:58:30+00:00)
Title: Return Value Optimization

Added initial support for return_value_ptr to fcall.c and alternative/fcall.c

This will allow us to avoid copy constructors in many cases.

For example, in this case:

```php
$frontCache = new Phalcon\Cache\Frontend\None(array('lifetime' => 10));
$cache = new Phalcon\Cache\Backend\Memory($frontCache);
```

currently only

```php
$string = str_repeat('a', 5000000);
$cache->save('test-data', $string);
$s1 = $frontCache->afterRetrieve($string);
$s2 = $frontCache->afterRetrieve($string);
$s3 = $frontCache->afterRetrieve($string);
```

will not waste additional RAM (due to `phalcon_execute_internal` trick) but this will:

```php
$string = str_repeat('a', 5000000);
$cache->save('test-data', $string);
$s1 = $cache->get('test-data');
$s2 = $cache->get('test-data');
$s3 = $cache->get('test-data');
```

$s1, $s2, $s3 will use ~5MB each.

The patch adds support for retval_ptr_ptr to fcall.c (the code has to be rewritten to take advantage of retval_ptr_ptr — this optimization cannot be applied transparently without breaking things).