[jquery-dev] Re: jQuery's Data functions

2008-11-04 Thread ricardobeat
Those bracket and dots selectors are very confusing, why not something simple like $('div:data(foo)') and $('div:data(foo!=dido)') ? Meanwhile, you can use a simple plugin (WTFPL licensed): $.fn.hasData = function(){ var a = arguments; return this.filter( (a[1]) ? function(){ ret

[jquery-dev] Re: Fast trim implementation

2008-11-04 Thread Andrea Giammarchi
Cheers :-) On Tue, Nov 4, 2008 at 10:11 PM, Ariel Flesler <[EMAIL PROTECTED]> wrote: > > Will benchmark all this. > > On Tue, Nov 4, 2008 at 7:10 PM, Andrea Giammarchi > <[EMAIL PROTECTED]> wrote: > > But in this case you are checking twice for each character, start less > than > > end plus the o

[jquery-dev] Re: Fast trim implementation

2008-11-04 Thread Andrea Giammarchi
something like ... function myBestTrim( str ){ var start = -1, end = str.length; if(end < 1000) return str.replace(/^\s+|\s+$/g, ""); while(str.charCodeAt( --end ) < 33); while(str.charCodeAt( ++start ) < 33); return str.slice( start, end + 1 ); }; On Tue, Nov 4, 2008

[jquery-dev] Re: Fast trim implementation

2008-11-04 Thread Ariel Flesler
Will benchmark all this. On Tue, Nov 4, 2008 at 7:10 PM, Andrea Giammarchi <[EMAIL PROTECTED]> wrote: > But in this case you are checking twice for each character, start less than > end plus the other check. > For small strings the best option culd be return the regexp version > /^\s+|\s+$/g whil

[jquery-dev] Re: Fast trim implementation

2008-11-04 Thread Andrea Giammarchi
But in this case you are checking twice for each character, start less than end plus the other check. For small strings the best option culd be return the regexp version /^\s+|\s+$/g while for strings with length more than N (dunno which length is big enough) we can use my last proposal without pro

[jquery-dev] Re: Fast trim implementation

2008-11-04 Thread Andrea Giammarchi
to save more space, compact version entirely based on NaN trick: function myBestTrim( str ){ var start = -1, end = str.length; while(str.charCodeAt( --end ) < 33); while(str.charCodeAt( ++start ) < 33); return str.slice( start, end + 1 ); }; Thoughts? On Tue, Nov 4, 2008 at 10:00

[jquery-dev] Re: Fast trim implementation

2008-11-04 Thread Ariel Flesler
That does, but will iterate doubly for strings made of spaces. That's why I added the check. But yeah, could do. I'll benchmark the different options asap (not today). On Tue, Nov 4, 2008 at 7:00 PM, Andrea Giammarchi <[EMAIL PROTECTED]> wrote: > Last suggestion. > > The charCodeAt(--end) return

[jquery-dev] Re: Fast trim implementation

2008-11-04 Thread Andrea Giammarchi
Last suggestion. The charCodeAt(--end) returns NaN when end is negative, and NaN < 33 is false. We can use this trick on start variable as well, removing one check for each character. As summary, I wonder which performances could have this version: function myBestTrim( str ){ var start = -1,

[jquery-dev] Re: Fast trim implementation

2008-11-04 Thread Ariel Flesler
Yeah, ++foo should be faster++ though the results were exactly the same when I tested for like 2K iterations. Still, can be changed. It remain from the former version, where start++ !== end was used ( !== instead of < ). It was then safe to use that operator only with the pluses on right. !== sho

[jquery-dev] Re: Fast trim implementation

2008-11-04 Thread Ariel Flesler
On Tue, Nov 4, 2008 at 6:34 PM, Andrea Giammarchi <[EMAIL PROTECTED]> wrote: > Ariel, > I read now the myBestTrim function. > > You check charCodeAt less than 33, but in the precedent version you used > these chars: > chars = ' > \n\r\t\v\f\u00a0\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u20

[jquery-dev] Re: Fast trim implementation

2008-11-04 Thread Andrea Giammarchi
P.S.2 ... in php for example ++$var is a bit faster than $var++ , dunno in JS which one performs better, that was the other improvement that is true in my old laptop On Tue, Nov 4, 2008 at 9:42 PM, Andrea Giammarchi < [EMAIL PROTECTED]> wrote: > P.S. there is a logic problem, and probably a perfo

[jquery-dev] Re: Fast trim implementation

2008-11-04 Thread Andrea Giammarchi
P.S. there is a logic problem, and probably a performances improvement using ++start instead of start++ function myBestTrim( str ){ var start = -1, end = str.length; while(str.charCodeAt(--end) < 33); while(*++start* < end && str.charCodeAt(start) < 33); return str.slice( start, end + 1 ); }

[jquery-dev] Re: Fast trim implementation

2008-11-04 Thread Andrea Giammarchi
Ariel, I read now the myBestTrim function. You check charCodeAt less than 33, but in the precedent version you used these chars: chars = ' \n\r\t\v\f\u00a0\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u200b\u2028\u2029\u3000'; I wonder which side effect could we have ignoring

[jquery-dev] Re: Fast trim implementation

2008-11-04 Thread Andrea Giammarchi
On Tue, Nov 4, 2008 at 5:58 PM, Ariel Flesler <[EMAIL PROTECTED]> wrote: > > P.S: I knew you'd be throwin' in your super revolutionary version of > it.. so predictable :-P :D mine was just a suggestion. Clever or recent browsers cast as constant the regexp, but to be sure it happens everywhere,

[jquery-dev] Re: Fast trim implementation

2008-11-04 Thread Ariel Flesler
There're 2 suites, one with a large string (10K chars) and one with a small(30 chars) strings. Both seem to yield positive results for my last function. I think it gets better as the length increases, but still outperforms on small ones. On Tue, Nov 4, 2008 at 2:00 PM, chris thatcher <[EMAIL PROT

[jquery-dev] Re: Fast trim implementation

2008-11-04 Thread Ariel Flesler
2 things: - Use the one called myBestTrim... that one, as the name indicates, is the best version. - A regex-based trim can do well for small strings (even more for empty ones), but scales horribly. They actually scale so badly that I had to remove the test called 'jQueryTrim' from the "large st

[jquery-dev] Re: Fast trim implementation

2008-11-04 Thread Andrea Giammarchi
jQuery core ready implementation: trim: function( re ){ return function( text ){ return ( text || "" ).replace( re, "" ) } }( /^\s+|\s+$/g ), :-) On Tue, Nov 4, 2008 at 5:35 PM, Andrea Giammarchi < [EMAIL PROTECTED]> wrote: > It's really weird that a manual imple

[jquery-dev] Re: Fast trim implementation

2008-11-04 Thread Andrea Giammarchi
It's really weird that a manual implementation of a regexp, that should be executed in core and should basically perform a really similar task you are performing manually, is faster ... I wonder if we really need an "error prone" code instead of something like this: $.trim = function(RegExp){

[jquery-dev] Re: Gradientz

2008-11-04 Thread weepy
It's quite odd - I found that using .html() would throw an exception ( it think because it's VML ) > register your plugin with LiveQuery will do On 4 Nov, 16:58, "Brandon Aaron" <[EMAIL PROTECTED]> wrote: > Nice work! I've been meaning to investigate doing this for my gradient > plugin for so

[jquery-dev] Re: Object tag problem -- when is it going to be fixed?

2008-11-04 Thread Valentin
This is clear: it doesn't work (as the devs have said above it's because of the weird behavior of the object tag in different browsers) -- but then again this is why we have JQuery to make it work somehow in the background :D On Nov 3, 12:29 pm, Andrea Ercolino <[EMAIL PROTECTED]> wrote: > using

[jquery-dev] Re: Fast trim implementation

2008-11-04 Thread chris thatcher
Nice, I've been using Steves trim12 for awhile, I guess I hadn't seen your earlier blog. Is there are significant difference in the time for trimming a large number of small strings versus a single large string? Just curious, but good work. +1 Thatcher On Tue, Nov 4, 2008 at 11:44 AM, Ariel Fl

[jquery-dev] Re: Gradientz

2008-11-04 Thread Brandon Aaron
Nice work! I've been meaning to investigate doing this for my gradient plugin for so long. Just in case ... feel free to call it gradient() and my gradient plugin can just die off. :) Also ... since you manually use innerHTML for MSIE, you should register your plugin with LiveQuery so that it can p

[jquery-dev] Fast trim implementation

2008-11-04 Thread Ariel Flesler
http://groups.google.com/group/jquery-en/browse_thread/thread/09abbc3bc6e14cdd Thoughts on this ? can you find any flaw ? Should it get to the core ? -- Ariel Flesler http://flesler.blogspot.com --~--~-~--~~~---~--~~ You received this message because you are subsc

[jquery-dev] Gradientz

2008-11-04 Thread weepy
I know this group isn't really for jQuery plugins, but I thought you guys might appreciate this : http://www.parkerfox.co.uk/labs/gradientz/ It renders gradient backgrounds using VML/Canvas without excanvas. Jonah --~--~-~--~~~---~--~~ You received this message b