Improve country() by using "static const" for lookup table (makes function 25% smaller)

and const-correctness.  Add .mobi TLD.


git-svn-id: svn://svn.code.sf.net/p/bitchx/code/trunk@112 13b04d17-f746-0410-82c6-800466cd88b0
This commit is contained in:
Kevin Easton
2011-03-23 11:17:23 +00:00
parent 94550b1fac
commit b17b09949b
4 changed files with 9 additions and 8 deletions

View File

@@ -1,5 +1,7 @@
[Changes 1.2c01] [Changes 1.2c01]
* Improve country() and add .mobi TLD. (caf)
* Apply fixes from darkfires removing non-standard use of arithmetic on * Apply fixes from darkfires removing non-standard use of arithmetic on
void * values, to allow building on Irix. (caf) void * values, to allow building on Irix. (caf)

View File

@@ -118,7 +118,7 @@ ChannelList * BX_prepare_command (int *, char *, int);
int timer_unban (void *, char *); int timer_unban (void *, char *);
void check_server_connect (int); void check_server_connect (int);
char *country(char *); const char *country(char *);
int do_newuser (char *, char *, char *); int do_newuser (char *, char *, char *);
int char_fucknut (register unsigned char *, char, int); int char_fucknut (register unsigned char *, char, int);
BanList *ban_is_on_channel(register char *, register ChannelList *); BanList *ban_is_on_channel(register char *, register ChannelList *);

View File

@@ -5487,7 +5487,6 @@ BUILT_IN_FUNCTION(function_irclib, input)
BUILT_IN_FUNCTION(function_country, input) BUILT_IN_FUNCTION(function_country, input)
{ {
extern char *country(char *);
RETURN_STR(country(input)); RETURN_STR(country(input));
} }

View File

@@ -4902,14 +4902,13 @@ void check_server_connect(int server)
#endif #endif
} }
char *country(char *hostname) const char *country(char *hostname)
{ {
#ifndef BITCHX_LITE #ifndef BITCHX_LITE
typedef struct _domain { static const struct {
char *code; const char *code;
char *country; const char *country;
} Domain; } domain[] = {
Domain domain[] = {
{"AC", "Ascension Island" }, {"AC", "Ascension Island" },
{"AD", "Andorra" }, {"AD", "Andorra" },
{"AE", "United Arab Emirates" }, {"AE", "United Arab Emirates" },
@@ -5166,6 +5165,7 @@ Domain domain[] = {
{"INFO", "Informational" }, {"INFO", "Informational" },
{"INT", "International" }, {"INT", "International" },
{"MIL", "United States Military" }, {"MIL", "United States Military" },
{"MOBI", "Mobile Device" },
{"MUSEUM", "Museum" }, {"MUSEUM", "Museum" },
{"NET", "Network" }, {"NET", "Network" },
{"NAME", "Individuals" }, {"NAME", "Individuals" },