Skip to main content

Bug Tracker

Side navigation

#10463 closed enhancement (patchwelcome)

Opened October 10, 2011 02:52AM UTC

Closed June 26, 2012 01:43PM UTC

RemoveAttr should check if attribute exist (when it's possible) before remove it

Reported by: markel Owned by: markel
Priority: low Milestone: None
Component: attributes Version: 1.7b1
Keywords: Cc:
Blocked by: Blocking:
Description

You already have similar behavior in removeClass method, without it you would got something like this --

http://jsperf.com/removeclass-without-check-for-classname-attr

Of course in removeClass that check needed for other reasons too,

but in some cases it will improve performance for removeAttr.

Fast -- http://jsperf.com/removeattr-with-check-for-attr

Less faster -- http://jsperf.com/removeattr-with-check-for-attr-2

Equally fast or little bit slower -- http://jsperf.com/removeattr-with-check-for-attr-3

Pull request -- https://github.com/jquery/jquery/pull/538

Attachments (0)
Change History (6)

Changed October 10, 2011 03:48AM UTC by rwaldron comment:1

_comment0: Those perfs are bogus because the attribute doesn't exist after the first removal.1318218596500154
component: unfiledattributes
owner: → markel
priority: undecidedlow
status: newpending

Strike that, I misread the test

Changed October 10, 2011 03:56AM UTC by markel comment:2

status: pendingnew

First show how speed will improve without attributes, is no need for attribute to exist -- its hole point

Second shows if one attribute exist and another is not, its add only one attribute every time

Third remove and immediately add the same attribute, so every time its will remove attribute

Please look more closely, they not bogus.

Changed October 10, 2011 04:01AM UTC by rwaldron comment:3

I think you missed my edit...

Replying to [comment:2 markel]:

First show how speed will improve without attributes, is no need for attribute to exist -- its hole point Second shows if one attribute exist and another is not, its add only one attribute every time Third remove and immediately add the same attribute, so every time its will remove attribute Please look more closely, they not bogus.

Changed October 10, 2011 04:03AM UTC by markel comment:4

yeah, i see now

Changed October 19, 2011 06:18PM UTC by timmywil comment:5

status: newopen

Changed June 26, 2012 01:43PM UTC by dmethvin comment:6

resolution: → patchwelcome
status: openclosed

They both seem fast enough, but if you want to resurrect this submit let us know and we can discuss for 1.9.