> 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 = [];
    },

    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.

-- T.J. :-)

On Aug 22, 3:37 pm, kangax <[EMAIL PROTECTED]> wrote:
> On Aug 22, 9:09 am, "T.J. Crowder" <[EMAIL PROTECTED]> wrote:
>
> > > > NodeLists are live, though, aren't 
> > > > they?http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.html#ID-......
>
> > > Of course, but our selector implementation turns them into an array.
>
> > Ah, okay, sorry about that.  I was thinking live.  I've 
> > readhttp://github.com/kangax/prototype/tree/master/src/element.js
> > now and see where you're coming from.  Should have done that earlier.
>
> > So if I'm using Prototype without enabling automatic extension, I can
> > use $$() to get an array of unextended elements and do whatever I want
> > (e.g., I know it's going to be a big list and don't want them extended
> > until/unless I actually use them).  If I use $$W(), I'll get the new
> > Prototype.NodeList with all of the elements pre-wrapped.  Is that the
> > idea going forward?
>
> Well, for now I want to keep $W and $$W as a separate addition. It's
> very unlikely that wrappers are to replace element extension anytime
> before ver. 2.0. Having a working implementation now will help us test
> it thoroughly (before moving it into the core).
> 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.
>
> --
> 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
-~----------~----~----~----~------~----~------~--~---

Reply via email to