1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-07-30 19:03:16 +03:00

Do not sort terminal symbols by name. The terminals remain in the same order

that they are encountered in the grammar file.  This results in parse tables
that are 25% smaller. (CVS 1261)

FossilOrigin-Name: f36b122d9767fa9e6dc5bcce04b5606d67cad3d9
This commit is contained in:
drh
2004-02-22 00:08:04 +00:00
parent b621c23775
commit 60d316542f
3 changed files with 22 additions and 13 deletions

View File

@ -1387,6 +1387,7 @@ char **argv;
lem.nsymbol = Symbol_count();
Symbol_new("{default}");
lem.symbols = Symbol_arrayof();
for(i=0; i<=lem.nsymbol; i++) lem.symbols[i]->index = i;
qsort(lem.symbols,lem.nsymbol+1,sizeof(struct symbol*),
(int(*)())Symbolcmpp);
for(i=0; i<=lem.nsymbol; i++) lem.symbols[i]->index = i;
@ -3886,12 +3887,20 @@ char *x;
return sp;
}
/* Compare two symbols */
int Symbolcmpp(a,b)
struct symbol **a;
struct symbol **b;
{
return strcmp((**a).name,(**b).name);
/* Compare two symbols for working purposes
**
** Symbols that begin with upper case letters (terminals or tokens)
** must sort before symbols that begin with lower case letters
** (non-terminals). Other than that, the order does not matter.
**
** We find experimentally that leaving the symbols in their original
** order (the order they appeared in the grammar file) gives the
** smallest parser tables in SQLite.
*/
int Symbolcmpp(struct symbol **a, struct symbol **b){
int i1 = (**a).index + 10000000*((**a).name[0]>'Z');
int i2 = (**b).index + 10000000*((**b).name[0]>'Z');
return i1-i2;
}
/* There is one instance of the following structure for each