From 7424b7984230235148e4e19d09a5e9fcb5e43483 Mon Sep 17 00:00:00 2001 From: John Koutsoumpas Date: Mon, 9 Mar 2020 17:44:12 +0200 Subject: [PATCH] replace expensive search method with efficient bottom-to-top one --- index.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 6137235..b2fddf9 100644 --- a/index.js +++ b/index.js @@ -21,7 +21,17 @@ module.exports = function(input, inputMap) { var resolve = this.resolve; var addDependency = this.addDependency; var emitWarning = this.emitWarning || function() {}; - var match = input.match(regex1) || input.match(regex2); + + var lines = input.split(/^/m); + var match = undefined; + + for(var i = lines.length - 1; i >= 0; i--) { + match = lines[i].match(regex1) || lines[i].match(regex2); + if(match) { + break; + } + } + if(match) { var url = match[1]; var dataUrlMatch = regexDataUrl.exec(url);