Migrated engine to using dlmalloc through eng::
This commit is contained in:
@@ -6,11 +6,11 @@
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <cmath>
|
||||
#include <iomanip>
|
||||
#include <cassert>
|
||||
#include <fstream>
|
||||
#include <cstdlib>
|
||||
#include <cmath>
|
||||
|
||||
#ifdef WIN32
|
||||
#endif
|
||||
@@ -30,7 +30,7 @@ static bool ascii_isdigit(char c) {
|
||||
return ((c >= '0') && (c <= '9'));
|
||||
}
|
||||
|
||||
bool is_identifier(const std::string &str) {
|
||||
bool is_identifier(const eng::string &str) {
|
||||
if (str.size() == 0) return false;
|
||||
char c=str[0];
|
||||
if ((!ascii_isalpha(c)) && (c!='_')) return false;
|
||||
@@ -41,7 +41,7 @@ bool is_identifier(const std::string &str) {
|
||||
return true;
|
||||
}
|
||||
|
||||
void quote_string(const std::string &s, std::ostream *os) {
|
||||
void quote_string(const eng::string &s, eng::ostream *os) {
|
||||
bool anysq = false;
|
||||
bool anydq = false;
|
||||
for (char c : s) {
|
||||
@@ -82,8 +82,8 @@ IdVector id_vector_create(int64_t id1, int64_t id2, int64_t id3, int64_t id4) {
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string id_vector_debug_string(const IdVector &idv) {
|
||||
std::ostringstream oss;
|
||||
eng::string id_vector_debug_string(const IdVector &idv) {
|
||||
eng::ostringstream oss;
|
||||
bool first = true;
|
||||
for (int64_t id : idv) {
|
||||
if (!first) oss << ",";
|
||||
@@ -111,7 +111,7 @@ IdVector sort_union_id_vectors(const IdVector &v1, const IdVector &v2) {
|
||||
return result;
|
||||
}
|
||||
|
||||
HashValue hash_string(const std::string &s) {
|
||||
HashValue hash_string(const eng::string &s) {
|
||||
uint64_t hash1 = 0;
|
||||
uint64_t hash2 = 0;
|
||||
SpookyHash::Hash128(s.c_str(), s.size(), &hash1, &hash2);
|
||||
@@ -125,14 +125,14 @@ HashValue hash_id_vector(const IdVector &idv) {
|
||||
return util::HashValue(hash1, hash2);
|
||||
}
|
||||
|
||||
std::string hash_to_hex(const HashValue &hv) {
|
||||
std::ostringstream oss;
|
||||
eng::string hash_to_hex(const HashValue &hv) {
|
||||
eng::ostringstream oss;
|
||||
oss << std::hex << std::setw(16) << std::setfill('0') << hv.first;
|
||||
oss << std::hex << std::setw(16) << std::setfill('0') << hv.second;
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
StringVec split(const std::string &s, char sep) {
|
||||
StringVec split(const eng::string &s, char sep) {
|
||||
StringVec result;
|
||||
int start = 0;
|
||||
for (int i = 0; i < int(s.size()); i++) {
|
||||
@@ -147,14 +147,14 @@ StringVec split(const std::string &s, char sep) {
|
||||
return result;
|
||||
}
|
||||
|
||||
static std::string substr_nocr(const std::string &s, int start, int len) {
|
||||
static eng::string substr_nocr(const eng::string &s, int start, int len) {
|
||||
if ((len > 0) && (s[start + len - 1] == '\r')) {
|
||||
len -= 1;
|
||||
}
|
||||
return s.substr(start, len);
|
||||
}
|
||||
|
||||
StringVec split_lines(const std::string &s) {
|
||||
StringVec split_lines(const eng::string &s) {
|
||||
StringVec result;
|
||||
int start = 0;
|
||||
for (int i = 0; i < int(s.size()); i++) {
|
||||
@@ -169,7 +169,7 @@ StringVec split_lines(const std::string &s) {
|
||||
return result;
|
||||
}
|
||||
|
||||
StringVec split_docstring(const std::string &s) {
|
||||
StringVec split_docstring(const eng::string &s) {
|
||||
StringVec result;
|
||||
int start = 0;
|
||||
for (int i = 0; i < int(s.size()); i++) {
|
||||
@@ -187,9 +187,9 @@ StringVec split_docstring(const std::string &s) {
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string join(const StringVec &strs, const std::string &sep) {
|
||||
eng::string join(const StringVec &strs, const eng::string &sep) {
|
||||
if (strs.empty()) return "";
|
||||
std::ostringstream oss;
|
||||
eng::ostringstream oss;
|
||||
oss << strs[0];
|
||||
for (int i = 1; i < int(strs.size()); i++) {
|
||||
oss << sep << strs[i];
|
||||
@@ -197,9 +197,9 @@ std::string join(const StringVec &strs, const std::string &sep) {
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
std::string repeat_string(const std::string &a, int n) {
|
||||
eng::string repeat_string(const eng::string &a, int n) {
|
||||
int len = a.size();
|
||||
std::string result(len * n, ' ');
|
||||
eng::string result(len * n, ' ');
|
||||
for (int i = 0; i < n; i++) {
|
||||
for (int j = 0; j < len; j++) {
|
||||
result[i*len + j] = a[j];
|
||||
@@ -208,7 +208,7 @@ std::string repeat_string(const std::string &a, int n) {
|
||||
return result;
|
||||
}
|
||||
|
||||
int common_prefix_length(const std::string &a, const std::string &b) {
|
||||
int common_prefix_length(const eng::string &a, const eng::string &b) {
|
||||
int minlen = std::min(a.size(), b.size());
|
||||
for (int i = 0; i < minlen; i++) {
|
||||
if (a[i] != b[i]) return i;
|
||||
@@ -216,25 +216,25 @@ int common_prefix_length(const std::string &a, const std::string &b) {
|
||||
return minlen;
|
||||
}
|
||||
|
||||
std::string tolower(std::string input) {
|
||||
eng::string tolower(eng::string input) {
|
||||
for (int i = 0; i < int(input.size()); i++) {
|
||||
input[i] = std::tolower(input[i]);
|
||||
}
|
||||
return input;
|
||||
}
|
||||
|
||||
std::string toupper(std::string input) {
|
||||
eng::string toupper(eng::string input) {
|
||||
for (int i = 0; i < int(input.size()); i++) {
|
||||
input[i] = std::toupper(input[i]);
|
||||
}
|
||||
return input;
|
||||
}
|
||||
|
||||
bool has_prefix(const std::string &s, const std::string &prefix) {
|
||||
bool has_prefix(const eng::string &s, const eng::string &prefix) {
|
||||
return 0 == s.compare(0, prefix.size(), prefix);
|
||||
}
|
||||
|
||||
bool has_suffix(const std::string &s, const std::string &suffix) {
|
||||
bool has_suffix(const eng::string &s, const eng::string &suffix) {
|
||||
if (s.length() >= suffix.length()) {
|
||||
return (0 == s.compare (s.length() - suffix.length(), suffix.length(), suffix));
|
||||
} else {
|
||||
@@ -242,14 +242,14 @@ bool has_suffix(const std::string &s, const std::string &suffix) {
|
||||
}
|
||||
}
|
||||
|
||||
bool validinteger(const std::string &value) {
|
||||
bool validinteger(const eng::string &value) {
|
||||
char *endptr;
|
||||
if (value.size() == 0) return false;
|
||||
strtoll(value.c_str(), &endptr, 10);
|
||||
return (endptr == value.c_str() + value.size());
|
||||
}
|
||||
|
||||
int64_t strtoint(const std::string &value, int64_t errval) {
|
||||
int64_t strtoint(const eng::string &value, int64_t errval) {
|
||||
char *endptr;
|
||||
if (value.size() == 0) return errval;
|
||||
int64_t result = strtoll(value.c_str(), &endptr, 10);
|
||||
@@ -260,7 +260,7 @@ int64_t strtoint(const std::string &value, int64_t errval) {
|
||||
}
|
||||
}
|
||||
|
||||
double strtodouble(const std::string &value) {
|
||||
double strtodouble(const eng::string &value) {
|
||||
char *endptr;
|
||||
if (value.size() == 0) return std::nan("");
|
||||
double result = strtod(value.c_str(), &endptr);
|
||||
@@ -271,25 +271,25 @@ double strtodouble(const std::string &value) {
|
||||
}
|
||||
}
|
||||
|
||||
std::string_view sv_ltrim(std::string_view v) {
|
||||
eng::string_view sv_ltrim(eng::string_view v) {
|
||||
const char *b = v.data();
|
||||
const char *e = v.data() + v.size();
|
||||
while ((e > b) && (std::isspace(b[0]))) {
|
||||
b++;
|
||||
}
|
||||
return std::string_view(b, e-b);
|
||||
return eng::string_view(b, e-b);
|
||||
}
|
||||
|
||||
std::string_view sv_rtrim(std::string_view v) {
|
||||
eng::string_view sv_rtrim(eng::string_view v) {
|
||||
const char *b = v.data();
|
||||
const char *e = v.data() + v.size();
|
||||
while ((e > b) && (std::isspace(e[-1]))) {
|
||||
e--;
|
||||
}
|
||||
return std::string_view(b, e-b);
|
||||
return eng::string_view(b, e-b);
|
||||
}
|
||||
|
||||
std::string_view sv_trim(std::string_view v) {
|
||||
eng::string_view sv_trim(eng::string_view v) {
|
||||
const char *b = v.data();
|
||||
const char *e = v.data() + v.size();
|
||||
while ((e > b) && (std::isspace(b[0]))) {
|
||||
@@ -298,25 +298,25 @@ std::string_view sv_trim(std::string_view v) {
|
||||
while ((e > b) && (std::isspace(e[-1]))) {
|
||||
e--;
|
||||
}
|
||||
return std::string_view(b, e-b);
|
||||
return eng::string_view(b, e-b);
|
||||
}
|
||||
|
||||
std::string ltrim(std::string_view v) {
|
||||
return std::string(sv_ltrim(v));
|
||||
eng::string ltrim(eng::string_view v) {
|
||||
return eng::string(sv_ltrim(v));
|
||||
}
|
||||
|
||||
std::string rtrim(std::string_view v) {
|
||||
return std::string(sv_rtrim(v));
|
||||
eng::string rtrim(eng::string_view v) {
|
||||
return eng::string(sv_rtrim(v));
|
||||
}
|
||||
|
||||
std::string trim(std::string_view v) {
|
||||
return std::string(sv_trim(v));
|
||||
eng::string trim(eng::string_view v) {
|
||||
return eng::string(sv_trim(v));
|
||||
}
|
||||
|
||||
std::string_view sv_read_line(std::string_view &source) {
|
||||
eng::string_view sv_read_line(eng::string_view &source) {
|
||||
size_t pos = source.find('\n');
|
||||
std::string_view result;
|
||||
if (pos == std::string_view::npos) {
|
||||
eng::string_view result;
|
||||
if (pos == eng::string_view::npos) {
|
||||
result = source;
|
||||
source = "";
|
||||
} else {
|
||||
@@ -342,43 +342,43 @@ bool world_type_authoritative(util::WorldType wt) {
|
||||
return (wt == WORLD_TYPE_MASTER) || (wt == WORLD_TYPE_STANDALONE);
|
||||
}
|
||||
|
||||
LuaSourcePtr make_lua_source(const std::string &code) {
|
||||
LuaSourcePtr make_lua_source(const eng::string &code) {
|
||||
LuaSourcePtr result(new LuaSourceVec);
|
||||
std::string fn = "file.lua";
|
||||
eng::string fn = "file.lua";
|
||||
result->push_back(std::make_pair(fn, code));
|
||||
return result;
|
||||
}
|
||||
|
||||
bool is_lua_comment(const std::string &s) {
|
||||
bool is_lua_comment(const eng::string &s) {
|
||||
int start = 0;
|
||||
while ((start < int(s.size())) && ((s[start]==' ') || (s[start]=='\t'))) start++;
|
||||
return s.substr(start, 2) == "--";
|
||||
}
|
||||
|
||||
std::string XYZ::debug_string() const {
|
||||
std::ostringstream oss;
|
||||
eng::string XYZ::debug_string() const {
|
||||
eng::ostringstream oss;
|
||||
oss << "(" << x << "," << y << "," << z << ")";
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
} // namespace util
|
||||
|
||||
std::ostream &operator<<(std::ostream &oss, const util::hex64 &v) {
|
||||
eng::ostream &operator<<(eng::ostream &oss, const util::hex64 &v) {
|
||||
oss << "0x" << std::setw(16) << std::setfill('0') << std::hex;
|
||||
return oss;
|
||||
}
|
||||
|
||||
std::ostream &operator<<(std::ostream &oss, const util::hex32 &v) {
|
||||
eng::ostream &operator<<(eng::ostream &oss, const util::hex32 &v) {
|
||||
oss << "0x" << std::setw(8) << std::setfill('0') << std::hex;
|
||||
return oss;
|
||||
}
|
||||
|
||||
std::ostream &operator<<(std::ostream &oss, const util::hex16 &v) {
|
||||
eng::ostream &operator<<(eng::ostream &oss, const util::hex16 &v) {
|
||||
oss << "0x" << std::setw(4) << std::setfill('0') << std::hex;
|
||||
return oss;
|
||||
}
|
||||
|
||||
std::ostream &operator<<(std::ostream &oss, const util::hex8 &v) {
|
||||
eng::ostream &operator<<(eng::ostream &oss, const util::hex8 &v) {
|
||||
oss << "0x" << std::setw(2) << std::setfill('0') << std::hex;
|
||||
return oss;
|
||||
}
|
||||
@@ -449,10 +449,10 @@ LuaDefine(unittests_util, "", "some unit tests") {
|
||||
LuaAssert(L, util::trim("") == "");
|
||||
|
||||
// Test sv_read_line
|
||||
std::string_view v = "foo\nbar\r\n";
|
||||
std::string_view v1 = util::sv_read_line(v);
|
||||
std::string_view v2 = util::sv_read_line(v);
|
||||
std::string_view v3 = util::sv_read_line(v);
|
||||
eng::string_view v = "foo\nbar\r\n";
|
||||
eng::string_view v1 = util::sv_read_line(v);
|
||||
eng::string_view v2 = util::sv_read_line(v);
|
||||
eng::string_view v3 = util::sv_read_line(v);
|
||||
LuaAssertStrEq(L, v1, "foo");
|
||||
LuaAssertStrEq(L, v2, "bar");
|
||||
LuaAssertStrEq(L, v3, "");
|
||||
|
||||
Reference in New Issue
Block a user