Optimize the ip2long function with trim logic applied

This commit is contained in:
lionsoul 2018-10-07 10:23:17 +08:00
parent 835d9c1b90
commit d796a76400
2 changed files with 28 additions and 23 deletions

View File

@ -396,6 +396,11 @@ IP2R_API uint_t ip2long(const char *ip)
uint_t ipval = 0; uint_t ipval = 0;
while ( *cs != '\0' ) { while ( *cs != '\0' ) {
if ( *cs == ' ' ) {
cs++;
continue;
}
if ( *cs == '.' ) { if ( *cs == '.' ) {
//single part length limit //single part length limit
if ( i > 3 ) { if ( i > 3 ) {

View File

@ -49,7 +49,7 @@ int main( int argc, char **argv )
datablock_entry datablock; datablock_entry datablock;
char *dbFile = NULL, *algorithm = NULL; char *dbFile = NULL, *algorithm = NULL;
char line[256]; char line[256];
uint_t (*func_ptr)(ip2region_t, char *, datablock_t); uint_t (*func_ptr)(ip2region_t, const char *, datablock_t);
double s_time, c_time; double s_time, c_time;
memset(&datablock, 0x00, sizeof(datablock_entry)); memset(&datablock, 0x00, sizeof(datablock_entry));
@ -95,7 +95,7 @@ int main( int argc, char **argv )
printf("%d|%s in %.5f millseconds\n", datablock.city_id, datablock.region, c_time); printf("%d|%s in %.5f millseconds\n", datablock.city_id, datablock.region, c_time);
} }
//destory the ip2rObj // destory the ip2rObj
ip2region_destroy(&ip2rEntry); ip2region_destroy(&ip2rEntry);
return 0; return 0;