Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deque #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 2 additions & 12 deletions Buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,11 @@
Buffer::Buffer() noexcept {
}

Buffer::Buffer(const std::vector<unsigned char> &_buffer) noexcept:
buffer(_buffer) {
}

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 @@ -45,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
9 changes: 4 additions & 5 deletions Buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,18 @@
*/

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

struct BufferOverflow : public std::exception {};

class Buffer {
public:
Buffer() noexcept;
Buffer(const std::vector<unsigned char>&) 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 Expand Up @@ -102,5 +101,5 @@ class Buffer {

~Buffer();
private:
std::vector<unsigned char> buffer;
std::deque<unsigned char> buffer;
};
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