Clarify pitfalls document.
This commit is contained in:
@@ -4,9 +4,9 @@
|
|||||||
This document discusses difficult traps and pitfalls in PHP, and how to avoid,
|
This document discusses difficult traps and pitfalls in PHP, and how to avoid,
|
||||||
work around, or at least understand them.
|
work around, or at least understand them.
|
||||||
|
|
||||||
= array_merge() in Incredibly Slow =
|
= array_merge() in Incredibly Slow When Merging A List of Arrays =
|
||||||
|
|
||||||
If you merge arrays like this:
|
If you merge a list of arrays like this:
|
||||||
|
|
||||||
COUNTEREXAMPLE
|
COUNTEREXAMPLE
|
||||||
$result = array();
|
$result = array();
|
||||||
@@ -14,9 +14,9 @@ If you merge arrays like this:
|
|||||||
$result = array_merge($result, $one_list);
|
$result = array_merge($result, $one_list);
|
||||||
}
|
}
|
||||||
|
|
||||||
...your program now has a huge runtime runtime because it generates a large
|
...your program now has a huge runtime because it generates a large number of
|
||||||
number of intermediate arrays and copies every element it has previously seen
|
intermediate arrays and copies every element it has previously seen each time
|
||||||
each time you iterate.
|
you iterate.
|
||||||
|
|
||||||
In a libphutil environment, you can use ##array_mergev($list_of_lists)##
|
In a libphutil environment, you can use ##array_mergev($list_of_lists)##
|
||||||
instead.
|
instead.
|
||||||
|
|||||||
Reference in New Issue
Block a user