User tests: Successful: Unsuccessful:
As above
Status | New | ⇒ | Pending |
Category | ⇒ | Front End Plugins |
Labels |
Added:
?
|
I have tested this item
foreach works with a copy of the array so it takes more memory and IIRC for is faster, so the only argument for using foreach is readability of code. I don't think that this is needed here.
Status | Pending | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2016-10-04 07:00:40 |
Closed_By | ⇒ | rdeutz |
Sorry but I don't understand that. The bit more memory used, is released as soon as the function returns. So this is not a reason to close all those PR's.
The pro's are both speed and readability. Readability alone would be a huge factor to weigh in.
So why exactly are all those PR's closed with only a comment from one person only?
Also, I 'd like to point out that the memory footprint for the looped array in most, if not all, cases is negligible. So I really see no reason, that those PR's are shutdown this way.
Your "bit more" depends on the number of elements that array in question have, so the "bit more" can be "huge more". That foreach is faster than for is not 100% clear and the checks I have found giving different results. So I have closed this:
Personal note for you @frankmayer
I told you already on the other refactor PR's that I see better places to work on. You are putting a lot of work into "cosmetic" changes, usually these PR are large and hard to test. So there is the danger that these will stay a long time not ready to merge and then you've the solve all the merge conflicts. Not fun.
I would really like to see you working on some bugs, I think it is better to fix one bug rather then optimize 30 "for" usages. Form all what I have seen you can code PHP and your time can be better spend.
@rdeutz I agree on the "bit more". If there is somewhere a situation that could "hit us", then this thing could be discussed and dealt with.
As for the other points:
besides the foreach changes, that's i actually agree with, this particular PR actually goes more ahead and reduces two for cycles in to just one. Clearly an improvement IMHO.
@frankmayer maybe this would be even more efficient
// Code removed for brevity
try
{
$rows = (array) $db->loadObjectList();
}
catch (RuntimeException $e)
{
JFactory::getApplication()->enqueueMessage(JText::_('JERROR_AN_ERROR_HAS_OCCURRED'), 'error');
return array();
}
foreach ($rows as $i => &$row)
{
if (!SearchHelper::checkNoHtml($row, $searchText, array('name', 'title', 'text')))
{
unset($rows[$i]);
continue;
}
$row->href = ContentHelperRoute::getCategoryRoute($row->slug);
$row->section = JText::_('JCATEGORY');
}
return $rows;
@andrepereiradasilva On a quick view your proposal seems ok and would be even more efficient. Though right now I am not investing more time into a closed PR. If by any chance it would be reopened, I will happily continue working on it. Sorry...
@andrepereiradasilva I have opened a new PR for this one with a further optimization. I didn't implement your solution above, as it might produce a problem later on. Let me explain.
When you have an array with keys 1,2,3,4,5 and you do unset on 2 and 4 for example, the resulting array will keys 1,3,5, which will most probably lead to problems(Undefined offset) specifically on for
loops that will handle this result.
Thanks for your thoughts, though. It was in a good direction. ;)
I have tested this item✅ successfully on 2a59282
on code review
This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/12299.