r96016 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r96015‎ | r96016 | r96017 >
Date:17:25, 1 September 2011
Author:krinkle
Status:ok (Comments)
Tags:
Comment:
Optimize ucFirst by using charAt
Modified paths:
  • /trunk/phase3/resources/jquery/jquery.mwExtension.js (modified) (history)

Diff [purge]

Index: trunk/phase3/resources/jquery/jquery.mwExtension.js
@@ -12,7 +12,7 @@
1313 '' : str.toString().replace( /\s+$/, '' );
1414 },
1515 ucFirst: function( str ) {
16 - return str.substr( 0, 1 ).toUpperCase() + str.substr( 1 );
 16+ return str.charAt( 0 ).toUpperCase() + str.substr( 1 );
1717 },
1818 escapeRE: function( str ) {
1919 return str.replace ( /([\\{}()|.?*+\-^$\[\]])/g, "\\$1" );

Sign-offs

UserFlagDate
Nikerabbitinspected20:18, 1 September 2011
Nikerabbittested20:18, 1 September 2011

Comments

#Comment by Hashar (talk | contribs)   15:25, 17 October 2011

Looks like a valid micro optimization. Since charAt() is in JS 1.0, we can assume this is working correctly on all browsers.

Note that both charAt() and substr() returns an empty string if index is out of range.

Status & tagging log