Thiemo Mättig (WMDE) has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/304005

Change subject: Prefer test() and simplify regular expressions for performance
......................................................................

Prefer test() and simplify regular expressions for performance

Change-Id: I3c1a9d8830ad477b5ff857a7c98eb68b26ded698
---
M wikibase/queryService/api/QuerySamples.js
M wikibase/queryService/api/Sparql.js
M wikibase/queryService/ui/editor/hint/Sparql.js
M wikibase/queryService/ui/resultBrowser/helper/FormatterHelper.js
4 files changed, 6 insertions(+), 13 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/wikidata/query/gui 
refs/changes/05/304005/1

diff --git a/wikibase/queryService/api/QuerySamples.js 
b/wikibase/queryService/api/QuerySamples.js
index db8f0fb..e5bc4d3 100644
--- a/wikibase/queryService/api/QuerySamples.js
+++ b/wikibase/queryService/api/QuerySamples.js
@@ -55,7 +55,7 @@
        SELF.prototype._extract = function ( wikitext ) {
                var self = this,
                        examples = [],
-                       regexSection = /^\=\=([^\=]+)\=\=$/g,
+                       regexSection = /^==([^=]+)==$/gm,
                        section = '',
                        sectionHeader = null;
 
diff --git a/wikibase/queryService/api/Sparql.js 
b/wikibase/queryService/api/Sparql.js
index a88ee10..c46772d 100644
--- a/wikibase/queryService/api/Sparql.js
+++ b/wikibase/queryService/api/Sparql.js
@@ -232,7 +232,7 @@
         */
        SELF.prototype._encodeCsv = function( string ) {
                var result = string.replace( /"/g, '""' );
-               if ( result.search( /("|,|\n)/g ) >= 0 ) {
+               if ( /[",\n]/.test( result ) ) {
                        result = '"' + result + '"';
                }
                return result;
diff --git a/wikibase/queryService/ui/editor/hint/Sparql.js 
b/wikibase/queryService/ui/editor/hint/Sparql.js
index 8a744c2..3724694 100755
--- a/wikibase/queryService/ui/editor/hint/Sparql.js
+++ b/wikibase/queryService/ui/editor/hint/Sparql.js
@@ -88,7 +88,7 @@
        SELF.prototype._getDefinedVariables = function( text ) {
                var variables = {};
 
-               $.each( text.match( /\?[\w]+/g ), function( key, word ) {
+               $.each( text.match( /\?\w+/g ), function( key, word ) {
                        variables[ word ] = true;
                } );
 
@@ -135,7 +135,7 @@
                        pos = 0;
                }
 
-               while ( line.charAt( pos ).match( /[\w?#]/ ) ) {
+               while ( /[\w?#]/.test( line.charAt( pos ) ) ) {
                        pos--;
                        if ( pos < 0 ) {
                                break;
@@ -144,7 +144,7 @@
                var left = pos + 1;
 
                pos = position;
-               while ( line.charAt( pos ).match( /[\w]/ ) ) {
+               while ( /\w/.test( line.charAt( pos ) ) ) {
                        pos++;
                        if ( pos >= line.length ) {
                                break;
diff --git a/wikibase/queryService/ui/resultBrowser/helper/FormatterHelper.js 
b/wikibase/queryService/ui/resultBrowser/helper/FormatterHelper.js
index fe3cccd..183a3e8 100644
--- a/wikibase/queryService/ui/resultBrowser/helper/FormatterHelper.js
+++ b/wikibase/queryService/ui/resultBrowser/helper/FormatterHelper.js
@@ -230,15 +230,8 @@
                if ( !this.isCommonsResource( url ) ) {
                        return url;
                }
-               if ( !width ) {
-                       width = 400;
-               }
 
-               if ( url.match( /^http\:\/\//i ) ) {
-                       url = url.replace( /^http\:\/\//, 'https://' );
-               }
-
-               return url + '?width=' + width;
+               return url.replace( /^http(?=:\/\/)/, 'https' ) + '?width=' + ( 
width || 400 );
        };
 
        /**

-- 
To view, visit https://gerrit.wikimedia.org/r/304005
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I3c1a9d8830ad477b5ff857a7c98eb68b26ded698
Gerrit-PatchSet: 1
Gerrit-Project: wikidata/query/gui
Gerrit-Branch: master
Gerrit-Owner: Thiemo Mättig (WMDE) <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to