This is one of our more common argument unions. Usage is just
prototyped in a few places, certainly not a full conversion.
I'm removing the str_replace.phpt test, because aparently it was
split up into smaller tests at some point, but the original has
not been removed.
Closes GH-4970.
When normalizing tags to check whether they are contained in the set
of allowable tags, we must not strip slashes, unless they come
immediately after the opening `<`, or immediately before the closing
`>`.
Previously:
* If only ["" => "x"] was present, the original string was returned
without warning.
* If both ["" => "x"] and at least one more element was present,
false was returned without warning.
New behavior:
* Ignore "" keys in the replacement array (and perform any remaining
replacement).
* Throw a warning indicating that an empty string replacement has
been ignored.
Closes GH-4792.
If a null $length is passed to any of these functions, behave as if no
parameter was passed:
- substr()
- substr_count()
- substr_compare()
- iconv_substr()
This falls out naturally from the following condition, because
either the needle length will be zero as well, or the needle
will be longer than the (empty) haystack.
The +1 on the string length is unnecessary, as we need the string
length without trailing NUL byte here.
The +1 on the chunks is only necessary if there is a rest. If the
string devides into chunks exactly, we don't need an extra chunk.
This makes the allocations exactly as large as it needs to be.
When the strip tags state machine has been flattened, an if statement
has mistakenly been treated as else if. We fix this, and also simplify
a bit right away.
On this benchmark:
function simple_string_escape() {
$a = "test'asd'asd'' asd\'\"asdfasdf";
for($i=0; $i<512; $i++) {
$a .= chr($i%256);
}
for ($i = 0; $i < 100000; $i++) {
if ($a === stripslashes(addslashes($a)))
$a .= chr($i%256);
else {
echo "error at i=".$i."\n";
return;
}
}
}
the execution time goes from 21.619s to 8.139s (165% speedup) on an A1 Graviton instance.
When removing the characters that need escaping, i.e., this benchmark:
function simple_string() {
$a = "testasdasd asdasdfasdf";
for ($i = 0; $i < 10000; $i++) {
if ($a === stripslashes(addslashes($a)))
$a .= "test dedeasdf";
else {
echo "error at i=".$i."\n";
return;
}
}
}
the execution time goes from 2.932s down to 0.516s (468% speedup) on an A1 Graviton instance.