Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

foreach and Iterator

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Feature Requests
View previous topic :: View next topic  
Author Message
antickon
Smarty n00b


Joined: 22 Feb 2011
Posts: 3

PostPosted: Mon Sep 12, 2011 11:07 pm    Post subject: foreach and Iterator Reply with quote

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
View user's profile Send private message Send e-mail
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Thu Sep 15, 2011 3:02 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Feature Requests All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP