# implode() speedup in PHP4

- Thread: https://externals.io/message/15489
- Original archive: https://news-web.php.net/php.internals/15489
- Started by Alexander Valyalkin on 2005-03-18T18:41:38+00:00
- Messages: 7
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #15489 — Alexander Valyalkin — 2005-03-18T18:41:38+00:00

URL: https://externals.io/message/15489#15489

I've posted patch last summer http://www.zend.com/zend/week/pat/pat5.txt
which imporves performance of `implode()` function in PHP4, but nobody  
doesn't
commit it yet. Can anybody explain the reason?

-- 
Using Opera's revolutionary e-mail client: http://www.opera.com/m2/

---

## #15491 — Christian Stadler — 2005-03-18T21:08:56+00:00

URL: https://externals.io/message/15489#15491 · In reply to: #15489

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Alexander Valyalkin schrieb:
> I've posted patch last summer http://www.zend.com/zend/week/pat/pat5.txt
> which imporves performance of `implode()` function in PHP4, but nobody 
> doesn't
> commit it yet. Can anybody explain the reason?

After applying the change to ext/standard/string.c in PHP4 the following
Test failed:
Bug #22224 (implode changes object references in array)
[ext/standard/tests/strings/bug22224.phpt]

Regards,
  Christian Stadler
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (MingW32)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFCO0No9250Hcbf/3IRAndDAJ9H9iNnfa1CXegMHWgmyfR0S2QLhwCfSv3F
7pYwoZ8Y9NeFpzrMeuHxue8=
=GtGF
-----END PGP SIGNATURE

---

## #15492 — Moriyoshi Koizumi — 2005-03-18T21:12:16+00:00

URL: https://externals.io/message/15489#15492 · In reply to: #15489

>
> I've posted patch last summer 
> http://www.zend.com/zend/week/pat/pat5.txt
> which imporves performance of `implode()` function in PHP4, but nobody 
> doesn't
> commit it yet. Can anybody explain the reason?

Because convert_to_string_ex() modifies the content of every element
that is not of string type.

<?php
$arrays = array(array(), array(), array());
var_dump(implode('', $arrays));
var_dump($arrays);
?>

We already have an optimisation in the 5.x branches.
I think it is appliable to the 4.3 branch.

Moriyoshi

---

## #15493 — Derick Rethans — 2005-03-18T21:14:31+00:00

URL: https://externals.io/message/15489#15493 · In reply to: #15492

> <?php
> $arrays = array(array(), array(), array());
> var_dump(implode('', $arrays));
> var_dump($arrays);
> ?>
> 
> We already have an optimisation in the 5.x branches.
> I think it is appliable to the 4.3 branch.

4.3 is only for bugfixes!

Derick

-- 
Derick Rethans
http://derickrethans.nl | http://ez.no | http://xdebug.org

---

## #15494 — Moriyoshi Koizumi — 2005-03-18T21:18:50+00:00

URL: https://externals.io/message/15489#15494 · In reply to: #15493

> 
>
> > […]
>
> 4.3 is only for bugfixes!

It didn't mean that the fix should be in the 4.3. What was it
that excited you so much? :)

Moriyoshi

---

## #15496 — Andi Gutmans — 2005-03-18T21:58:09+00:00

URL: https://externals.io/message/15489#15496 · In reply to: #15489

Just make sure that zval's which are isolated with convert_to_string_ex() 
are only used as read-only.

At 09:41 PM 3/18/2005 +0300, Alexander Valyalkin wrote:

>I've posted patch last summer http://www.zend.com/zend/week/pat/pat5.txt
>which imporves performance of `implode()` function in PHP4, but nobody
>doesn't
>commit it yet. Can anybody explain the reason?
>
>--
>Using Opera's revolutionary e-mail client: http://www.opera.com/m2/

---

## #15526 — Alexander Valyalkin — 2005-03-21T19:50:58+00:00

URL: https://externals.io/message/15489#15526 · In reply to: #15491

> After applying the change to ext/standard/string.c in PHP4 the following
> Test failed:
> Bug #22224 (implode changes object references in array)
> [ext/standard/tests/strings/bug22224.phpt]
>
> Regards,
>   Christian Stadler

I understood my fault. I didn't notice condition
if (!(*ppzv)->is_ref) { }
in convert_to_ex_master() macro.

But compare execution time of the following test on PHP4 & PHP5:
<?
function getmicrotime()
{
    list($usec, $sec) = explode(" ", `microtime()`);
    return ((float)$usec + (float)$sec);
}
$t = getmicrotime();
$s = str_repeat('a', 1 << 24);
$a = implode(",", array($s, $s));
echo getmicrotime() - $t;
?>

I think, it will be good idea to fix such time wasting in PHP4.
