projects
/
ecparse.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
use initialSize
[ecparse.git]
/
GrowingBuffer.cpp
diff --git
a/GrowingBuffer.cpp
b/GrowingBuffer.cpp
index
602084c
..
e73350f
100644
(file)
--- a/
GrowingBuffer.cpp
+++ b/
GrowingBuffer.cpp
@@
-8,8
+8,8
@@
#include "GrowingBuffer.h"
GrowingBuffer::GrowingBuffer(size_t initialSize) {
#include "GrowingBuffer.h"
GrowingBuffer::GrowingBuffer(size_t initialSize) {
- this->data = malloc(
1024
);
- this->size =
1024
;
+ this->data = malloc(
initialSize
);
+ this->size =
initialSize
;
this->limit = 0;
this->position = 0;
}
this->limit = 0;
this->position = 0;
}
@@
-44,17
+44,18
@@
void* GrowingBuffer::read(void* buffer, size_t length) {
}
void GrowingBuffer::write(const void* buffer, size_t length) {
}
void GrowingBuffer::write(const void* buffer, size_t length) {
- if (length > (size -
position
)) {
+ if (length > (size -
limit
)) {
int newSize = size;
do {
newSize *= 2;
int newSize = size;
do {
newSize *= 2;
- } while (length > (newSize -
position
));
+ } while (length > (newSize -
limit
));
void* newData = malloc(newSize);
memcpy(newData, data, position);
free(data);
data = newData;
}
void* newData = malloc(newSize);
memcpy(newData, data, position);
free(data);
data = newData;
}
- memcpy((ptrdiff_t*) data + position, buffer, length);
+ memcpy((ptrdiff_t*) data + limit, buffer, length);
+ limit += length;
}
void GrowingBuffer::cut() {
}
void GrowingBuffer::cut() {