mirror of
https://github.com/lionsoul2014/ip2region.git
synced 2025-12-08 19:25:22 +00:00
optimized the header block size & fix the may comming leak for c binding
This commit is contained in:
parent
43cdeb8c17
commit
56c83f3895
@ -36,6 +36,8 @@ IP2R_API uint_t ip2region_create(ip2region_t ip2rObj, char *dbFile)
|
||||
ip2rObj->dbHandler = fopen(dbFile, "rb");
|
||||
if ( ip2rObj->dbHandler == NULL )
|
||||
{
|
||||
IP2R_FREE(ip2rObj->HeaderSip);
|
||||
IP2R_FREE(ip2rObj->HeaderPtr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@ -44,7 +44,7 @@ typedef unsigned int uint_t;
|
||||
typedef unsigned long ulong_t;
|
||||
|
||||
#define INDEX_BLOCK_LENGTH 12
|
||||
#define TOTAL_HEADER_LENGTH 8192
|
||||
#define TOTAL_HEADER_LENGTH 4096
|
||||
|
||||
/*
|
||||
* ip2region properties struct
|
||||
|
||||
@ -91,7 +91,8 @@ public class DbSearcher
|
||||
if ( HeaderSip == null )
|
||||
{
|
||||
raf.seek(8L); //pass the super block
|
||||
byte[] b = new byte[dbConfig.getTotalHeaderSize()];
|
||||
//byte[] b = new byte[dbConfig.getTotalHeaderSize()];
|
||||
byte[] b = new byte[4096];
|
||||
raf.readFully(b, 0, b.length);
|
||||
|
||||
//fill the header
|
||||
@ -290,6 +291,16 @@ public class DbSearcher
|
||||
{
|
||||
return binarySearch(Util.ip2long(ip));
|
||||
}
|
||||
|
||||
/**
|
||||
* get the db config
|
||||
*
|
||||
* @return DbConfig
|
||||
*/
|
||||
public DbConfig getDbConfig()
|
||||
{
|
||||
return dbConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* close the db
|
||||
|
||||
@ -7,7 +7,7 @@
|
||||
*/
|
||||
|
||||
defined('INDEX_BLOCK_LENGTH') or define('INDEX_BLOCK_LENGTH', 12);
|
||||
defined('TOTAL_HEADER_LENGTH') or define('TOTAL_HEADER_LENGTH', 8192);
|
||||
defined('TOTAL_HEADER_LENGTH') or define('TOTAL_HEADER_LENGTH', 4096);
|
||||
|
||||
class Ip2Region
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user