summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorskotlex <skotlex@54d463be-8e91-2dee-dedb-b68131a5f0ec>2007-01-24 15:11:42 +0000
committerskotlex <skotlex@54d463be-8e91-2dee-dedb-b68131a5f0ec>2007-01-24 15:11:42 +0000
commite7466e5e46805c4e859d923c7a9ed7877fd59eda (patch)
tree666b8b365a12cbd30bb309d7f613e9cbd929bde5 /src
parent765e2ceaac15587cb25e776234214687d7b36e1b (diff)
downloadhercules-e7466e5e46805c4e859d923c7a9ed7877fd59eda.tar.gz
hercules-e7466e5e46805c4e859d923c7a9ed7877fd59eda.tar.bz2
hercules-e7466e5e46805c4e859d923c7a9ed7877fd59eda.tar.xz
hercules-e7466e5e46805c4e859d923c7a9ed7877fd59eda.zip
- 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://rathena.svn.sourceforge.net/svnroot/rathena/trunk@9706 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src')
-rw-r--r--src/map/script.c44
1 files changed, 23 insertions, 21 deletions
diff --git a/src/map/script.c b/src/map/script.c
index 03ff19973..7abbe83df 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -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 {