Commit e1764ed9 authored by Olly Betts's avatar Olly Betts
Browse files

[java] Optimise setlimit tomark AE for ...

All uses of setlimit in the current stemmers we ship follow this
pattern, and by special-casing we can avoid having to save and restore
the cursor.

Addresses https://github.com/snowballstem/snowball/issues/74 for
Java.
parent 3f5d84b6
...@@ -763,19 +763,32 @@ static void generate_setlimit(struct generator * g, struct node * p) { ...@@ -763,19 +763,32 @@ static void generate_setlimit(struct generator * g, struct node * p) {
struct str * savevar = vars_newname(g); struct str * savevar = vars_newname(g);
struct str * varname = vars_newname(g); struct str * varname = vars_newname(g);
write_comment(g, p); write_comment(g, p);
write_savecursor(g, p, savevar); if (p->left && p->left->type == c_tomark && !p->left->right) {
generate(g, p->left); /* Special case for:
*
* setlimit tomark AE for C
*
* All uses of setlimit in the current stemmers we ship follow this
* pattern, and by special-casing we can avoid having to save and
* restore c.
*/
struct node * q = p->left;
g->S[0] = q->mode == m_forward ? ">" : "<";
w(g, "~Mif (cursor ~S0 "); generate_AE(g, q->AE); w(g, ")~N");
write_block_start(g);
write_failure(g);
write_block_end(g);
g->unreachable = false;
if (!g->unreachable) {
g->B[0] = str_data(varname); g->B[0] = str_data(varname);
if (p->mode == m_forward) { if (p->mode == m_forward) {
w(g, "~Mint ~B0 = limit - cursor;~N"); w(g, "~Mint ~B0 = limit - cursor;~N");
w(g, "~Mlimit = cursor;~N"); w(g, "~Mlimit = ");
} else { } else {
w(g, "~Mint ~B0 = limit_backward;~N"); w(g, "~Mint ~B0 = limit_backward;~N");
w(g, "~Mlimit_backward = cursor;~N"); w(g, "~Mlimit_backward = ");
} }
write_restorecursor(g, p, savevar); generate_AE(g, q->AE); writef(g, ";~N", q);
if (p->mode == m_forward) { if (p->mode == m_forward) {
str_assign(g->failure_str, "limit += "); str_assign(g->failure_str, "limit += ");
...@@ -786,6 +799,34 @@ static void generate_setlimit(struct generator * g, struct node * p) { ...@@ -786,6 +799,34 @@ static void generate_setlimit(struct generator * g, struct node * p) {
str_append(g->failure_str, varname); str_append(g->failure_str, varname);
str_append_ch(g->failure_str, ';'); str_append_ch(g->failure_str, ';');
} }
} else {
write_savecursor(g, p, savevar);
generate(g, p->left);
if (!g->unreachable) {
g->B[0] = str_data(varname);
if (p->mode == m_forward) {
w(g, "~Mint ~B0 = limit - cursor;~N");
w(g, "~Mlimit = cursor;~N");
} else {
w(g, "~Mint ~B0 = limit_backward;~N");
w(g, "~Mlimit_backward = cursor;~N");
}
write_restorecursor(g, p, savevar);
if (p->mode == m_forward) {
str_assign(g->failure_str, "limit += ");
str_append(g->failure_str, varname);
str_append_ch(g->failure_str, ';');
} else {
str_assign(g->failure_str, "limit_backward = ");
str_append(g->failure_str, varname);
str_append_ch(g->failure_str, ';');
}
}
}
if (!g->unreachable) {
generate(g, p->aux); generate(g, p->aux);
if (!g->unreachable) { if (!g->unreachable) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment