From 7959828e48aac956ed58c356451d2db11776819e Mon Sep 17 00:00:00 2001 From: nacin Date: Tue, 28 Feb 2012 20:51:19 +0000 Subject: [PATCH] Faster theme searching. Only calculate what is necessary -- if the theme doesn't have all of the features, bail. If a word matches a tag or header, jump to the next word, we don't care how many times it matches. see #20103. git-svn-id: http://svn.automattic.com/wordpress/trunk@20027 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- .../includes/class-wp-themes-list-table.php | 41 ++++++++----------- 1 file changed, 16 insertions(+), 25 deletions(-) diff --git a/wp-admin/includes/class-wp-themes-list-table.php b/wp-admin/includes/class-wp-themes-list-table.php index c64074c46..059335baa 100644 --- a/wp-admin/includes/class-wp-themes-list-table.php +++ b/wp-admin/includes/class-wp-themes-list-table.php @@ -190,38 +190,29 @@ class WP_Themes_List_Table extends WP_List_Table { } function search_theme( $theme ) { - $matched = 0; + // Search the features + if ( $this->features ) { + foreach ( $this->features as $word ) { + if ( ! in_array( $word, $theme['Tags'] ) ) + return false; + } + } // Match all phrases - if ( count( $this->search ) > 0 ) { + if ( $this->search ) { foreach ( $this->search as $word ) { - $matched = 0; - - // In a tag? if ( in_array( $word, $theme['Tags'] ) ) - $matched = 1; - - // In one of the fields? - foreach ( array( 'Name', 'Title', 'Description', 'Author', 'Template', 'Stylesheet' ) AS $field ) { - if ( stripos( $theme[$field], $word ) !== false ) - $matched++; - } - - if ( $matched == 0 ) - return false; + continue; } + + foreach ( array( 'Name', 'Title', 'Description', 'Author', 'Template', 'Stylesheet' ) as $header ) { + if ( false !== stripos( $theme[ $header ], $word ) ) + continue 2; + } + + return false; } - // Now search the features - if ( count( $this->features ) > 0 ) { - foreach ( $this->features as $word ) { - // In a tag? - if ( !in_array( $word, $theme['Tags'] ) ) - return false; - } - } - - // Only get here if each word exists in the tags or one of the fields return true; } }