#803 enhancement
Thomas Pulickal

A slight improvement on findFirstElement

Reported by Thomas Pulickal | September 16th, 2009 @ 11:34 PM

findFirstElement was using 2-3 iterations. I tried to remake it using one.

Comments and changes to this ticket

  • Juriy Zaytsev

    Juriy Zaytsev September 26th, 2009 @ 07:54 PM

    Do you have any performance comparison tests for this?

  • Thomas Pulickal

    Thomas Pulickal September 29th, 2009 @ 09:24 PM

    Yeah... on second thought, it's a terribly small difference for a method that's not used too many times in a page anyway. But either way, I posted some comparison test results at the end of this post.

    But more importantly and on a slightly different note, I noticed something else in the process. I think the original method might be working slightly incorrectly. It is returning the element with a tabIndex of 0, whereas a tabIndex of 1 is what properly signifies the first tab-able element.

    (http://www.w3.org/TR/html401/interact/forms.html#adef-tabindex)

    Those elements that support the tabindex attribute and assign a positive value to it are navigated first....

    Those elements that do not support the tabindex attribute or support it and assign it a value of "0" are navigated next. These elements are navigated in the order they appear in the character stream.

    So I'm attaching two patches here: a patch to fix the tabIndex 0 problem in the original code and the corrected version of the previous patch . Note: both patches are independent patches (independent of each other and of the previous patch).

    Thanks,
    Thomas

    Test results:

    With TabIndex of 1,2,3...:

    version: original
    numElements: 1000, numIterations: 100
    duration: 6885, time per call: 68.85

    version: new
    numElements: 1000, numIterations: 100
    duration: 2134, time per call: 21.34

    _With TabIndex of 2,3,4...:_

    version: original
    numElements: 1000, numIterations: 100
    duration: 7273, time per call: 72.73

    version: new
    numElements: 1000, numIterations: 100
    duration: 5214, time per call: 52.14

    _With no tabIndex:_

    version: original
    numElements: 1000, numIterations: 100
    duration: 4676, time per call: 46.76

    version: new
    numElements: 1000, numIterations: 100
    duration: 3983, time per call: 39.83

  • T.J. Crowder

    T.J. Crowder November 16th, 2009 @ 04:50 PM

    [responsible:none bulk edit command]

  • Tobie Langel
  • Radoslav Stankov

    Radoslav Stankov March 1st, 2010 @ 03:19 PM

    • Tag set to section:dom
    • State changed from “new” to “enhancement”
  • Radoslav Stankov

    Radoslav Stankov March 1st, 2010 @ 03:59 PM

    • Tag changed from section:dom to needs:review, patched, section:dom

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

The Prototype JavaScript library.

Shared Ticket Bins

Pages