mirror of
https://github.com/php/php-src.git
synced 2024-09-21 18:07:23 +00:00
a6b43086e6
Trimming a potentially over-allocated string appears to be reasonable, so we drop the condition altogether. We also re-allocate twice the size needed in the first place, and not roughly tripple the size. Closes GH-7231.
22 lines
553 B
PHP
22 lines
553 B
PHP
--TEST--
|
|
Bug #81243 (Too much memory is allocated for preg_replace())
|
|
--FILE--
|
|
<?php
|
|
$test_string = str_repeat('Eins zwei drei', 2000);
|
|
|
|
$replaced = preg_replace('/\s/', '-', $test_string);
|
|
$mem0 = memory_get_usage();
|
|
$replaced = str_repeat($replaced, 1);
|
|
$mem1 = memory_get_usage();
|
|
var_dump($mem0 == $mem1);
|
|
|
|
$replaced = preg_replace_callback('/\s/', function ($_) {return '-';}, $test_string);
|
|
$mem0 = memory_get_usage();
|
|
$replaced = str_repeat($replaced, 1);
|
|
$mem1 = memory_get_usage();
|
|
var_dump($mem0 == $mem1);
|
|
?>
|
|
--EXPECT--
|
|
bool(true)
|
|
bool(true)
|