Line concatenation: use dstring instead of tprintf:

Parsing time of Skywater libs reduced by more than 35%.
This commit is contained in:
Holger Vogt 2023-04-22 14:55:23 +02:00
parent f5279c0ef5
commit 5bd0346b64
1 changed files with 67 additions and 71 deletions

View File

@ -617,14 +617,17 @@ static char *cat2strings(char *s1, char *s2, bool spa)
----> ---->
line1 line2 line1 line2
Proccedure: store regular card in prev, skip comment lines (*..) and some Proccedure: store regular card in prev, skip comment lines (*..) and some
others others, add tokens from + lines to prev using dstring.
*/ */
static void inp_stitch_continuation_lines(struct card* working) static void inp_stitch_continuation_lines(struct card* working)
{ {
struct card* prev = NULL; struct card* prev = NULL;
bool firsttime = TRUE;
DS_CREATE(newline, 200);
while (working) { while (working) {
char *s, c, *buffer; char* s, c;
for (s = working->line; (c = *s) != '\0' && c <= ' '; s++) for (s = working->line; (c = *s) != '\0' && c <= ' '; s++)
; ;
@ -663,50 +666,43 @@ static void inp_stitch_continuation_lines(struct card *working)
prev->nextcard = tmpl; prev->nextcard = tmpl;
} }
/* create buffer and write last and current line into it. if (firsttime) {
When reading a PDK, the following may be called more than 1e6 times. */ sadd(&newline, prev->line);
#if defined (_MSC_VER) firsttime = FALSE;
/* vsnprintf (used by tprintf) in Windows is efficient, VS2019 arb. referencevalue 7,
cat2strings() yields ref. speed value 12 only, CYGWIN is 12 in both cases,
MINGW is 36. */
buffer = tprintf("%s %s", prev->line, s + 1);
#else
/* vsnprintf in Linux is very inefficient, ref. value 24
cat2strings() is efficient with ref. speed value 6,
MINGW is 12 */
buffer = cat2strings(prev->line, s + 1, TRUE);
#endif
/* replace prev->line by buffer */
s = prev->line;
prev->line = buffer;
prev->nextcard = working->nextcard;
working->nextcard = NULL;
/* add original line to prev->actualLine */
if (prev->actualLine) {
struct card *end;
for (end = prev->actualLine; end->nextcard;
end = end->nextcard)
;
end->nextcard = working;
tfree(s);
} }
else { else {
prev->actualLine = /* replace '+' by space */
insert_new_line(NULL, s, prev->linenum, 0); *s = ' ';
prev->actualLine->level = prev->level; sadd(&newline, s);
prev->actualLine->nextcard = working; /* mark for later removal */
*s = '*';
} }
working = prev->nextcard;
break; break;
default: /* regular one-line card */ default: /* regular one-line card */
if (!firsttime) {
tfree(prev->line);
prev->line = copy(ds_get_buf(&newline));
ds_clear(&newline);
firsttime = TRUE;
/* remove final used '+' line, if regular line is following */
struct card* tmpl = prev->nextcard->nextcard;
line_free_x(prev->nextcard, FALSE);
prev->nextcard = tmpl;
}
prev = working; prev = working;
working = working->nextcard; working = working->nextcard;
break; break;
} }
} }
/* remove final used '+' line when no regular line is following */
if (!firsttime) {
tfree(prev->line);
prev->line = copy(ds_get_buf(&newline));
}
ds_free(&newline);
} }
/* /*
* search for `=' assignment operator * search for `=' assignment operator