Hi there,
What is wrong with the removeElementClass as it is now?
I defined your function as removeElementClass2 and ran some quick
tests in firebug. The test looks like this
function test(initialclass, toremove, n) {
var start, t1, t2;
start = new Date().getTime()
for (var i = 0; i < n; i++) {
removeElementClass(SPAN({'class': initialclass}, null), toremove);
}
t1 = new Date().getTime() - start;
start = new Date().getTime();
for (var i = 0; i < n; i++) {
removeElementClass2(SPAN({'class': initialclass}, null), toremove);
}
t2 = new Date().getTime() - start;
return new Array(initialclass, toremove, t1, t2, 100*(t1-t2)/t1);
}
Notice the array it returns, the t1 is the time in msec of original
removeElement, t2 is yours. The last item is the speed up in
percentage of the original one.
Here are some results:
>>> test('', 'removeme', 1000);
["", "removeme", 797, 1171, -46.92597239648683]
>>> test('removeme', 'removeme', 1000);
["removeme", "removeme", 813, 1156, -42.189421894218945]
>>> test('more stuff here removeme', 'removeme', 1000);
["more stuff here removeme", "removeme", 922, 1141, -23.752711496746205]
>>> test('removeme some here too', 'removeme', 1000);
["removeme some here too", "removeme", 953, 1079, -13.221406086044071]
>>> test('other stuff', 'removeme', 1000);
["other stuff", "removeme", 891, 1094, -22.783389450056116]
>>> test('alot other stuff that doesnt include the one', 'removeme', 1000);
["alot other stuff that doesnt include the one", "removeme", 859,
1141, -32.82887077997672]
Your version was up to 46% slower than the current MochiKit version.
In the interest of science I also tested the following:
removeElementClass3 = function (element, className) {
element = MochiKit.DOM.getElement(element);
var oldClass = element.className;
var newClass = filter(partial(operator.ne, className),
oldClass.split(" ")).join(" ");
element.className = newClass;
return oldClass != newClass;
}
.. it was up to 3x slower than the original one. :o)
If you still do want to submit patches I suggest you submit them in
Trac and just a short note on the mailing list and if you want it to
be applied you should provide a good reason to do so.
Arnar
On 2/18/07, Aaron Faanes <[EMAIL PROTECTED]> wrote:
>
> (Sorry for the endless spam of fixes to this. :( )
>
> --- element.className = cls.replace(className, "");
> +++ element.className = cls.replace(className, " ");
>
> - Aaron
>
> On Feb 18, 6:57 am, "Aaron Faanes" <[EMAIL PROTECTED]> wrote:
> > or, rather, for (removing foo in an element with "foo foobar")
> >
> > /** @id MochiKit.DOM.removeElementClass */
> > removeElementClass: function (element, className) {
> > element = MochiKit.DOM.getElement(element);
> > className = " " + className + " ";
> > var cls = " " + element.className + " " || "";
> > element.className = cls.replace(className, "");
> > // Returns true if a change was made, false otherwise.
> > return cls.length > 0 && cls !== element.className;
> > },
> >
> > On Feb 18, 3:57 am, "Aaron Faanes" <[EMAIL PROTECTED]> wrote:
> >
> > > A much cleaner removeElementClass?
> >
> > > /** @id MochiKit.DOM.removeElementClass */
> > > removeElementClass: function (element, className) {
> > > element = MochiKit.DOM.getElement(element);
> > > var cls = element.className || "";
> > > element.className = cls.replace(className, "");
> > > // Returns true if a change was made, false otherwise.
> > > return cls.length > 0 && cls !== element.className;
> > > },
> >
> > > - Aaron
>
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"MochiKit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/mochikit?hl=en
-~----------~----~----~----~------~----~------~--~---