resourceloader: Move add() outside loop to optimise sortDependencies()
authorTimo Tijhof <krinklemail@gmail.com>
Thu, 9 Aug 2018 01:27:08 +0000 (02:27 +0100)
committerKrinkle <krinklemail@gmail.com>
Thu, 9 Aug 2018 01:38:28 +0000 (01:38 +0000)
commitd60d5d7a4728e984a4f82773977c4e9df9f7fc74
tree51a17e69e0f197087f09f3aba546bde7b200dd8e
parent97c35356592bd6dc1ee7fade4131d5e8a4524e2a
resourceloader: Move add() outside loop to optimise sortDependencies()

Follows-up CR of dec800968.

As being a set, repeatedly calling unresolved.add() with the same
module name is not useful. This removes that needless overhead
by moving the statement from inside the loop to before it.

This does mean it is now before the first call to has(), but this
change does not affect its behaviour. Tests confirm that.

Aside from optimising the loop, this also ends up reducing the level
of recursion required to detect self-dependencies (eg. A > A).

At first I thought that self-dependencies were not detectable
right now, but the recursion made this work previously as well.
I've added a test case to confirm this going forward, and updated
the existing test cases to consistently use ABC in examples.

Change-Id: I9f4d0a18750f8e5778e0bf3c693b1d83a4ec4312
resources/src/startup/mediawiki.js
tests/qunit/suites/resources/mediawiki/mediawiki.loader.test.js