mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-19 08:00:23 +00:00
fix(injector): small perf improvement & code cleanup
This commit is contained in:
parent
97dae0d0a0
commit
1e96d0af8c
2 changed files with 15 additions and 11 deletions
|
|
@ -384,25 +384,29 @@ function createInjector(modulesToLoad) {
|
|||
|
||||
function invoke(fn, self, locals){
|
||||
var args = [],
|
||||
$injectAnnotation,
|
||||
$injectAnnotationIndex,
|
||||
$inject,
|
||||
length,
|
||||
key;
|
||||
|
||||
if (typeof fn == 'function') {
|
||||
$injectAnnotation = inferInjectionArgs(fn);
|
||||
$injectAnnotationIndex = $injectAnnotation.length;
|
||||
$inject = inferInjectionArgs(fn);
|
||||
length = $inject.length;
|
||||
} else {
|
||||
if (isArray(fn)) {
|
||||
$injectAnnotation = fn;
|
||||
$injectAnnotationIndex = $injectAnnotation.length;
|
||||
fn = $injectAnnotation[--$injectAnnotationIndex];
|
||||
$inject = fn;
|
||||
length = $inject.length - 1;
|
||||
fn = $inject[length];
|
||||
}
|
||||
assertArgFn(fn, 'fn');
|
||||
}
|
||||
|
||||
while($injectAnnotationIndex--) {
|
||||
key = $injectAnnotation[$injectAnnotationIndex];
|
||||
args.unshift(locals && locals.hasOwnProperty(key) ? locals[key] : getService(key));
|
||||
for(var i = 0; i < length; i++) {
|
||||
key = $inject[i];
|
||||
args.push(
|
||||
locals && locals.hasOwnProperty(key)
|
||||
? locals[key]
|
||||
: getService(key, path)
|
||||
);
|
||||
}
|
||||
|
||||
// Performance optimization: http://jsperf.com/apply-vs-call-vs-invoke
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ describe('injector', function() {
|
|||
|
||||
injector.get('s1');
|
||||
|
||||
expect(log).toEqual(['s6', 's5', 's3', 's4', 's2', 's1']);
|
||||
expect(log).toEqual(['s6', 's3', 's5', 's4', 's2', 's1']);
|
||||
});
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue