Page MenuHomePhabricator

Avoid using array_map in ExtensionRegistry and ExtensionProcessor for simple operations
Closed, ResolvedPublic

Description

In MediaWiki core's includes/registration/ directory, there are a few (two I think) places we use array_map for very simple operations:

			$this->globals["wgExtensionMessagesFiles"] += array_map( function ( $file ) use ( $dir ) {
				return "$dir/$file";
			}, $info['ExtensionMessagesFiles'] );

Since these are quick operations, we can make this code faster by using a foreach loop instead of array_map with a closure (unnecessary function calls are expensive).

I'll mentor this task for Google-Code-in-2017 .

Event Timeline

One alternative is to use the reference form of foreach:

function prefixArray( $array, $prefix ) {
    foreach ( $array as &$element ) {
        $element = "$prefix/$element";
    }
    return $array;
}

Change 398015 had a related patch set uploaded (by Eflyjason; owner: Eflyjason):
[mediawiki/core@master] Avoid using array_map in ExtensionRegistry and ExtensionProcessor for simple operations

https://gerrit.wikimedia.org/r/398015

Change 398015 merged by jenkins-bot:
[mediawiki/core@master] Avoid using array_map in ExtensionRegistry and ExtensionProcessor for simple operations

https://gerrit.wikimedia.org/r/398015

eflyjason claimed this task.