Skip to content

Optimize `getElements` method

Compare
Choose a tag to compare
@lsvx lsvx released this 28 Apr 05:11
· 1 commit to master since this release

This commit optimizes the internal getElements method, which Postpone
uses to locate and register all elements on the page who's resources
should be managed. This code change takes advantage of the fact that if
an element is already being managed by Postpone and the postponed
elements on the page have not changed, then the index of that given
element in the array of postponed elements should already be known. This
allows for the elimination of the Array.prototype.indexOf method,
effectively changing the line of code from O(n) to O(1).