- Improved a bit the menu entries counting code (using a while with strchr should yield better performance that a for done on the string's strlen, right? However, it bugs me that strchr's man-page says it won't work on multi-byte characters. But does a strchr(str,':') works any worse than (str[i]== ':')?

git-svn-id: https://svn.code.sf.net/p/rathena/svn/trunk@9706 54d463be-8e91-2dee-dedb-b68131a5f0ec
This commit is contained in:
skotlex 2007-01-24 15:11:42 +00:00
parent 9342b7e4d5
commit f904054ce8

View File

@ -4371,8 +4371,8 @@ int buildin_close2(struct script_state *st)
*/
int buildin_menu(struct script_state *st)
{
char *buf;
int len,i, max = 1;
char *buf, *ptr;
int len,i;
struct map_session_data *sd = script_rid2sd(st);
nullpo_retr(0, sd);
@ -4399,11 +4399,11 @@ int buildin_menu(struct script_state *st)
strcat(buf,":");
}
}
for(i=0; (unsigned int)i < strlen(buf); i++){
if(buf[i] == ':')
max++;
}
sd->npc_menu = max; //Reuse to store max menu entries. Avoids the need of an extra variable.
ptr = buf;
sd->npc_menu = 0; //Reuse to store max menu entries. Avoids the need of an extra variable.
while (ptr && (ptr = strchr(ptr, ':')) != NULL)
{ sd->npc_menu++; ptr++; }
clif_scriptmenu(sd,st->oid,buf);
aFree(buf);
} else if(sd->npc_menu==0xff){ // cancel
@ -10614,8 +10614,8 @@ int buildin_jump_zero(struct script_state *st) {
int buildin_select(struct script_state *st)
{
char *buf;
int len,i,max = 1;
char *buf, *ptr;
int len,i;
struct map_session_data *sd;
sd=script_rid2sd(st);
@ -10633,11 +10633,12 @@ int buildin_select(struct script_state *st)
strcat(buf,st->stack->stack_data[i].u.str);
strcat(buf,":");
}
for(i=0; (unsigned int)i < strlen(buf); i++){
if(buf[i] == ':')
max++;
}
sd->npc_menu = max; //Reuse to store max menu entries. Avoids the need of an extra variable.
ptr = buf;
sd->npc_menu = 0; //Reuse to store max menu entries. Avoids the need of an extra variable.
while (ptr && (ptr = strchr(ptr, ':')) != NULL)
{ sd->npc_menu++; ptr++; }
clif_scriptmenu(sd,st->oid,buf);
aFree(buf);
} else if(sd->npc_menu==0xff){
@ -10659,8 +10660,8 @@ int buildin_select(struct script_state *st)
int buildin_prompt(struct script_state *st)
{
char *buf;
int len,i,max = 1;
char *buf, *ptr;
int len,i;
struct map_session_data *sd;
sd=script_rid2sd(st);
@ -10679,11 +10680,12 @@ int buildin_prompt(struct script_state *st)
strcat(buf,st->stack->stack_data[i].u.str);
strcat(buf,":");
}
for(i=0; (unsigned int)i < strlen(buf); i++){
if(buf[i] == ':')
max++;
}
sd->npc_menu = max; //Reuse to store max menu entries. Avoids the need of an extra variable.
ptr = buf;
sd->npc_menu = 0; //Reuse to store max menu entries. Avoids the need of an extra variable.
while (ptr && (ptr = strchr(ptr, ':')) != NULL)
{ sd->npc_menu++; ptr++; }
clif_scriptmenu(sd,st->oid,buf);
aFree(buf);
} else {