Implement virtual write support for bufWrite to speed up zpaq support and simplify the virtual read function for bufRead.

This commit is contained in:
Con Kolivas 2012-03-16 23:00:29 +11:00
parent 4d48717949
commit 26433850b9

View file

@ -455,19 +455,14 @@ struct bufRead: public libzpaq::Reader {
} // read and return byte 0..255, or -1 at EOF
int read(char *buf, int n) {
int diff;
if (*s_len < 1)
return -1;
if (n > *s_len)
diff = *s_len;
else
diff = *s_len - n;
n = *s_len;
*s_len -= diff;
memcpy(buf, s_buf, diff);
return diff;
if (n > 0) {
*s_len -= n;
memcpy(buf, s_buf, n);
}
return n;
}
};
@ -475,9 +470,15 @@ struct bufWrite: public libzpaq::Writer {
uchar *c_buf;
long long *c_len;
bufWrite(uchar *buf_, long long *n_): c_buf(buf_), c_len(n_) {}
void put(int c) {
c_buf[(*c_len)++] = (uchar)c;
}
void write(const char *buf, int n) {
memcpy(c_buf + *c_len, buf, n);
*c_len += n;
}
};
extern "C" void zpaq_compress(uchar *c_buf, long long *c_len, uchar *s_buf, long long s_len, int level) {