diff --git a/src/CFGFileParser.cpp b/src/CFGFileParser.cpp index 03f84b9df8d43706932a90235a4d39e3f7c285ee..8291e0601f560975e5d0f156ada240a3e9019a5d 100644 --- a/src/CFGFileParser.cpp +++ b/src/CFGFileParser.cpp @@ -7,7 +7,7 @@ CFGFileParser::CFGFileParser(const char* filename) // the buffer, close the file cfg_file = fopen(filename, "r"); stat(filename, cfg_fileinfo); - buffer = (char*)tlsf_calloc(cfg_fileinfo->st_size,sizeof(char)); + buffer = static_cast<char*>(tlsf_calloc(cfg_fileinfo->st_size,sizeof(char))); fread(buffer,sizeof(char),cfg_fileinfo->st_size,cfg_file); fclose(cfg_file); } @@ -16,4 +16,27 @@ CFGFileParser::~CFGFileParser() { // clean up! tlsf_free(buffer); +} + +namespace despair{ + size_t string_hash(const fast_string &str) + { + size_t out = 0; +#if UINTPTR_MAX == 0xffffffff + MurmurHash3_x86_128 ( &str, sizeof(str), 7904542L, &out ); +#elif UINTPTR_MAX == 0xffffffffffffffff + MurmurHash3_x64_128 ( &str, sizeof(str), 5484754L, &out ); +#else +#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; + } } \ No newline at end of file diff --git a/src/CFGFileParser.h b/src/CFGFileParser.h index a3894396c5b20443f060bb71fea3a5949792e974..e99f13963a12ce59067872ea3ff21c319848fce0 100644 --- a/src/CFGFileParser.h +++ b/src/CFGFileParser.h @@ -7,37 +7,13 @@ #include <algorithm> #include "TLSFAlloc.h" #include "Murmur3.h" -extern "C"{ #include "tlsf.h" #include <sys/stat.h> -} #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); bool fast_string_compare(fast_string t1, fast_string t2); } - -namespace despair{ - size_t string_hash(const fast_string &str) - { - size_t out = 0; -#if UINTPTR_MAX == 0xffffffff - MurmurHash3_x86_128 ( &str, sizeof(str), 7904542L, &out ); -#elif UINTPTR_MAX == 0xffffffffffffffff - MurmurHash3_x64_128 ( &str, sizeof(str), 5484754L, &out ); -#else -#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,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 diff --git a/src/TLSFAlloc.h b/src/TLSFAlloc.h index bcebdf70320ba1ad0696c018998c13a05e345ec2..eb4ecdadfa4f20f12d42ba2fdfeeea0d4c8c5820 100644 --- a/src/TLSFAlloc.h +++ b/src/TLSFAlloc.h @@ -4,9 +4,7 @@ #include <limits> #include <iostream> -extern "C"{ #include "tlsf.h" -} namespace despair { template <class T> diff --git a/src/main.cpp b/src/main.cpp index 724a85a621a2b787ca6a622de65dcc2cb0949a9e..c4f69f9e2295d07a134acf3a24eae811ed7b1b06 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4,16 +4,15 @@ #include "Log.h" #include "URL.h" #include "WebResource.h" -extern "C"{ #include "tlsf.h" -#ifdef _WIN32 -void init_heap(); -#endif - } #include <ctime> #include <iostream> #include <sys/stat.h> - +extern "C"{ + #ifdef _WIN32 + void init_heap(); + #endif +} #if defined(_WIN32) && !defined(_WIN64) #define PLATFORM "i686-pc-winnt" #endif diff --git a/src/pnm.h b/src/pnm.h index 57cbf5cb6c755d08bac1867f72f026bd41fd27ce..271f86ebef699035fe6cd83690a823d67dc1a40b 100644 --- a/src/pnm.h +++ b/src/pnm.h @@ -1,7 +1,6 @@ #include <string> -extern "C"{ #include "tlsf.h" -} + // this structure expects RGBA struct RGBAPNMObject { std::string magicNum; diff --git a/src/tlsf.c b/src/tlsf.c index 285a08499e6cd7a5605dfacaa31d5010395f451d..27651a847812398010d61e6ce7235aa49a8f1f93 100644 --- a/src/tlsf.c +++ b/src/tlsf.c @@ -1,3 +1,6 @@ +#ifdef __cplusplus +extern "C" { +#endif /* * Two Levels Segregate Fit memory allocator (TLSF) * Version 2.4.6 @@ -1227,4 +1230,7 @@ void print_all_blocks(tlsf_t * tlsf) } } +#endif +#ifdef __cplusplus +} #endif \ No newline at end of file diff --git a/src/tlsf.h b/src/tlsf.h index 29ffb7fcfba616ab3800c0bcef62b956bf4a4e9c..5ab40b7270765a9bf494ae5937adbf43ca0f38e0 100644 --- a/src/tlsf.h +++ b/src/tlsf.h @@ -18,7 +18,9 @@ #ifndef _TLSF_H_ #define _TLSF_H_ - +#ifdef __cplusplus +extern "C"{ +#endif #include <sys/types.h> extern size_t init_memory_pool(size_t, void *); @@ -37,3 +39,6 @@ extern void *tlsf_realloc(void *ptr, size_t size); extern void *tlsf_calloc(size_t nelem, size_t elem_size); #endif +#ifdef __cplusplus +} +#endif \ No newline at end of file