Make WordPress Core

Opened 14 years ago

Closed 14 years ago

#20126 closed defect (bug) (fixed)

get_file_data() is obtuse

Reported by: nacin's profile nacin Owned by: nacin's profile nacin
Milestone: 3.4 Priority: normal
Severity: normal Version:
Component: Performance Keywords:
Focuses: Cc:

Description

get_file_data() employs two odd-looking constructs. This is to make keys equal the values:

$extra_headers = array_flip( $extra_headers );
foreach( $extra_headers as $key=>$value ) {
	$extra_headers[$key] = $key;
}

A single array_combine() will clean this up.

Later, it uses ${$field}, followed by a return compact( array_keys( ) ), rather than simply building the output array in the format for which it is returned.

Attached is a simple patch that shortens the function while making it easier to understand, and introduces some small performance gains.

Attachments (1)

20126.diff (1.4 KB) - added by nacin 14 years ago.

Download all attachments as: .zip

Change History (3)

@nacin
14 years ago

#1 @scribu
14 years ago

In fairness, array_combine() was not available in PHP4.

#2 @nacin
14 years ago

  • Owner set to nacin
  • Resolution set to fixed
  • Status changed from new to closed

In [20088]:

Use array_combine() in get_file_data() and avoid variable variables when an array is just fine. fixes #20126.

Note: See TracTickets for help on using tickets.