added caching to parse() function
This commit is contained in:
@@ -1044,9 +1044,16 @@
|
|||||||
this._protocolRegex = /^[a-zA-Z]+:\/\//i;
|
this._protocolRegex = /^[a-zA-Z]+:\/\//i;
|
||||||
this._urlRegex = /^((https?:\/\/)?[\w-]+(\.[\w-]+)+\.?(:\d+)?(\/\S*)?)$/i;
|
this._urlRegex = /^((https?:\/\/)?[\w-]+(\.[\w-]+)+\.?(:\d+)?(\/\S*)?)$/i;
|
||||||
this.parse = this.parse.bind(this);
|
this.parse = this.parse.bind(this);
|
||||||
|
this._lastQuery = "";
|
||||||
|
this._lastParse;
|
||||||
}
|
}
|
||||||
|
|
||||||
parse(query) {
|
parse(query) {
|
||||||
|
if (this._lastQuery === query) {
|
||||||
|
return this._lastParse;
|
||||||
|
}
|
||||||
|
this._lastQuery = query;
|
||||||
|
|
||||||
const res = { query: query, split: null };
|
const res = { query: query, split: null };
|
||||||
|
|
||||||
if (this._urlRegex.test(query)) {
|
if (this._urlRegex.test(query)) {
|
||||||
@@ -1090,6 +1097,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
res.color = QueryParser._getColorFromUrl(this._commands, res.redirect);
|
res.color = QueryParser._getColorFromUrl(this._commands, res.redirect);
|
||||||
|
this._lastParse = res;
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user