Browse Source

code cleanup

master
despair 5 years ago
parent
commit
35adeb199d
  1. 25
      src/CFGFileParser.cpp
  2. 26
      src/CFGFileParser.h
  3. 2
      src/TLSFAlloc.h
  4. 11
      src/main.cpp
  5. 3
      src/pnm.h
  6. 6
      src/tlsf.c
  7. 7
      src/tlsf.h

25
src/CFGFileParser.cpp

@ -7,7 +7,7 @@ CFGFileParser::CFGFileParser(const char* filename) @@ -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() @@ -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;
}
}

26
src/CFGFileParser.h

@ -7,37 +7,13 @@ @@ -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

2
src/TLSFAlloc.h

@ -4,9 +4,7 @@ @@ -4,9 +4,7 @@
#include <limits>
#include <iostream>
extern "C"{
#include "tlsf.h"
}
namespace despair {
template <class T>

11
src/main.cpp

@ -4,16 +4,15 @@ @@ -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

3
src/pnm.h

@ -1,7 +1,6 @@ @@ -1,7 +1,6 @@
#include <string>
extern "C"{
#include "tlsf.h"
}
// this structure expects RGBA
struct RGBAPNMObject {
std::string magicNum;

6
src/tlsf.c

@ -1,3 +1,6 @@ @@ -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) @@ -1227,4 +1230,7 @@ void print_all_blocks(tlsf_t * tlsf)
}
}
#endif
#ifdef __cplusplus
}
#endif

7
src/tlsf.h

@ -18,7 +18,9 @@ @@ -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); @@ -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
Loading…
Cancel
Save