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

Legoktm created this task.Dec 12 2017, 12:40 AM
Restricted Application added a subscriber: Aklapper. · View Herald TranscriptDec 12 2017, 12:40 AM

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 closed this task as Resolved.Dec 15 2017, 11:56 AM
eflyjason claimed this task.