mirror of
https://github.com/ckolivas/lrzip.git
synced 2025-12-06 07:12:00 +01:00
Add virtual read() support to the bufRead class to speed up encoding/decoding via the zpaq library.
This commit is contained in:
parent
a55250cf16
commit
4d48717949
|
|
@ -31,6 +31,7 @@ comprises the reference decoder for the ZPAQ level 2 standard.
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
namespace libzpaq {
|
namespace libzpaq {
|
||||||
|
|
||||||
|
|
@ -444,6 +445,7 @@ struct bufRead: public libzpaq::Reader {
|
||||||
uchar *s_buf;
|
uchar *s_buf;
|
||||||
long long *s_len;
|
long long *s_len;
|
||||||
bufRead(uchar *buf_, long long *n_): s_buf(buf_), s_len(n_) {}
|
bufRead(uchar *buf_, long long *n_): s_buf(buf_), s_len(n_) {}
|
||||||
|
|
||||||
int get() {
|
int get() {
|
||||||
if (*s_len > 0) {
|
if (*s_len > 0) {
|
||||||
(*s_len)--;
|
(*s_len)--;
|
||||||
|
|
@ -451,6 +453,22 @@ struct bufRead: public libzpaq::Reader {
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
} // read and return byte 0..255, or -1 at EOF
|
} // 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;
|
||||||
|
|
||||||
|
*s_len -= diff;
|
||||||
|
memcpy(buf, s_buf, diff);
|
||||||
|
return diff;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct bufWrite: public libzpaq::Writer {
|
struct bufWrite: public libzpaq::Writer {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue