From b09c5ef04c1f6942b7f7ab8ae9bcdaec70c95b5c Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Mon, 27 Jun 2016 21:37:47 +0100 Subject: [PATCH] jquery.accessKeyLabel: Avoid needless mw.Message#parser in updateTooltip() When calling mw.util.addPortletLink(), Chrome on a MacBook Pro spends 3ms in mw.Message#parser for each link that doesn't even have a title. > addPortletLink: updateTooltipAccessKeys: updateTooltip: msg: mw.Message.parser Change-Id: Id6c26e31eb2c1431fe9725e608813bdf40069207 --- resources/src/jquery/jquery.accessKeyLabel.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/resources/src/jquery/jquery.accessKeyLabel.js b/resources/src/jquery/jquery.accessKeyLabel.js index 519e39bc8e..6ff2e01810 100644 --- a/resources/src/jquery/jquery.accessKeyLabel.js +++ b/resources/src/jquery/jquery.accessKeyLabel.js @@ -113,18 +113,19 @@ function getAccessKeyLabel( element ) { * @param {HTMLElement} titleElement Element with the title to update (may be the same as `element`) */ function updateTooltipOnElement( element, titleElement ) { - var array = ( mw.msg( 'word-separator' ) + mw.msg( 'brackets' ) ).split( '$1' ), - regexp = new RegExp( $.map( array, mw.RegExp.escape ).join( '.*?' ) + '$' ), - oldTitle = titleElement.title, - rawTitle = oldTitle.replace( regexp, '' ), - newTitle = rawTitle, - accessKeyLabel = getAccessKeyLabel( element ); - - // don't add a title if the element didn't have one before + var oldTitle, parts, regexp, newTitle, accessKeyLabel; + + oldTitle = titleElement.title; if ( !oldTitle ) { + // don't add a title if the element didn't have one before return; } + parts = ( mw.msg( 'word-separator' ) + mw.msg( 'brackets' ) ).split( '$1' ); + regexp = new RegExp( $.map( parts, mw.RegExp.escape ).join( '.*?' ) + '$' ); + newTitle = oldTitle.replace( regexp, '' ); + accessKeyLabel = getAccessKeyLabel( element ); + if ( accessKeyLabel ) { // Should be build the same as in Linker::titleAttrib newTitle += mw.msg( 'word-separator' ) + mw.msg( 'brackets', accessKeyLabel ); -- 2.20.1