Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 1e96d0a

Browse files
IgorMinarmhevery
authored andcommitted
fix(injector): small perf improvement & code cleanup
1 parent 97dae0d commit 1e96d0a

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

src/Injector.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -384,25 +384,29 @@ function createInjector(modulesToLoad) {
384384

385385
function invoke(fn, self, locals){
386386
var args = [],
387-
$injectAnnotation,
388-
$injectAnnotationIndex,
387+
$inject,
388+
length,
389389
key;
390390

391391
if (typeof fn == 'function') {
392-
$injectAnnotation = inferInjectionArgs(fn);
393-
$injectAnnotationIndex = $injectAnnotation.length;
392+
$inject = inferInjectionArgs(fn);
393+
length = $inject.length;
394394
} else {
395395
if (isArray(fn)) {
396-
$injectAnnotation = fn;
397-
$injectAnnotationIndex = $injectAnnotation.length;
398-
fn = $injectAnnotation[--$injectAnnotationIndex];
396+
$inject = fn;
397+
length = $inject.length - 1;
398+
fn = $inject[length];
399399
}
400400
assertArgFn(fn, 'fn');
401401
}
402402

403-
while($injectAnnotationIndex--) {
404-
key = $injectAnnotation[$injectAnnotationIndex];
405-
args.unshift(locals && locals.hasOwnProperty(key) ? locals[key] : getService(key));
403+
for(var i = 0; i < length; i++) {
404+
key = $inject[i];
405+
args.push(
406+
locals && locals.hasOwnProperty(key)
407+
? locals[key]
408+
: getService(key, path)
409+
);
406410
}
407411

408412
// Performance optimization: http://jsperf.com/apply-vs-call-vs-invoke

test/InjectorSpec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ describe('injector', function() {
5252

5353
injector.get('s1');
5454

55-
expect(log).toEqual(['s6', 's5', 's3', 's4', 's2', 's1']);
55+
expect(log).toEqual(['s6', 's3', 's5', 's4', 's2', 's1']);
5656
});
5757

5858

0 commit comments

Comments
 (0)