dedup dedup
This commit is contained in:
parent
ab04acdf53
commit
098a36427e
1 changed files with 17 additions and 31 deletions
48
boot.c
48
boot.c
|
@ -286,24 +286,6 @@ int parse_string() {
|
|||
return string_lut_size++;
|
||||
}
|
||||
|
||||
void rewind_string(int new_data) {
|
||||
string_offset = string_lut[token_data];
|
||||
token_data = new_data;
|
||||
--string_lut_size;
|
||||
}
|
||||
|
||||
void dedup_string() {
|
||||
int last_string = string_lut_size - 1;
|
||||
char* latest = string_table + string_lut[last_string];
|
||||
for (int i = 0; i < last_string; i++) {
|
||||
char* candidate = string_table + string_lut[i];
|
||||
if (streq(candidate, latest)) {
|
||||
rewind_string(i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
char id_table[ID_TABLE_SIZE];
|
||||
int id_offset;
|
||||
int id_lut[ID_LUT_SIZE];
|
||||
|
@ -320,24 +302,27 @@ int parse_id(int ch) {
|
|||
return id_lut_size++;
|
||||
}
|
||||
|
||||
void rewind_id(int new_data) {
|
||||
id_offset = id_lut[token_data];
|
||||
token_data = new_data;
|
||||
--id_lut_size;
|
||||
}
|
||||
|
||||
void dedup_id() {
|
||||
int last_id = id_lut_size - 1;
|
||||
char* latest = id_table + id_lut[last_id];
|
||||
for (int i = 0; i < last_id; i++) {
|
||||
char* candidate = id_table + id_lut[i];
|
||||
void dedup(char* table, int* lut, int* lut_size, int* offset) {
|
||||
char* latest = table + lut[*lut_size - 1];
|
||||
for (int i = 0; i < *lut_size - 1; i++) {
|
||||
char* candidate = table + lut[i];
|
||||
if (streq(candidate, latest)) {
|
||||
rewind_id(i);
|
||||
*offset = lut[token_data];
|
||||
--*lut_size;
|
||||
token_data = i;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void dedup_string() {
|
||||
dedup(string_table, string_lut, &string_lut_size, &string_offset);
|
||||
}
|
||||
|
||||
void dedup_id() {
|
||||
dedup(id_table, id_lut, &id_lut_size, &id_offset);
|
||||
}
|
||||
|
||||
void parse_id_like(int ch) {
|
||||
token_type = TOKEN_ID;
|
||||
token_data = parse_id(ch);
|
||||
|
@ -370,7 +355,8 @@ void parse_id_like(int ch) {
|
|||
token_type = TOKEN_ENUM;
|
||||
}
|
||||
if (token_type != TOKEN_ID) {
|
||||
rewind_id(0);
|
||||
id_offset = id_lut[token_data];
|
||||
--id_lut_size;
|
||||
} else {
|
||||
dedup_id();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue