Performance improvements
This commit is contained in:
parent
015c262bbf
commit
18fc8d9865
@ -48,22 +48,21 @@ class Deinflection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (const rule in rules) {
|
for (const rule in rules) {
|
||||||
const variants = rules[rule];
|
for (const variant of rules[rule]) {
|
||||||
for (const v of variants) {
|
|
||||||
let allowed = this.tags.length === 0;
|
let allowed = this.tags.length === 0;
|
||||||
for (const tag of this.tags) {
|
for (const tag of this.tags) {
|
||||||
if (v.ti.indexOf(tag) !== -1) {
|
if (variant.ti.indexOf(tag) !== -1) {
|
||||||
allowed = true;
|
allowed = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!allowed || !this.term.endsWith(v.ki)) {
|
if (!allowed || !this.term.endsWith(variant.ki)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const term = this.term.slice(0, -v.ki.length) + v.ko;
|
const term = this.term.slice(0, -variant.ki.length) + variant.ko;
|
||||||
const child = new Deinflection(term, v.to, rule);
|
const child = new Deinflection(term, variant.to, rule);
|
||||||
if (child.deinflect(validator, rules)) {
|
if (child.deinflect(validator, rules)) {
|
||||||
this.children.push(child);
|
this.children.push(child);
|
||||||
}
|
}
|
||||||
|
@ -35,6 +35,7 @@ class Yomichan {
|
|||||||
|
|
||||||
this.translator = new Translator();
|
this.translator = new Translator();
|
||||||
this.asyncPools = {};
|
this.asyncPools = {};
|
||||||
|
this.ankiConnectVer = 0;
|
||||||
this.setState('disabled');
|
this.setState('disabled');
|
||||||
|
|
||||||
chrome.runtime.onInstalled.addListener(this.onInstalled.bind(this));
|
chrome.runtime.onInstalled.addListener(this.onInstalled.bind(this));
|
||||||
@ -129,14 +130,19 @@ class Yomichan {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ankiInvokeSafe(action, params, pool, callback) {
|
ankiInvokeSafe(action, params, pool, callback) {
|
||||||
|
if (this.ankiConnectVer === this.getApiVersion()) {
|
||||||
|
this.ankiInvoke(action, params, pool, callback);
|
||||||
|
} else {
|
||||||
this.api_getVersion({callback: (version) => {
|
this.api_getVersion({callback: (version) => {
|
||||||
if (version === this.getApiVersion()) {
|
if (version === this.getApiVersion()) {
|
||||||
|
this.ankiConnectVer = version;
|
||||||
this.ankiInvoke(action, params, pool, callback);
|
this.ankiInvoke(action, params, pool, callback);
|
||||||
} else {
|
} else {
|
||||||
callback(null);
|
callback(null);
|
||||||
}
|
}
|
||||||
}});
|
}});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ankiInvoke(action, params, pool, callback) {
|
ankiInvoke(action, params, pool, callback) {
|
||||||
if (this.options.enableAnkiConnect) {
|
if (this.options.enableAnkiConnect) {
|
||||||
|
Loading…
Reference in New Issue
Block a user