Commit 63f66b10 authored by Olly Betts's avatar Olly Betts
Browse files

[pascal] 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 Pascal.
parent deb8414b
......@@ -762,20 +762,33 @@ static void generate_setlimit(struct generator * g, struct node * p) {
struct str * savevar = vars_newname(g);
struct str * varname = vars_newname(g);
write_comment(g, p);
write_savecursor(g, p, savevar);
generate(g, p->left);
if (p->left && p->left->type == c_tomark && !p->left->right) {
/* 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 (FCursor ~S0 "); generate_AE(g, q->AE); w(g, ") Then~N");
write_block_start(g);
write_failure(g);
write_block_end(g);
g->unreachable = false;
if (!g->unreachable) {
g->B[0] = str_data(varname);
write_declare(g, "~B0 : Integer", p);
if (p->mode == m_forward) {
w(g, "~M~B0 := FLimit - FCursor;~N");
w(g, "~MFLimit := FCursor;~N");
w(g, "~MFLimit := ");
} else {
w(g, "~M~B0 := FBkLimit;~N");
w(g, "~MFBkLimit := FCursor;~N");
w(g, "~MFBkLimit := ");
}
write_restorecursor(g, p, savevar);
generate_AE(g, q->AE); writef(g, ";~N", q);
if (p->mode == m_forward) {
str_assign(g->failure_str, "FLimit := FLimit + ");
......@@ -786,6 +799,35 @@ static void generate_setlimit(struct generator * g, struct node * p) {
str_append(g->failure_str, varname);
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);
write_declare(g, "~B0 : Integer", p);
if (p->mode == m_forward) {
w(g, "~M~B0 := FLimit - FCursor;~N");
w(g, "~MFLimit := FCursor;~N");
} else {
w(g, "~M~B0 := FBkLimit;~N");
w(g, "~MFBkLimit := FCursor;~N");
}
write_restorecursor(g, p, savevar);
if (p->mode == m_forward) {
str_assign(g->failure_str, "FLimit := FLimit + ");
str_append(g->failure_str, varname);
str_append_ch(g->failure_str, ';');
} else {
str_assign(g->failure_str, "FBkLimit := ");
str_append(g->failure_str, varname);
str_append_ch(g->failure_str, ';');
}
}
}
if (!g->unreachable) {
generate(g, p->aux);
if (!g->unreachable) {
......@@ -794,6 +836,7 @@ static void generate_setlimit(struct generator * g, struct node * p) {
write_newline(g);
}
}
str_delete(varname);
str_delete(savevar);
}
......
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