Skip to content

Commit b9afed1

Browse files
committed
Touch context buffers frequently
Signed-off-by: Hiroshi Hatake <[email protected]>
1 parent d362fbf commit b9afed1

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

ext/zstdruby/streaming_compress.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,10 @@ static VALUE
105105
no_compress(struct streaming_compress_t* sc, ZSTD_EndDirective endOp)
106106
{
107107
ZSTD_inBuffer input = { NULL, 0, 0 };
108-
const char* output_data = RSTRING_PTR(sc->buf);
109108
VALUE result = rb_str_new(0, 0);
110109
size_t ret;
111110
do {
111+
const char* output_data = RSTRING_PTR(sc->buf);
112112
ZSTD_outBuffer output = { (void*)output_data, sc->buf_size, 0 };
113113

114114
ret = zstd_stream_compress(sc->ctx, &output, &input, endOp, false);
@@ -131,9 +131,9 @@ rb_streaming_compress_compress(VALUE obj, VALUE src)
131131
struct streaming_compress_t* sc;
132132
TypedData_Get_Struct(obj, struct streaming_compress_t, &streaming_compress_type, sc);
133133

134-
const char* output_data = RSTRING_PTR(sc->buf);
135134
VALUE result = rb_str_new(0, 0);
136135
while (input.pos < input.size) {
136+
const char* output_data = RSTRING_PTR(sc->buf);
137137
ZSTD_outBuffer output = { (void*)output_data, sc->buf_size, 0 };
138138
size_t const ret = zstd_stream_compress(sc->ctx, &output, &input, ZSTD_e_continue, false);
139139
if (ZSTD_isError(ret)) {
@@ -150,7 +150,6 @@ rb_streaming_compress_write(int argc, VALUE *argv, VALUE obj)
150150
size_t total = 0;
151151
struct streaming_compress_t* sc;
152152
TypedData_Get_Struct(obj, struct streaming_compress_t, &streaming_compress_type, sc);
153-
const char* output_data = RSTRING_PTR(sc->buf);
154153

155154
while (argc-- > 0) {
156155
VALUE str = *argv++;
@@ -161,6 +160,7 @@ rb_streaming_compress_write(int argc, VALUE *argv, VALUE obj)
161160
VALUE result = rb_str_new(0, 0);
162161

163162
while (input.pos < input.size) {
163+
const char* output_data = RSTRING_PTR(sc->buf);
164164
ZSTD_outBuffer output = { (void*)output_data, sc->buf_size, 0 };
165165
size_t const ret = zstd_stream_compress(sc->ctx, &output, &input, ZSTD_e_continue, false);
166166
if (ZSTD_isError(ret)) {

ext/zstdruby/streaming_decompress.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,10 @@ rb_streaming_decompress_decompress(VALUE obj, VALUE src)
100100

101101
struct streaming_decompress_t* sd;
102102
TypedData_Get_Struct(obj, struct streaming_decompress_t, &streaming_decompress_type, sd);
103-
const char* output_data = RSTRING_PTR(sd->buf);
104103
VALUE result = rb_str_new(0, 0);
105104
size_t ret;
106105
do {
106+
const char* output_data = RSTRING_PTR(sd->buf);
107107
ZSTD_outBuffer output = { (void*)output_data, sd->buf_size, 0 };
108108
ret = zstd_stream_decompress(sd->dctx, &output, &input, false);
109109
if (ZSTD_isError(ret)) {

0 commit comments

Comments
 (0)