|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
antickon Smarty n00b
Joined: 22 Feb 2011 Posts: 3
|
Posted: Mon Sep 12, 2011 11:07 pm Post subject: foreach and Iterator |
|
|
Smarty's foreach uses ->rewind() and then iterator_count (via the internal method _count) to decide between the foreach or foreachelse clauses when confronted with an Iterator. I don't believe it is necessary to use iterator_count, just checking ->valid() after rewinding should be enough in this case. Actually I'm not sure why this case-by-case check is being done at all. The same behavior could be achieved for all cases by setting a flag inside the loop.
In any case the current behavior is not wrong per se, but it is causing minor performance issues for my app where Iterators are used heavily to instantiate objects for each row in a resource. |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Thu Sep 15, 2011 3:02 pm Post subject: |
|
|
The {foreach} compiler was optimized not to call _count() unless the number of elements is needed for the {foreach} "total" or "last" properties.
The update is now the the SVN Smarty_3_1_DEV branch. |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|