Re: What's behind ${collection?size} ?
Daniel Dekany <[email protected]>
| Newsgroups | gmane.comp.web.freemarker.user |
|---|---|
| Message-ID | <[email protected]> |
Sounds like something silly is going on inside the object wrapper,
because the ?size operation itself queries the size only once for
sure. What is the exact Java class of the collection, and which
ObjectWrapper are you using (the DefaultWrapper?)?
Monday, May 17, 2010, 10:39:31 AM, Kjeld wrote:
> Hi,
>
> In my template there is an instruction like: ${collection?size}
>
> I noticed that when processing this instruction, Freemarker does a 'strange'
> procedure to achieve the collection size. Instead of calling
> collection.size() once, it repeats a call to the following instructions, for
> every element in the collection:
>
> collection.size()
> collection.size()
> collection.size()
> collection.get(elementIndex)
> collection.size()
> collection.size()
> collection.size()
>
> My collection contains 100.000 elements, so the code here above is repeated
> 100.000 times, that is 700.000 instruction calls to get the collection
> size... :S
>
> I can easily bypass this by providing the template processor with the
> explicit collection size, but I am very curious why Freemarker doesn't just
> call collection.size() once.
>
> Cheers,
> Kjeld
>
>
--
Best regards,
Daniel Dekany
------------------------------------------------------------------------------