diff options
author | ultramage <ultramage@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2011-06-16 17:36:53 +0000 |
---|---|---|
committer | ultramage <ultramage@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2011-06-16 17:36:53 +0000 |
commit | 8af17f9980ea44989c273ba96bd6ba673847744d (patch) | |
tree | 987099134ca9e88fd559351b1a9a3c68e9e28103 /src/common/db.c | |
parent | 5666e57db9792d5e2f4faf89599812a570b39b96 (diff) | |
download | hercules-8af17f9980ea44989c273ba96bd6ba673847744d.tar.gz hercules-8af17f9980ea44989c273ba96bd6ba673847744d.tar.bz2 hercules-8af17f9980ea44989c273ba96bd6ba673847744d.tar.xz hercules-8af17f9980ea44989c273ba96bd6ba673847744d.zip |
Moved DBMap's string maxlen parameter translation (0 -> UINT16_MAX) to its initialization phase, so that it runs once instead of on every hash and compare step. This will slightly speed up most strdb operations.
git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@14854 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src/common/db.c')
-rw-r--r-- | src/common/db.c | 19 |
1 files changed, 5 insertions, 14 deletions
diff --git a/src/common/db.c b/src/common/db.c index 5622a2433..cd39f7a4b 100644 --- a/src/common/db.c +++ b/src/common/db.c @@ -632,14 +632,12 @@ static DBKey db_dup_key(DBMap_impl* db, DBKey key) { char *str; size_t len; - unsigned short maxlen; DB_COUNTSTAT(db_dup_key); switch (db->type) { case DB_STRING: case DB_ISTRING: - maxlen = ( db->maxlen != 0 ) ? db->maxlen : UINT16_MAX; - len = strnlen(key.str, maxlen); + len = strnlen(key.str, db->maxlen); str = (char*)aMalloc(len + 1); memcpy(str, key.str, len); str[len] = '\0'; @@ -889,8 +887,6 @@ static int db_uint_cmp(DBKey key1, DBKey key2, unsigned short maxlen) static int db_string_cmp(DBKey key1, DBKey key2, unsigned short maxlen) { DB_COUNTSTAT(db_string_cmp); - if (maxlen == 0) - maxlen = UINT16_MAX; return strncmp((const char *)key1.str, (const char *)key2.str, maxlen); } @@ -909,8 +905,6 @@ static int db_string_cmp(DBKey key1, DBKey key2, unsigned short maxlen) static int db_istring_cmp(DBKey key1, DBKey key2, unsigned short maxlen) { DB_COUNTSTAT(db_istring_cmp); - if (maxlen == 0) - maxlen = UINT16_MAX; return strncasecmp((const char *)key1.str, (const char *)key2.str, maxlen); } @@ -952,7 +946,6 @@ static unsigned int db_uint_hash(DBKey key, unsigned short maxlen) /** * Default hasher for DB_STRING databases. - * If maxlen if 0, the maximum number of maxlen is used instead. * @param key Key to be hashed * @param maxlen Maximum length of the key to hash * @return hash of the key @@ -967,8 +960,6 @@ static unsigned int db_string_hash(DBKey key, unsigned short maxlen) unsigned short i; DB_COUNTSTAT(db_string_hash); - if (maxlen == 0) - maxlen = UINT16_MAX; for (i = 0; *k; ++i) { hash = (hash*33 + ((unsigned char)*k))^(hash>>24); @@ -982,7 +973,6 @@ static unsigned int db_string_hash(DBKey key, unsigned short maxlen) /** * Default hasher for DB_ISTRING databases. - * If maxlen if 0, the maximum number of maxlen is used instead. * @param key Key to be hashed * @param maxlen Maximum length of the key to hash * @return hash of the key @@ -996,8 +986,6 @@ static unsigned int db_istring_hash(DBKey key, unsigned short maxlen) unsigned short i; DB_COUNTSTAT(db_istring_hash); - if (maxlen == 0) - maxlen = UINT16_MAX; for (i = 0; *k; i++) { hash = (hash*33 + ((unsigned char)TOLOWER(*k)))^(hash>>24); @@ -2379,7 +2367,7 @@ DBReleaser db_custom_release(DBRelease which) * @param type Type of database * @param options Options of the database * @param maxlen Maximum length of the string to be used as key in string - * databases + * databases. If 0, the maximum number of maxlen is used (64K). * @return The interface of the database * @public * @see #DBMap_impl @@ -2443,6 +2431,9 @@ DBMap* db_alloc(const char *file, int line, DBType type, DBOptions options, unsi db->maxlen = maxlen; db->global_lock = 0; + if( db->maxlen == 0 && (type == DB_STRING || type == DB_ISTRING) ) + db->maxlen = UINT16_MAX; + return &db->vtable; } |