From f16cef118f170239b4ac325b72f58356c33914cd Mon Sep 17 00:00:00 2001 From: Zixaphir Date: Thu, 2 May 2013 01:23:51 -0700 Subject: [PATCH] Lets... not store a useless RegExp string in memory. --- builds/4chan-X.js | 4 +--- builds/4chan-X.user.js | 4 +--- builds/crx/script.js | 4 +--- src/Linkification/Linkify.coffee | 39 ++++++++++++++++---------------- 4 files changed, 22 insertions(+), 29 deletions(-) diff --git a/builds/4chan-X.js b/builds/4chan-X.js index c41fa701f..5b1b0ee3e 100644 --- a/builds/4chan-X.js +++ b/builds/4chan-X.js @@ -4107,7 +4107,7 @@ if (g.VIEW === 'catalog' || !Conf['Linkify']) { return; } - this.regString = Conf['Allow False Positives'] ? this.regLooseString : this.regStrictString; + this.regString = Conf['Allow False Positives'] ? /(\b([a-z]+:\/\/|[a-z]{3,}\.[-a-z0-9]+\.[a-z]+|[-a-z0-9]+\.[a-z]|[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+|[a-z]{3,}:[a-z0-9?]|[a-z0-9._%+-:]+@[a-z0-9.-]+\.[a-z0-9])[^\s'"]+)/gi : /(((magnet|mailto)\:|(www\.)|(news|(ht|f)tp(s?))\:\/\/){1}\S+)/gi; if (Conf['Comment Expansion']) { ExpandComment.callbacks.push(this.node); } @@ -4116,8 +4116,6 @@ cb: this.node }); }, - regLooseString: /(\b([a-z]+:\/\/|[a-z]{3,}\.[-a-z0-9]+\.[a-z]+|[-a-z0-9]+\.[a-z]|[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+|[a-z]{3,}:[a-z0-9?]|[a-z0-9._%+-:]+@[a-z0-9.-]+\.[a-z0-9])[^\s'"]+)/gi, - regStrictString: /(((magnet|mailto)\:|(www\.)|(news|(ht|f)tp(s?))\:\/\/){1}\S+)/gi, cypher: $.el('div'), node: function() { var a, child, cypher, cypherText, data, embed, embedder, embeds, i, index, len, link, links, lookahead, name, next, node, nodes, snapshot, spoiler, text, _i, _j, _k, _l, _len, _len1, _len2, _len3, _len4, _m, _ref, _ref1, _ref2; diff --git a/builds/4chan-X.user.js b/builds/4chan-X.user.js index 319fa8f58..4f91239ea 100644 --- a/builds/4chan-X.user.js +++ b/builds/4chan-X.user.js @@ -4103,7 +4103,7 @@ if (g.VIEW === 'catalog' || !Conf['Linkify']) { return; } - this.regString = Conf['Allow False Positives'] ? this.regLooseString : this.regStrictString; + this.regString = Conf['Allow False Positives'] ? /(\b([a-z]+:\/\/|[a-z]{3,}\.[-a-z0-9]+\.[a-z]+|[-a-z0-9]+\.[a-z]|[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+|[a-z]{3,}:[a-z0-9?]|[a-z0-9._%+-:]+@[a-z0-9.-]+\.[a-z0-9])[^\s'"]+)/gi : /(((magnet|mailto)\:|(www\.)|(news|(ht|f)tp(s?))\:\/\/){1}\S+)/gi; if (Conf['Comment Expansion']) { ExpandComment.callbacks.push(this.node); } @@ -4112,8 +4112,6 @@ cb: this.node }); }, - regLooseString: /(\b([a-z]+:\/\/|[a-z]{3,}\.[-a-z0-9]+\.[a-z]+|[-a-z0-9]+\.[a-z]|[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+|[a-z]{3,}:[a-z0-9?]|[a-z0-9._%+-:]+@[a-z0-9.-]+\.[a-z0-9])[^\s'"]+)/gi, - regStrictString: /(((magnet|mailto)\:|(www\.)|(news|(ht|f)tp(s?))\:\/\/){1}\S+)/gi, cypher: $.el('div'), node: function() { var a, child, cypher, cypherText, data, embed, embedder, embeds, i, index, len, link, links, lookahead, name, next, node, nodes, snapshot, spoiler, text, _i, _j, _k, _l, _len, _len1, _len2, _len3, _len4, _m, _ref, _ref1, _ref2; diff --git a/builds/crx/script.js b/builds/crx/script.js index e46fe5f50..f569158b0 100644 --- a/builds/crx/script.js +++ b/builds/crx/script.js @@ -4105,7 +4105,7 @@ if (g.VIEW === 'catalog' || !Conf['Linkify']) { return; } - this.regString = Conf['Allow False Positives'] ? this.regLooseString : this.regStrictString; + this.regString = Conf['Allow False Positives'] ? /(\b([a-z]+:\/\/|[a-z]{3,}\.[-a-z0-9]+\.[a-z]+|[-a-z0-9]+\.[a-z]|[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+|[a-z]{3,}:[a-z0-9?]|[a-z0-9._%+-:]+@[a-z0-9.-]+\.[a-z0-9])[^\s'"]+)/gi : /(((magnet|mailto)\:|(www\.)|(news|(ht|f)tp(s?))\:\/\/){1}\S+)/gi; if (Conf['Comment Expansion']) { ExpandComment.callbacks.push(this.node); } @@ -4114,8 +4114,6 @@ cb: this.node }); }, - regLooseString: /(\b([a-z]+:\/\/|[a-z]{3,}\.[-a-z0-9]+\.[a-z]+|[-a-z0-9]+\.[a-z]|[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+|[a-z]{3,}:[a-z0-9?]|[a-z0-9._%+-:]+@[a-z0-9.-]+\.[a-z0-9])[^\s'"]+)/gi, - regStrictString: /(((magnet|mailto)\:|(www\.)|(news|(ht|f)tp(s?))\:\/\/){1}\S+)/gi, cypher: $.el('div'), node: function() { var a, child, cypher, cypherText, data, embed, embedder, embeds, i, index, len, link, links, lookahead, name, next, node, nodes, snapshot, spoiler, text, _i, _j, _k, _l, _len, _len1, _len2, _len3, _len4, _m, _ref, _ref1, _ref2; diff --git a/src/Linkification/Linkify.coffee b/src/Linkification/Linkify.coffee index 6a497455e..8862fd11d 100644 --- a/src/Linkification/Linkify.coffee +++ b/src/Linkification/Linkify.coffee @@ -2,7 +2,25 @@ Linkify = init: -> return if g.VIEW is 'catalog' or not Conf['Linkify'] - @regString = if Conf['Allow False Positives'] then @regLooseString else @regStrictString + @regString = if Conf['Allow False Positives'] + ///( + \b( + [a-z]+:// + | + [a-z]{3,}\.[-a-z0-9]+\.[a-z]+ + | + [-a-z0-9]+\.[a-z] + | + [0-9]+\.[0-9]+\.[0-9]+\.[0-9]+ + | + [a-z]{3,}:[a-z0-9?] + | + [a-z0-9._%+-:]+@[a-z0-9.-]+\.[a-z0-9] + ) + [^\s'"]+ + )///gi + else + /(((magnet|mailto)\:|(www\.)|(news|(ht|f)tp(s?))\:\/\/){1}\S+)/gi if Conf['Comment Expansion'] ExpandComment.callbacks.push @node @@ -11,25 +29,6 @@ Linkify = name: 'Linkify' cb: @node - regLooseString: ///( - \b( - [a-z]+:// - | - [a-z]{3,}\.[-a-z0-9]+\.[a-z]+ - | - [-a-z0-9]+\.[a-z] - | - [0-9]+\.[0-9]+\.[0-9]+\.[0-9]+ - | - [a-z]{3,}:[a-z0-9?] - | - [a-z0-9._%+-:]+@[a-z0-9.-]+\.[a-z0-9] - ) - [^\s'"]+ - )///gi - - regStrictString: ///(((magnet|mailto)\:|(www\.)|(news|(ht|f)tp(s?))\://){1}\S+)///gi - cypher: $.el 'div' node: ->