Browse Source

cleaned up recent work, begin impl of file parser object

master
despair 5 years ago
parent
commit
494c2fb473
  1. 1
      .gitignore
  2. 17
      src/CFGFileParser.h

1
.gitignore vendored

@ -19,3 +19,4 @@ NetRunner2008.ncb @@ -19,3 +19,4 @@ NetRunner2008.ncb
/libssp-0.dll
/libstdc++-6.dll
/netrunner.exe
.vscode

17
src/CFGFileParser.h

@ -14,12 +14,12 @@ extern "C"{ @@ -14,12 +14,12 @@ extern "C"{
#include <cstdint>
// let's try fast strings
typedef std::basic_string<char, std::char_traits<char>, despair::TLSFAlloc<char>> fast_string;
namespace despair{ size_t string_hash(const fast_string &str); }
namespace despair{ size_t string_hash(const fast_string &str); bool fast_string_compare(fast_string t1, fast_string t2); }
namespace despair{
size_t string_hash(const fast_string &str)
{
size_t out;
size_t out = 0;
#if UINTPTR_MAX == 0xffffffff
MurmurHash3_x86_128 ( &str, sizeof(str), 7904542L, &out );
#elif UINTPTR_MAX == 0xffffffffffffffff
@ -28,8 +28,17 @@ namespace despair{ @@ -28,8 +28,17 @@ namespace despair{
#endif
return out;
}
bool fast_string_compare(fast_string t1, fast_string t2)
{
int i = strcmp(t1.c_str(),t2.c_str());
if (!i)
return true;
else
return false;
}
}
typedef std::unordered_map<fast_string,char*,std::function<decltype(despair::string_hash)>,std::equal_to<std::string>,despair::TLSFAlloc<std::pair<const fast_string, fast_string>>> stringmap;
typedef std::unordered_map<fast_string,fast_string,std::function<decltype(despair::string_hash)>,std::function<decltype(despair::fast_string_compare)>,despair::TLSFAlloc<std::pair<const fast_string, fast_string>>> stringmap;
// Class which holds the parsed configuration options after
// being processed by CFGFileParser. No longer a "trivial class"
@ -37,7 +46,7 @@ typedef std::unordered_map<fast_string,char*,std::function<decltype(despair::str @@ -37,7 +46,7 @@ typedef std::unordered_map<fast_string,char*,std::function<decltype(despair::str
struct BrowserConfiguration{
stringmap GlobalSettings;
// fast allocation!
static void* operator new(size_t n){ if (void *mem = tlsf_malloc(n)) return mem; throw std::bad_alloc {}; }
static void* operator new(size_t n) { if (void *mem = tlsf_malloc(n)) return mem; throw std::bad_alloc {}; }
static void operator delete(void *p){tlsf_free(p);}
void clear();
};

Loading…
Cancel
Save