Skip to content

Commit

Permalink
Simplify string cast
Browse files Browse the repository at this point in the history
  • Loading branch information
Anton Shabouta committed May 11, 2019
1 parent d9c9fcc commit 839d5df
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 11 deletions.
10 changes: 2 additions & 8 deletions Buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ void Buffer::clear() noexcept {
buffer.clear();
}

void Buffer::write(char * str, long length) noexcept {
void Buffer::write(char * str, unsigned long length) noexcept {
buffer.insert(buffer.end(), str, str + length);
}

Expand All @@ -41,13 +41,7 @@ void Buffer::merge(const Buffer &other) noexcept {
}

std::string Buffer::bytes() const noexcept {
std::stringstream stream;

unsigned long long size = buffer.size();
for (unsigned long long i = 0; i < size; ++i)
stream << buffer[i];

return stream.str();
return std::string(buffer.begin(), buffer.end());
}

std::string Buffer::flush() noexcept {
Expand Down
4 changes: 2 additions & 2 deletions Buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

#pragma once
#include <deque>
#include <sstream>
#include <string>
#include <exception>

struct BufferOverflow : public std::exception {};
Expand All @@ -19,7 +19,7 @@ class Buffer {
Buffer() noexcept;

void clear() noexcept;
void write(char * str, long length) noexcept;
void write(char * str, unsigned long length) noexcept;
void discard(unsigned long long n);

unsigned long long size() const noexcept;
Expand Down
2 changes: 1 addition & 1 deletion buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ static zend_function_entry buffer_object_methods[] = {
};

static zend_object* buffer_object_create(zend_class_entry *ce) {
buffer_object *objval = (buffer_object*) ecalloc(1, sizeof(buffer_object) + zend_object_properties_size(ce));
buffer_object *objval = (buffer_object*) emalloc(sizeof(buffer_object) + zend_object_properties_size(ce));

zend_object* ret = buffer_object_to_zend_object(objval);

Expand Down

0 comments on commit 839d5df

Please sign in to comment.