more string concatenation speed-up.

This commit is contained in:
Enno Rehling 2005-05-05 00:12:54 +00:00
parent 5aaf6bfed5
commit ec3ad436d8
1 changed files with 135 additions and 143 deletions

View File

@ -108,6 +108,13 @@ int *month_season;
char *agename; char *agename;
int seasons; int seasons;
static size_t
strlcpy(char * dst, const char * src) {
size_t s = 0;
while ((*dst++ = *src++)!=0) ++s;
return s;
}
static const char* static const char*
MailitPath(void) MailitPath(void)
{ {
@ -457,6 +464,7 @@ report_spell(FILE * F, spellid_t id, const struct locale * lang)
resource_t res; resource_t res;
int dh = 0; int dh = 0;
spell *sp = find_spellbyid(id); spell *sp = find_spellbyid(id);
char * bufp;
rnl(F); rnl(F);
centre(F, spell_name(sp, lang), true); centre(F, spell_name(sp, lang), true);
@ -467,15 +475,15 @@ report_spell(FILE * F, spellid_t id, const struct locale * lang)
rnl(F); rnl(F);
strcpy(buf, "Art: "); bufp = strcpy(buf, "Art: ");
if (sp->sptyp & PRECOMBATSPELL) { if (sp->sptyp & PRECOMBATSPELL) {
scat("Präkampfzauber"); bufp += strlcpy(bufp, "Präkampfzauber");
} else if (sp->sptyp & COMBATSPELL) { } else if (sp->sptyp & COMBATSPELL) {
scat("Kampfzauber"); bufp += strlcpy(bufp, "Kampfzauber");
} else if (sp->sptyp & POSTCOMBATSPELL) { } else if (sp->sptyp & POSTCOMBATSPELL) {
scat("Postkampfzauber"); bufp += strlcpy(bufp, "Postkampfzauber");
} else { } else {
scat("Normaler Zauber"); bufp += strlcpy(bufp, "Normaler Zauber");
} }
rps(F, buf); rps(F, buf);
@ -487,9 +495,9 @@ report_spell(FILE * F, spellid_t id, const struct locale * lang)
costtyp = sp->komponenten[k][2]; costtyp = sp->komponenten[k][2];
if(itemanz > 0){ if(itemanz > 0){
if (sp->sptyp & SPELLLEVEL) { if (sp->sptyp & SPELLLEVEL) {
sprintf(buf, " %d %s", itemanz, LOC(lang, resname(res, itemanz!=1))); bufp = buf + sprintf(buf, " %d %s", itemanz, LOC(lang, resname(res, itemanz!=1)));
if (costtyp == SPC_LEVEL || costtyp == SPC_LINEAR ) { if (costtyp == SPC_LEVEL || costtyp == SPC_LINEAR ) {
scat(" * Stufe"); bufp += strlcpy(bufp, " * Stufe");
} }
} else { } else {
if (costtyp == SPC_LEVEL || costtyp == SPC_LINEAR ) { if (costtyp == SPC_LEVEL || costtyp == SPC_LINEAR ) {
@ -501,35 +509,35 @@ report_spell(FILE * F, spellid_t id, const struct locale * lang)
} }
} }
strcpy(buf, "Modifikationen: "); bufp = buf + strlcpy(buf, "Modifikationen: ");
if (sp->sptyp & FARCASTING) { if (sp->sptyp & FARCASTING) {
scat("Fernzauber"); bufp += strlcpy(bufp, "Fernzauber");
dh = 1; dh = 1;
} }
if (sp->sptyp & OCEANCASTABLE) { if (sp->sptyp & OCEANCASTABLE) {
if (dh == 1){ if (dh == 1){
scat(", "); bufp += strlcpy(bufp, ", ");
} }
scat("Seezauber"); bufp += strlcpy(bufp, "Seezauber");
dh = 1; dh = 1;
} }
if (sp->sptyp & ONSHIPCAST) { if (sp->sptyp & ONSHIPCAST) {
if (dh == 1){ if (dh == 1){
scat(", "); bufp += strlcpy(bufp, ", ");
} }
scat("Schiffszauber"); bufp += strlcpy(bufp, "Schiffszauber");
dh = 1; dh = 1;
} }
if (sp->sptyp & NOTFAMILIARCAST) { if (sp->sptyp & NOTFAMILIARCAST) {
if (dh == 1){ if (dh == 1){
scat(", k"); bufp += strlcpy(bufp, ", k");
} else { } else {
scat("K"); bufp += strlcpy(bufp, "K");
} }
scat("ann nicht vom Vertrauten gezaubert werden"); bufp += strlcpy(bufp, "ann nicht vom Vertrauten gezaubert werden");
dh = 1; dh = 1;
} }
if(dh == 0) scat("Keine"); if(dh == 0) bufp += strlcpy(bufp, "Keine");
rps(F, buf); rps(F, buf);
@ -538,48 +546,48 @@ report_spell(FILE * F, spellid_t id, const struct locale * lang)
sprintf(buf, "Rang: %d", sp->rank); sprintf(buf, "Rang: %d", sp->rank);
rps(F, buf); rps(F, buf);
rnl(F); rnl(F);
strcpy(buf, "Syntax: "); strcpy(buf, "Syntax: ");
rps(F, buf); rps(F, buf);
if(!sp->syntax){
if(sp->sptyp & ISCOMBATSPELL){ if (!sp->syntax) {
strcpy(buf, "KAMPFZAUBER "); if (sp->sptyp & ISCOMBATSPELL) {
}else{ bufp = buf + strlcpy(buf, "KAMPFZAUBER ");
strcpy(buf, "ZAUBERE "); } else {
bufp = buf + strlcpy(buf, "ZAUBERE ");
} }
/* Reihenfolge beachten: Erst REGION, dann STUFE! */ /* Reihenfolge beachten: Erst REGION, dann STUFE! */
if (sp->sptyp & FARCASTING) { if (sp->sptyp & FARCASTING) {
scat("[REGION x y] "); bufp += strlcpy(bufp, "[REGION x y] ");
} }
if (sp->sptyp & SPELLLEVEL) { if (sp->sptyp & SPELLLEVEL) {
scat("[STUFE n] "); bufp += strlcpy(bufp, "[STUFE n] ");
} }
scat("\""); bufp += strlcpy(bufp, "\"");
scat(spell_name(sp, lang)); bufp += strlcpy(bufp, spell_name(sp, lang));
scat("\" "); bufp += strlcpy(bufp, "\" ");
if (sp->sptyp & ONETARGET){ if (sp->sptyp & ONETARGET){
if (sp->sptyp & UNITSPELL) { if (sp->sptyp & UNITSPELL) {
scat("<Einheit-Nr>"); bufp += strlcpy(bufp, "<Einheit-Nr>");
} else if (sp->sptyp & SHIPSPELL) { } else if (sp->sptyp & SHIPSPELL) {
scat("<Schiff-Nr>"); bufp += strlcpy(bufp, "<Schiff-Nr>");
} else if (sp->sptyp & BUILDINGSPELL) { } else if (sp->sptyp & BUILDINGSPELL) {
scat("<Gebäude-Nr>"); bufp += strlcpy(bufp, "<Gebäude-Nr>");
} }
}else { } else {
if (sp->sptyp & UNITSPELL) { if (sp->sptyp & UNITSPELL) {
scat("<Einheit-Nr> [<Einheit-Nr> ...]"); bufp += strlcpy(bufp, "<Einheit-Nr> [<Einheit-Nr> ...]");
} else if (sp->sptyp & SHIPSPELL) { } else if (sp->sptyp & SHIPSPELL) {
scat("<Schiff-Nr> [<Schiff-Nr> ...]"); bufp += strlcpy(bufp, "<Schiff-Nr> [<Schiff-Nr> ...]");
} else if (sp->sptyp & BUILDINGSPELL) { } else if (sp->sptyp & BUILDINGSPELL) {
scat("<Gebäude-Nr> [<Gebäude-Nr> ...]"); bufp += strlcpy(bufp, "<Gebäude-Nr> [<Gebäude-Nr> ...]");
} }
} }
}else{ } else {
strcpy(buf, sp->syntax); bufp += strlcpy(bufp, sp->syntax);
} }
rps(F, buf); rps(F, buf);
rnl(F); rnl(F);
} }
@ -986,27 +994,29 @@ prices(FILE * F, const region * r, const faction * f)
nr_render(m, f->locale, buf, sizeof(buf), f); nr_render(m, f->locale, buf, sizeof(buf), f);
msg_release(m); msg_release(m);
if(n > 0) { if (n > 0) {
scat(" "); char * bufp = buf + strlen(buf);
scat(LOC(f->locale, "nr_trade_intro")); bufp += strlcpy(bufp, " ");
scat(" "); bufp += strlcpy(bufp, LOC(f->locale, "nr_trade_intro"));
bufp += strlcpy(bufp, " ");
for (dmd=r->land->demands;dmd;dmd=dmd->next) if(dmd->value > 0) { for (dmd=r->land->demands;dmd;dmd=dmd->next) if(dmd->value > 0) {
char sbuf[80];
m = msg_message("nr_market_price", "product price", m = msg_message("nr_market_price", "product price",
dmd->type->itype->rtype, dmd->value * dmd->type->price); dmd->type->itype->rtype, dmd->value * dmd->type->price);
nr_render(m, f->locale, sbuf, sizeof(sbuf), f); nr_render(m, f->locale, bufp, sizeof(buf)-(bufp-buf), f);
msg_release(m); msg_release(m);
scat(sbuf);
n--; n--;
if (n == 0) scat(LOC(f->locale, "nr_trade_end")); bufp += strlen(bufp);
if (n == 0) {
bufp += strlcpy(bufp, LOC(f->locale, "nr_trade_end"));
}
else if (n == 1) { else if (n == 1) {
scat(" "); strcpy(bufp++, " ");
scat(LOC(f->locale, "nr_trade_final")); bufp += strlcpy(bufp, LOC(f->locale, "nr_trade_final"));
scat(" "); strcpy(bufp++, " ");
} else { } else {
scat(LOC(f->locale, "nr_trade_next")); bufp += strlcpy(bufp, LOC(f->locale, "nr_trade_next"));
scat(" "); strcpy(bufp++, " ");
} }
} }
} }
@ -1074,7 +1084,6 @@ eval_trail(struct opstack ** stack, const void * userdata) /* (int, int) -> int
static void static void
describe(FILE * F, const region * r, int partial, faction * f) describe(FILE * F, const region * r, int partial, faction * f)
{ {
char dbuf[512];
int n; int n;
boolean dh; boolean dh;
direction_t d; direction_t d;
@ -1093,9 +1102,10 @@ describe(FILE * F, const region * r, int partial, faction * f)
direction_t lastd; direction_t lastd;
} * edges = NULL, * e; } * edges = NULL, * e;
boolean see[MAXDIRECTIONS]; boolean see[MAXDIRECTIONS];
char * bufp = buf;
for (d = 0; d != MAXDIRECTIONS; d++) for (d = 0; d != MAXDIRECTIONS; d++) {
{ /* Nachbarregionen, die gesehen werden, ermitteln */ /* Nachbarregionen, die gesehen werden, ermitteln */
region *r2 = rconnect(r, d); region *r2 = rconnect(r, d);
border *b; border *b;
see[d] = true; see[d] = true;
@ -1124,27 +1134,27 @@ describe(FILE * F, const region * r, int partial, faction * f)
} }
} }
strcpy(buf, f_regionid(r, f)); bufp += strlcpy(bufp, f_regionid(r, f));
if (partial == 1) { if (partial == 1) {
scat(" (durchgereist)"); bufp += strlcpy(bufp, " (durchgereist)");
} }
else if (partial == 3) { else if (partial == 3) {
scat(" (benachbart)"); bufp += strlcpy(bufp, " (benachbart)");
} }
else if (partial == 2) { else if (partial == 2) {
scat(" (vom Turm erblickt)"); bufp += strlcpy(bufp, " (vom Turm erblickt)");
} }
/* Terrain */ /* Terrain */
scat(", "); bufp += strlcpy(bufp, ", ");
if(is_cursed(r->attribs,C_MAELSTROM, 0)) if(is_cursed(r->attribs,C_MAELSTROM, 0))
tname = "maelstrom"; tname = "maelstrom";
else { else {
if (r_isforest(r)) tname = "forest"; if (r_isforest(r)) tname = "forest";
else tname = terrain[rterrain(r)].name; else tname = terrain[rterrain(r)].name;
} }
scat(LOC(f->locale, tname)); bufp += strlcpy(bufp, LOC(f->locale, tname));
/* Bäume */ /* Bäume */
@ -1152,40 +1162,34 @@ describe(FILE * F, const region * r, int partial, faction * f)
trees = rtrees(r,2); trees = rtrees(r,2);
ytrees = rtrees(r,1); ytrees = rtrees(r,1);
if (production(r)) { if (production(r)) {
if(trees > 0 || ytrees > 0) { if (trees > 0 || ytrees > 0) {
scat(", "); bufp += sprintf(bufp, ", %d/%d", trees, ytrees);
icat(trees);
scat("/");
icat(ytrees);
scat(" ");
if (fval(r, RF_MALLORN)) { if (fval(r, RF_MALLORN)) {
if (trees == 1) if (trees == 1)
scat(LOC(f->locale, "nr_mallorntree")); bufp += strlcpy(bufp, LOC(f->locale, "nr_mallorntree"));
else else
scat(LOC(f->locale, "nr_mallorntree_p")); bufp += strlcpy(bufp, LOC(f->locale, "nr_mallorntree_p"));
} }
else if (trees == 1) else if (trees == 1)
scat(LOC(f->locale, "nr_tree")); bufp += strlcpy(bufp, LOC(f->locale, "nr_tree"));
else else
scat(LOC(f->locale, "nr_tree_p")); bufp += strlcpy(bufp, LOC(f->locale, "nr_tree_p"));
} }
} }
#else #else
trees = rtrees(r); trees = rtrees(r);
if (production(r) && trees > 0) { if (production(r) && trees > 0) {
scat(", "); bufp += sprintf(bufp, ", %d ", trees);
icat(trees);
scat(" ");
if (fval(r, RF_MALLORN)) { if (fval(r, RF_MALLORN)) {
if (trees == 1) if (trees == 1)
scat(LOC(f->locale, "nr_mallorntree")); bufp += strlcpy(bufp, LOC(f->locale, "nr_mallorntree"));
else else
scat(LOC(f->locale, "nr_mallorntree_p")); bufp += strlcpy(bufp, LOC(f->locale, "nr_mallorntree_p"));
} }
else if (trees == 1) else if (trees == 1)
scat(LOC(f->locale, "nr_tree")); bufp += strlcpy(bufp, LOC(f->locale, "nr_tree"));
else else
scat(LOC(f->locale, "nr_tree_p")); bufp += strlcpy(bufp, LOC(f->locale, "nr_tree_p"));
} }
#endif #endif
@ -1217,9 +1221,9 @@ describe(FILE * F, const region * r, int partial, faction * f)
} }
} }
if (level>=0 && visible >= 0) { if (level>=0 && visible >= 0) {
char * pos = buf+strlen(buf); bufp += snprintf(bufp, sizeof(buf)-(bufp-buf), ", %d %s/%d",
snprintf(pos, sizeof(buf)-(pos-buf), ", %d %s/%d", visible, LOC(f->locale, res->type->name),
visible, LOC(f->locale, res->type->name), res->level + itype->construction->minskill - 1); res->level + itype->construction->minskill - 1);
} }
} }
#else #else
@ -1233,75 +1237,66 @@ describe(FILE * F, const region * r, int partial, faction * f)
} }
} }
if (riron(r) > 0 && maxmining >= 4) { if (riron(r) > 0 && maxmining >= 4) {
scat(", "); bufp += sprinf(bufp, ", %d Eisen", riron(r));
icat(riron(r));
scat(" Eisen");
} }
if (rlaen(r)>=0 && maxmining >= 7) { if (rlaen(r)>=0 && maxmining >= 7) {
scat(", "); bufp += sprintf(bufp, ", %d Laen", rlaen(r));
icat(rlaen(r));
scat(" Laen");
} }
#endif #endif
} }
/* peasants & silver */ /* peasants & silver */
if (rpeasants(r)) { if (rpeasants(r)) {
scat(", "); bufp += sprintf(bufp, ", %d", rpeasants(r));
icat(rpeasants(r));
if(fval(r, RF_ORCIFIED)) { if(fval(r, RF_ORCIFIED)) {
scat(" "); strcpy(bufp++, " ");
scat(LOC(f->locale, rpeasants(r)==1?"rc_orc":"rc_orc_p")); bufp += strlcpy(bufp, LOC(f->locale, rpeasants(r)==1?"rc_orc":"rc_orc_p"));
} else { } else {
scat(" "); strcpy(bufp++, " ");
scat(LOC(f->locale, resourcename(oldresourcetype[R_PEASANTS], rpeasants(r)!=1))); bufp += strlcpy(bufp, LOC(f->locale, resourcename(oldresourcetype[R_PEASANTS], rpeasants(r)!=1)));
} }
if (rmoney(r) && partial == 0) { if (rmoney(r) && partial == 0) {
scat(", "); bufp += sprintf(bufp, ", %d ", rmoney(r));
icat(rmoney(r)); bufp += strlcpy(bufp, LOC(f->locale, resourcename(oldresourcetype[R_SILVER], rmoney(r)!=1)));
scat(" ");
scat(LOC(f->locale, resourcename(oldresourcetype[R_SILVER], rmoney(r)!=1)));
} }
} }
/* Pferde */ /* Pferde */
if (rhorses(r)) { if (rhorses(r)) {
scat(", "); bufp += sprintf(bufp, ", %d ", rhorses(r));
icat(rhorses(r));
scat(" ");
#ifdef NEW_ITEMS #ifdef NEW_ITEMS
scat(LOC(f->locale, resourcename(oldresourcetype[R_HORSE], (rhorses(r)>1)?GR_PLURAL:0))); bufp += strlcpy(bufp, LOC(f->locale, resourcename(oldresourcetype[R_HORSE], (rhorses(r)>1)?GR_PLURAL:0)));
#else #else
scat(itemdata[I_HORSE].name[rhorses(r) > 1]); bufp += strlcpy(bufp, itemdata[I_HORSE].name[rhorses(r) > 1]);
#endif #endif
} }
scat("."); strcpy(bufp++, ".");
if (r->display && r->display[0]) { if (r->display && r->display[0]) {
scat(" "); strcpy(bufp++, " ");
scat(r->display); bufp += strlcpy(bufp, r->display);
n = r->display[strlen(r->display) - 1]; n = r->display[strlen(r->display) - 1];
if (n != '!' && n != '?' && n != '.') if (n != '!' && n != '?' && n != '.')
scat("."); strcpy(bufp++, ".");
} }
{ {
const unit * u = region_owner(r); const unit * u = region_owner(r);
if (u) { if (u) {
scat(" Die Region ist im Besitz von "); bufp += strlcpy(bufp, " Die Region ist im Besitz von ");
scat(factionname(u->faction)); bufp += strlcpy(bufp, factionname(u->faction));
scat("."); strcpy(bufp++, ".");
} }
} }
if (!is_cursed(r->attribs, C_REGCONF, 0)) { if (!is_cursed(r->attribs, C_REGCONF, 0)) {
attrib *a_do = a_find(r->attribs, &at_overrideroads); attrib *a_do = a_find(r->attribs, &at_overrideroads);
if(a_do) { if(a_do) {
scat(" "); strcpy(bufp++, " ");
scat((char *)a_do->data.v); bufp += strlcpy(bufp, (char *)a_do->data.v);
} else { } else {
int nrd = 0; int nrd = 0;
@ -1318,44 +1313,40 @@ describe(FILE * F, const region * r, int partial, faction * f)
nrd--; nrd--;
if (dh) { if (dh) {
if (nrd == 0) { if (nrd == 0) {
scat(" "); strcpy(bufp++, " ");
scat(LOC(f->locale, "nr_nb_final")); bufp += strlcpy(bufp, LOC(f->locale, "nr_nb_final"));
} else { } else {
scat(LOC(f->locale, "nr_nb_next")); bufp += strlcpy(bufp, LOC(f->locale, "nr_nb_next"));
} }
scat(LOC(f->locale, directions[d])); bufp += strlcpy(bufp, LOC(f->locale, directions[d]));
scat(" "); strcpy(bufp++, " ");
sprintf(dbuf, trailinto(r2, f->locale), bufp += sprintf(bufp, trailinto(r2, f->locale),
f_regionid(r2, f)); f_regionid(r2, f));
scat(dbuf);
} }
else { else {
scat(" "); strcpy(bufp++, " ");
MSG(("nr_vicinitystart", "dir region", d, r2), dbuf, sizeof(dbuf), f->locale, f); MSG(("nr_vicinitystart", "dir region", d, r2), bufp, sizeof(buf)-(bufp-buf), f->locale, f);
scat(dbuf);
dh = true; dh = true;
} }
} }
/* Spezielle Richtungen */ /* Spezielle Richtungen */
for (a = a_find(r->attribs, &at_direction);a;a = a->nexttype) { for (a = a_find(r->attribs, &at_direction);a;a = a->nexttype) {
spec_direction * d = (spec_direction *)(a->data.v); spec_direction * d = (spec_direction *)(a->data.v);
scat(" "); strcpy(bufp++, " ");
scat(d->desc); bufp += strlcpy(bufp, d->desc);
scat(" (\""); bufp += strlcpy(bufp, " (\"");
scat(d->keyword); bufp += strlcpy(bufp, d->keyword);
scat("\")"); bufp += strlcpy(bufp, "\")");
scat("."); strcpy(bufp++, ".");
dh = 1; dh = 1;
} }
if (dh) scat("."); if (dh) strcpy(bufp++, ".");
} }
rnl(F);
rparagraph(F, buf, 0, 0);
} else { } else {
scat(" Große Verwirrung befällt alle Reisenden in dieser Region."); bufp += strlcpy(bufp, " Große Verwirrung befällt alle Reisenden in dieser Region.");
}
rnl(F); rnl(F);
rparagraph(F, buf, 0, 0); rparagraph(F, buf, 0, 0);
}
if (partial==0 && rplane(r) == get_astralplane() && if (partial==0 && rplane(r) == get_astralplane() &&
!is_cursed(r->attribs, C_ASTRALBLOCK, 0)) { !is_cursed(r->attribs, C_ASTRALBLOCK, 0)) {
@ -1395,20 +1386,21 @@ describe(FILE * F, const region * r, int partial, faction * f)
for (e=edges;e;e=e->next) { for (e=edges;e;e=e->next) {
boolean first = true; boolean first = true;
for (d=0;d!=MAXDIRECTIONS;++d) { for (d=0;d!=MAXDIRECTIONS;++d) {
char * bufp = buf;
if (!e->exist[d]) continue; if (!e->exist[d]) continue;
if (first) strcpy(buf, "Im "); if (first) bufp += strlcpy(bufp, "Im ");
else { else {
if (e->lastd==d) strcat(buf, " und im "); if (e->lastd==d) bufp += strlcpy(bufp, " und im ");
else strcat(buf, ", im "); else bufp += strlcpy(bufp, ", im ");
} }
strcat(buf, LOC(f->locale, directions[d])); bufp += strlcpy(bufp, LOC(f->locale, directions[d]));
first = false; first = false;
} }
if (!e->transparent) strcat(buf, " versperrt "); if (!e->transparent) bufp += strlcpy(bufp, " versperrt ");
else strcat(buf, " befindet sich "); else bufp += strlcpy(bufp, " befindet sich ");
strcat(buf, e->name); bufp += strlcpy(bufp, e->name);
if (!e->transparent) strcat(buf, " die Sicht."); if (!e->transparent) bufp += strlcpy(bufp, " die Sicht.");
else strcat(buf, "."); else strcpy(bufp++, ".");
rparagraph(F, buf, 0, 0); rparagraph(F, buf, 0, 0);
} }
if (edges) { if (edges) {