Migrated engine to using dlmalloc through eng::
This commit is contained in:
@@ -25,7 +25,7 @@ StreamBuffer::StreamBuffer() {
|
||||
|
||||
StreamBuffer::StreamBuffer(int64_t size, bool fixed) {
|
||||
assert(size >= 0);
|
||||
init(fixed, true, (char*)malloc(size), size);
|
||||
init(fixed, true, (char*)dlmalloc(size), size);
|
||||
}
|
||||
|
||||
StreamBuffer::StreamBuffer(const char *s, int64_t size) {
|
||||
@@ -34,13 +34,13 @@ StreamBuffer::StreamBuffer(const char *s, int64_t size) {
|
||||
write_cursor_ = buf_hi_;
|
||||
}
|
||||
|
||||
StreamBuffer::StreamBuffer(const std::string &src) {
|
||||
StreamBuffer::StreamBuffer(const eng::string &src) {
|
||||
init(true, false, const_cast<char *>(src.c_str()), src.size());
|
||||
write_cursor_ = buf_hi_;
|
||||
}
|
||||
|
||||
StreamBuffer::~StreamBuffer() {
|
||||
if (owned_ && (buf_lo_ != 0)) free(buf_lo_);
|
||||
if (owned_ && (buf_lo_ != 0)) dlfree(buf_lo_);
|
||||
}
|
||||
|
||||
int64_t StreamBuffer::total_reads() const {
|
||||
@@ -87,9 +87,9 @@ void StreamBuffer::make_space_slow(int64_t bytes) {
|
||||
} else if (existing_size >= desired_size) {
|
||||
if (data_size > 0) memcpy(buf_lo_, read_cursor_, data_size);
|
||||
} else {
|
||||
char *nbuf = (char *)malloc(desired_size);
|
||||
char *nbuf = (char *)dlmalloc(desired_size);
|
||||
if (data_size > 0) memcpy(nbuf, read_cursor_, data_size);
|
||||
if (buf_lo_ != nullptr) free(buf_lo_);
|
||||
if (buf_lo_ != nullptr) dlfree(buf_lo_);
|
||||
buf_lo_ = nbuf;
|
||||
buf_hi_ = nbuf + desired_size;
|
||||
}
|
||||
@@ -116,7 +116,7 @@ char *StreamBuffer::get_overwrite(int64_t size, int64_t write_count_after) {
|
||||
void StreamBuffer::clear() {
|
||||
assert(owned_);
|
||||
if (!fixed_size_) {
|
||||
if (buf_lo_ != nullptr) free(buf_lo_);
|
||||
if (buf_lo_ != nullptr) dlfree(buf_lo_);
|
||||
buf_lo_ = 0;
|
||||
buf_hi_ = 0;
|
||||
}
|
||||
@@ -128,14 +128,14 @@ void StreamBuffer::clear() {
|
||||
lua_reader_size_ = 0;
|
||||
}
|
||||
|
||||
std::string StreamBuffer::readline() {
|
||||
eng::string StreamBuffer::readline() {
|
||||
char *p = read_cursor_;
|
||||
while ((p < write_cursor_) && (*p != '\n')) p++;
|
||||
if (p == write_cursor_) {
|
||||
return "";
|
||||
} else {
|
||||
p++;
|
||||
std::string result(read_cursor_, p - read_cursor_);
|
||||
eng::string result(read_cursor_, p - read_cursor_);
|
||||
read_cursor_ = p;
|
||||
return result;
|
||||
}
|
||||
@@ -182,7 +182,7 @@ void StreamBuffer::write_bytes(const char *s, int64_t len) {
|
||||
write_cursor_ += len;
|
||||
}
|
||||
|
||||
void StreamBuffer::write_bytes(const std::string &s) {
|
||||
void StreamBuffer::write_bytes(const eng::string &s) {
|
||||
write_bytes(s.c_str(), s.size());
|
||||
}
|
||||
|
||||
@@ -322,7 +322,7 @@ void StreamBuffer::write_hashvalue(const util::HashValue &hv) {
|
||||
write_uint64(hv.second);
|
||||
}
|
||||
|
||||
void StreamBuffer::write_string(const std::string &s) {
|
||||
void StreamBuffer::write_string(const eng::string &s) {
|
||||
if (s.size() >= 255) {
|
||||
write_uint8(0xFF);
|
||||
write_uint64(s.size());
|
||||
@@ -339,11 +339,11 @@ util::HashValue StreamBuffer::read_hashvalue() {
|
||||
return util::HashValue(f,s);
|
||||
}
|
||||
|
||||
std::string StreamBuffer::read_string() {
|
||||
eng::string StreamBuffer::read_string() {
|
||||
return read_string_limit(0xFFFFFFF);
|
||||
}
|
||||
|
||||
std::string StreamBuffer::read_string_limit(int64_t max_allowed) {
|
||||
eng::string StreamBuffer::read_string_limit(int64_t max_allowed) {
|
||||
int64_t len = read_uint8();
|
||||
if (len == 255) {
|
||||
len = read_int64();
|
||||
@@ -351,11 +351,11 @@ std::string StreamBuffer::read_string_limit(int64_t max_allowed) {
|
||||
if (len < 0) throw StreamCorruption();
|
||||
if (len > max_allowed) throw StreamCorruption();
|
||||
const char *bytes = read_bytes(len);
|
||||
return std::string(bytes, len);
|
||||
return eng::string(bytes, len);
|
||||
}
|
||||
|
||||
std::string StreamBuffer::read_entire_contents() {
|
||||
std::string result(read_cursor_, fill());
|
||||
eng::string StreamBuffer::read_entire_contents() {
|
||||
eng::string result(read_cursor_, fill());
|
||||
read_cursor_ = write_cursor_;
|
||||
return result;
|
||||
}
|
||||
@@ -504,18 +504,18 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
class StreamBufferOStream : public std::ostream {
|
||||
class StreamBufferOStream : public eng::ostream {
|
||||
private:
|
||||
StreamBufferWriter writer_;
|
||||
public:
|
||||
StreamBufferOStream(StreamBuffer *t) : std::ostream(nullptr), writer_(t) {
|
||||
StreamBufferOStream(StreamBuffer *t) : eng::ostream(nullptr), writer_(t) {
|
||||
rdbuf(&writer_);
|
||||
}
|
||||
virtual ~StreamBufferOStream() {
|
||||
}
|
||||
};
|
||||
|
||||
std::ostream &StreamBuffer::ostream() {
|
||||
eng::ostream &StreamBuffer::ostream() {
|
||||
if (ostream_ == nullptr) {
|
||||
ostream_.reset(new StreamBufferOStream(this));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user