From a7f6b5be604e9cc94d5905aa33aa7354078f59bc Mon Sep 17 00:00:00 2001 From: Camille Barneaud Date: Sat, 2 Nov 2013 19:08:41 +0100 Subject: [PATCH] Replace array.map() by array.forEach() As told by @q-- in #376 replace array.map() by array.forEach() because it's faster and the array returned by map() is not used --- drivers/bookmarklet/js/driver.js | 2 +- drivers/chrome/js/driver.js | 6 +++--- drivers/chrome/js/popup.js | 2 +- drivers/html/js/driver.js | 2 +- drivers/php/js/driver.js | 2 +- share/js/wappalyzer.js | 20 ++++++++++---------- 6 files changed, 17 insertions(+), 17 deletions(-) diff --git a/drivers/bookmarklet/js/driver.js b/drivers/bookmarklet/js/driver.js index eb5d2db9e..19b3f8121 100644 --- a/drivers/bookmarklet/js/driver.js +++ b/drivers/bookmarklet/js/driver.js @@ -125,7 +125,7 @@ ; if ( w.detected[url] != null && w.detected[url].length ) { - w.detected[url].map(function(app, i) { + w.detected[url].forEach(function(app, i) { html += '
' + '' + diff --git a/drivers/chrome/js/driver.js b/drivers/chrome/js/driver.js index 078362a18..de0b651d2 100644 --- a/drivers/chrome/js/driver.js +++ b/drivers/chrome/js/driver.js @@ -102,7 +102,7 @@ }); chrome.tabs.query({}, function(tabs) { - tabs.map(function(tab) { + tabs.forEach(function(tab) { if ( tab.url.match(/^https?:\/\//) ) { chrome.tabs.executeScript(tab.id, { file: 'js/content.js' }); } @@ -152,9 +152,9 @@ // Find the main application to display var i, appName, found = false; - w.driver.categoryOrder.map(function(match) { + w.driver.categoryOrder.forEach(function(match) { for ( appName in w.detected[tab.url] ) { - w.apps[appName].cats.map(function(cat) { + w.apps[appName].cats.forEach(function(cat) { if ( cat == match && !found ) { chrome.browserAction.setIcon({ tabId: tab.id, path: 'images/icons/' + appName + '.png' }); diff --git a/drivers/chrome/js/popup.js b/drivers/chrome/js/popup.js index 10b2a7e0f..d21be18fb 100644 --- a/drivers/chrome/js/popup.js +++ b/drivers/chrome/js/popup.js @@ -68,7 +68,7 @@ document.addEventListener('DOMContentLoaded', function() { '' + appName + ( version ? ' ' + version : '' ) + ( confidence < 100 ? ' (' + confidence + '% sure)' : '' ) + '' + ''; - response.apps[appName].cats.map(function(cat) { + response.apps[appName].cats.forEach(function(cat) { html += '' + '' + chrome.i18n.getMessage('categoryName' + cat) + '' + diff --git a/drivers/html/js/driver.js b/drivers/html/js/driver.js index 085d2223f..98a622b17 100644 --- a/drivers/html/js/driver.js +++ b/drivers/html/js/driver.js @@ -46,7 +46,7 @@ displayApps: function() { document.getElementById('apps').innerHTML = ''; - w.detected['http://google.com'].map(function(app) { + w.detected['http://google.com'].forEach(function(app) { document.getElementById('apps').innerHTML += ' ' + app + '
'; }); }, diff --git a/drivers/php/js/driver.js b/drivers/php/js/driver.js index 91416520c..f6e6994bd 100644 --- a/drivers/php/js/driver.js +++ b/drivers/php/js/driver.js @@ -30,7 +30,7 @@ w.driver = { version: w.detected[w.driver.data.url][app].version }; - w.apps[app].cats.map(function(cat) { + w.apps[app].cats.forEach(function(cat) { apps[app].categories.push(w.categories[cat]); }); }; diff --git a/share/js/wappalyzer.js b/share/js/wappalyzer.js index 6f66052de..06645a6d4 100644 --- a/share/js/wappalyzer.js +++ b/share/js/wappalyzer.js @@ -78,7 +78,7 @@ var wappalyzer = (function() { w.log({ matches: matches, version: version }); if ( matches ) { - matches.map(function(match, i) { + matches.forEach(function(match, i) { // Parse ternary operator var ternary = new RegExp('\\\\' + i + '\\?([^:]+):(.+)$').exec(version); @@ -158,10 +158,10 @@ var wappalyzer = (function() { patterns = [ patterns ]; } - patterns.map(function(pattern) { + patterns.forEach(function(pattern) { attrs = {}; - pattern.split('\\;').map(function(attr, i) { + pattern.split('\\;').forEach(function(attr, i) { if ( i ) { // Key value pairs attr = attr.split(':'); @@ -276,7 +276,7 @@ var wappalyzer = (function() { for ( type in w.apps[app] ) { switch ( type ) { case 'url': - parse(w.apps[app][type]).map(function(pattern) { + parse(w.apps[app][type]).forEach(function(pattern) { if ( pattern.regex.test(url) ) { apps[app].setDetected(pattern, type, url); @@ -290,7 +290,7 @@ var wappalyzer = (function() { break; } - parse(w.apps[app][type]).map(function(pattern) { + parse(w.apps[app][type]).forEach(function(pattern) { if ( pattern.regex.test(data[type]) ) { apps[app].setDetected(pattern, type, data[type]); @@ -306,7 +306,7 @@ var wappalyzer = (function() { regexScript = new RegExp(']+src=("|\')([^"\']+)', 'ig'); - parse(w.apps[app][type]).map(function(pattern) { + parse(w.apps[app][type]).forEach(function(pattern) { while ( match = regexScript.exec(data.html) ) { if ( pattern.regex.test(match[2]) ) { @@ -331,7 +331,7 @@ var wappalyzer = (function() { if ( new RegExp('name=["\']' + meta + '["\']', 'i').test(match) ) { content = match.toString().match(/content=("|')([^"']+)("|')/i); - parse(w.apps[app].meta[meta]).map(function(pattern) { + parse(w.apps[app].meta[meta]).forEach(function(pattern) { if ( content && content.length === 4 && pattern.regex.test(content[2]) ) { apps[app].setDetected(pattern, type, content[2], meta); @@ -349,7 +349,7 @@ var wappalyzer = (function() { } for ( header in w.apps[app].headers ) { - parse(w.apps[app][type][header]).map(function(pattern) { + parse(w.apps[app][type][header]).forEach(function(pattern) { if ( typeof data[type][header.toLowerCase()] === 'string' && pattern.regex.test(data[type][header.toLowerCase()]) ) { apps[app].setDetected(pattern, type, data[type][header.toLowerCase()], header); @@ -364,7 +364,7 @@ var wappalyzer = (function() { break; } - parse(w.apps[app][type]).map(function(pattern) { + parse(w.apps[app][type]).forEach(function(pattern) { for ( i in data[type] ) { if ( pattern.regex.test(data[type][i]) ) { @@ -402,7 +402,7 @@ var wappalyzer = (function() { w.apps[app].implies = [ w.apps[app].implies ]; } - w.apps[app].implies.map(function(implied) { + w.apps[app].implies.forEach(function(implied) { implied = parse(implied)[0]; if ( !w.apps[implied.string] ) {