mirror of
https://github.com/zhigang1992/angular.js.git
synced 2026-04-18 07:50:52 +08:00
fix(injector): small perf improvement & code cleanup
This commit is contained in:
@@ -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']);
|
||||
});
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user