Replace CLang file hashing with .st_mtime

Replace CLang file hashing with .st_mtime for performance.
Also, fix a problem in CLangMngr::MergeDefinitionFile.
This commit is contained in:
HttrckCldHKS 2015-02-19 21:28:45 +02:00
parent 2b9e9c79b9
commit 530d0bf570
2 changed files with 13 additions and 56 deletions

View File

@ -318,48 +318,22 @@ void reparse_color(String* def)
// -- BAILOPAN
int CLangMngr::MergeDefinitionFile(const char *file)
{
const char* md5buffer = hashFile(file, Hash_Md5);
if (!md5buffer)
/** Tries to open the file. */
struct stat fileStat;
if (stat(file, &fileStat))
{
CVector<md5Pair *>::iterator iter;
for (iter = FileList.begin(); iter != FileList.end(); ++iter)
{
if ((*iter)->file.compare(file) == 0)
{
char buf[33] = {0};
(*iter)->val.assign(buf);
break;
}
}
FileList.remove(file);
AMXXLOG_Log("[AMXX] Failed to open dictionary file: %s", file);
return 0;
}
bool foundFlag = false;
CVector<md5Pair *>::iterator iter;
for (iter = FileList.begin(); iter != FileList.end(); ++iter)
{
if ((*iter)->file.compare(file) == 0)
{
if ((*iter)->val.compare(md5buffer) == 0)
{
/** Checks if there is an existing entry with same time stamp. */
time_t timeStamp;
if (FileList.retrieve(file, &timeStamp) && fileStat.st_mtime == timeStamp)
return -1;
} else {
(*iter)->val.assign(md5buffer);
break;
}
foundFlag = true;
}
}
if (!foundFlag)
{
md5Pair *p = new md5Pair;
p->file.assign(file);
p->val.assign(md5buffer);
FileList.push_back(p);
}
/** If yes, it either means that the entry doesn't exist or the existing entry needs to be updated. */
FileList.replace(file, fileStat.st_mtime);
FILE* fp = fopen(file, "rt");
if (!fp)
@ -532,12 +506,6 @@ const char *CLangMngr::GetDef(const char *langName, const char *key, int &status
void CLangMngr::InvalidateCache()
{
for (size_t i = 0; i < FileList.size(); i++)
{
if (FileList[i])
delete FileList[i];
}
FileList.clear();
}
@ -558,12 +526,6 @@ void CLangMngr::Clear()
delete m_Languages[i];
}
for (i = 0; i < FileList.size(); i++)
{
if (FileList[i])
delete FileList[i];
}
for (i = 0; i < KeyList.size(); i++)
{
if (KeyList[i])

View File

@ -11,6 +11,7 @@
#define _INCLUDE_CLANG_H
#include "sh_tinyhash.h"
#include "sm_stringhashmap.h"
#define LANG_SERVER 0
#define LANG_PLAYER -1
@ -18,12 +19,6 @@
#define ERR_BADKEY 1 // Lang key not found
#define ERR_BADLANG 2 // Invalid lang
struct md5Pair
{
String file;
String val;
};
struct sKeyDef
{
String *definition;
@ -118,7 +113,7 @@ private:
LangVec m_Languages;
CVector<md5Pair *> FileList;
StringHashMap<time_t> FileList;
CVector<String *> KeyList;
THash<String, keytbl_val> KeyTable;