Class: MatchPatternSet

matching~MatchPatternSet

An optimized object for matching against match patterns. A MatchPatternSet can provide a significant performance improvement in comparison to RegExps, in some instances greater than 100x. A MatchPatternSet can also be exported to an object that uses only built-in types, so it can be persisted or passed to content scripts in extension storage.

There are several key optimizations in MatchPatternSet:

  • URLs are parsed with the URL class, which has native implementation.
  • Match patterns are indexed by hostname in a hash map. Lookups are much faster than iteratively advancing and backtracking through a complex regular expression, which is how domain matching currently occurs with the Irregexp regular expression engine in Firefox and Chrome.
  • Match patterns with identical scheme, subdomain matching, and host (i.e., that differ only in path) are combined.
  • The only remaining use of regular expressions is in path matching, where expressions can be (relatively) uncomplicated.

Future performance improvements could include:

  • Replacing the path matching implementation to eliminate regular expressions entirely.
  • Replacing the match pattern index, such as by implementing a trie.

Methods

export() → {Object}

Serializes the internals of the match pattern set to a serializable object, for purposes of saving to extension local storage or messaging across contexts.

Source:
Returns:
  • An opaque serializable object representing the match pattern set internals.
Type
Object

matches(url) → {boolean}

Compares a URL string to the match patterns in the set.

Parameters:
Name Type Description
url string

The URL string to compare.

Source:
Returns:

Whether the URL string matches a pattern in the set.

Type
boolean