chapmanu / fragmentions

A proposal and polyfill to use ## double-hash anchors as links to individual words or phrases in a document.
https://github.com/chapmanu/fragmentions
Other
76 stars 13 forks source link

Use childNodes rather than getElementsByTagName. #1

Closed dracos closed 10 years ago

dracos commented 10 years ago

getElementsByTagName() returns all descendants, which means it iterates over children of things you have already discounted. childNodes returns only the immediate children. I think this should be more efficient (jsperf has a comparison of getElementsByTagName/childNodes where the former is 50% slower, and that's just doing a simple lookup, no iteration).

jonathantneal commented 10 years ago

LGTM! @dracos, would you link to the jsperf so it’s preserved here?

dracos commented 10 years ago

I've now made one specifically for this function at http://jsperf.com/getelementsbytagname-vs-childnodes-loop. Thanks :)

jonathantneal commented 10 years ago

Excellent, and thank you.