On Aug 22, 11:30 am, "T.J. Crowder" <[EMAIL PROTECTED]> wrote: > > I'm not sure if we should "pre-wrap" elements or do the "lazy init". > > First approach "hits" the memory consumption, while second - run-time > > performance. We'll need benchmarks for this. > > Yeah. I know you were initially thinking pre-wrap, and my first > instinct was lazy-init (of course!), which was part of the point of my > question. If I have $$() for my lazy-init needs, I'm less likely to > weigh in and say $$W() should be lazy-init as well. > > That said, lazy-init seems pretty cheap; essentially an extra > comparison on each item() call. Thinking out loud: > > initialize: function(source) { > this.source = source; > this.wrappers = [];
Not sure if having two arrays in each `NodeList` compensates for the load-time save : ) Definitely an interesting idea, though. I'll think about it. > }, > > size: function() { > return this.source.length; > }, > > item: function(index) { > return this.wrappers[index] || (this.wrappers[index] = > $W(this.source[index])); > }, > > _each: function(iterator) { > var w, s, index, length, value; > w = this.wrappers; > s = this.source; > index = 0; > length = s.length; > while (index < length) { > value = w[index] || (w[index] = $W(s[index])); > iterator(value, index++); > } > } > > I repeated the item() logic within _each() because it's such a common > op it seems worth avoiding the extra function call, but anyone who > wants to accuse me of premature optimization at the cost of > maintainability might be on reasonably solid ground. ;-) > > But I agree with you: We need benchmarks. -- kangax --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Prototype: Core" group. To post to this group, send email to prototype-core@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/prototype-core?hl=en -~----------~----~----~----~------~----~------~--~---