twitter-archive / twitter-text-js

A JavaScript implementation of Twitter's text processing library
1.21k stars 166 forks source link

Some RegExp optimizations #70

Open devinrhode2 opened 11 years ago

devinrhode2 commented 11 years ago

I give full credit to closure compiler for this. I cleaned up the output a lot, the WARNING's are all for the same References to the global RegExp object prevents optimization of regular expressions.

twitter-text.js:787: WARNING - References to the global RegExp object prevents optimization of regular expressions.
        RegExp.rightContext.match(twttr.txt.regexen.endMentionMatch)) {
        ^

twitter-text.js:817: WARNING 
      var before = RegExp.$2, url = RegExp.$3, protocol = RegExp.$4, domain = RegExp.$5, path = RegExp.$7;
                   ^                ^                     ^                   ^                 ^

twitter-text.js:860: WARNING 
          url = RegExp.lastMatch;
                ^

twitter-text.js:1268: WARNING
      return ((typeof string === "string") && string.match(regex) && RegExp["$&"] === string);
                                                                     ^

twitter-text.js:1272: WARNING
    return (!string || (string.match(regex) && RegExp["$&"] === string));
                                               ^
lukeasrodgers commented 11 years ago

IIRC, the reason why closure compiler can't optimize these is precisely because you can do things like RegExp.$1, which this library does in a bunch of places, so fixing these warnings would require a significant refactor.