Performance of mediawiki.searchSuggest.js
authorThiemo Mättig <thiemo.maettig@wikimedia.de>
Fri, 14 Feb 2014 12:58:44 +0000 (13:58 +0100)
committerThiemo Mättig <thiemo.maettig@wikimedia.de>
Fri, 14 Feb 2014 12:58:44 +0000 (13:58 +0100)
Two tiny performance improvements.

The complexity of a regular expression is not needed to check if a
string contains a character. string.match() returns an array of
matches which is not used anyway in this case. Either
string.indexOf() or RegExp.test() should be used.

Duplicate jQuery call merged.

Change-Id: Ifec79eada70181df0d56c583ef832ee82594620e

resources/mediawiki/mediawiki.searchSuggest.js

index 3b360af..8d950a0 100644 (file)
 
                // Compute form data for search suggestions functionality.
                function computeResultRenderCache( context ) {
-                       var $form, formAction, baseHref, linkParams;
+                       var $form, baseHref, linkParams;
 
                        // Compute common parameters for links' hrefs
                        $form = context.config.$region.closest( 'form' );
 
-                       formAction = $form.attr( 'action' );
-                       baseHref = formAction + ( formAction.match( /\?/ ) ? '&' : '?' );
+                       baseHref = $form.attr( 'action' );
+                       baseHref += baseHref.indexOf( '?' ) > -1 ? '&' : '?';
 
                        linkParams = {};
                        $.each( $form.serializeArray(), function ( idx, obj ) {
                        special: {
                                render: specialRenderFunction,
                                select: function ( $input ) {
-                                       $input.closest( 'form' ).append(
-                                               $( '<input type="hidden" name="fulltext" value="1"/>' )
-                                       );
-                                       $input.closest( 'form' ).submit();
+                                       $input.closest( 'form' )
+                                               .append( $( '<input type="hidden" name="fulltext" value="1"/>' ) )
+                                               .submit();
                                }
                        },
                        $region: $searchRegion