mirror of
https://github.com/discourse/discourse.git
synced 2025-09-06 10:50:21 +08:00
optimize rule lookup
we have tons of bbcode rules, might as well speed them up
This commit is contained in:
parent
0ba39109a0
commit
0650c8dbab
3 changed files with 23 additions and 23 deletions
|
@ -48,8 +48,24 @@ class Ruler {
|
|||
return this.rules;
|
||||
}
|
||||
|
||||
getRuleForTag(tag) {
|
||||
this.ensureCache();
|
||||
return this.cache[tag];
|
||||
}
|
||||
|
||||
ensureCache() {
|
||||
if (this.cache) { return; }
|
||||
|
||||
this.cache = {};
|
||||
for(let i=this.rules.length-1;i>=0;i--) {
|
||||
let info = this.rules[i];
|
||||
this.cache[info.rule.tag] = info;
|
||||
}
|
||||
}
|
||||
|
||||
push(name, rule) {
|
||||
this.rules.push({name, rule});
|
||||
this.cache = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue