Issue information

Issue ID
#6769
Status
Invalid
Severity
None
Started
Hercules Elf Bot
Oct 8, 2012 2:34
Last Post
Hercules Elf Bot
Nov 8, 2012 23:39
Confirmation
Yes (1)
No (0)

Hercules Elf Bot - Oct 8, 2012 2:34

Originally posted by [b]mkbu95[/b]
I sent a pm a few weeks ago to Ind about some >possible< tweaks.

So, in date.c only 4 out of 9 functions are being used.
In the following functions: date_get_year, date_get_month, date_get_hour, date_get_min, date_get_sec, the only one which it is used is date_get_day to later be called from is_day_of_sun, is_day_of_moon, is_day_of_star which will be called on other files.
My suggestion is that the functions that are not in use to be removed. Otherwise a macro could be done, I made a simple one (I didn't test <don't blame me yet>).
[spoiler][code]#define date_get_sub(tm_element) { \
time_t t; \
struct tm* lt; \
t = time(NULL); \
lt = localtime(&t); \
return lt->tm_element; \
}

int date_get_year(void) {
date_get_sub(tm_year + 1900);
}

int date_get_month(void) {
date_get_sub(tm_mon + 1);
}

int date_get_day(void) {
date_get_sub(tm_mday);
}

int date_get_hour(void) {
date_get_sub(tm_hour);
}

int date_get_min(void) {
date_get_sub(tm_min);
}

int date_get_sec(void) {
date_get_sub(tm_sec);
}[/code][/spoiler]

Also, it reminded me about Show* functions. And another macro was born:
[spoiler][code]#define ShowSub(msg_const) { \
int ret; \
va_list ap; \
va_start(ap, string); \
ret = _vShowMessage(msg_const, string, ap); \
va_end(ap); \
return ret; \
}

int ShowMessage(const char *string, ...) {
ShowSub(MSG_NONE);
}

int ShowStatus(const char *string, ...) {
ShowSub(MSG_STATUS);
}

int ShowSQL(const char *string, ...) {
ShowSub(MSG_SQL);
}

int ShowInfo(const char *string, ...) {
ShowSub(MSG_INFORMATION);
}

int ShowNotice(const char *string, ...) {
ShowSub(MSG_NOTICE);
}

int ShowWarning(const char *string, ...) {
ShowSub(MSG_WARNING);
}

int ShowDebug(const char *string, ...) {
ShowSub(MSG_DEBUG);
}

int ShowError(const char *string, ...) {
ShowSub(MSG_ERROR);
}

int ShowFatalError(const char *string, ...) {
ShowSub(MSG_FATALERROR);
}[/code][/spoiler]

Now, I don't know if the usage of macros is a good programming practice, it's up to you to decide if this is a good thing that I suggested.

And do you guys think that it would be worth using the restrict keyword, since pointers are everywhere in the code, and I just thought that it could help optimize it.
Example:[spoiler][code]int merc_hom_change_name(struct map_session_data *sd, char *restrict name) <-----
{
int i;
struct homun_data *hd;
nullpo_retr(1, sd);

hd = sd->hd;
if (!merc_is_hom_active(hd))
return 1;
if(hd->homunculus.rename_flag && !battle_config.hom_rename)
return 1;

for(i=0;i<NAME_LENGTH && name[i];i++){ <---
if( !(name[i]&0xe0) || name[i]==0x7f) <---
return 1;
}

return intif_rename_hom(sd, name); <---
}[/code][/spoiler]

Thanks.

Hercules Elf Bot - Nov 6, 2012 12:51

Originally posted by [b]mkbu95[/b]
Please, close. I've moved this to Source Discussion, where it belongs /ok