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

zlib: instance-ify two methods #21702

Closed
wants to merge 1 commit into from
Closed
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
40 changes: 18 additions & 22 deletions src/node_zlib.cc
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ class ZCtx : public AsyncWrap, public ThreadPoolWork {
write_js_callback, dictionary, dictionary_len);
if (!ret) goto end;

SetDictionary(ctx);
ctx->SetDictionary();

end:
return args.GetReturnValue().Set(ret);
Expand All @@ -496,14 +496,14 @@ class ZCtx : public AsyncWrap, public ThreadPoolWork {
CHECK(args.Length() == 2 && "params(level, strategy)");
ZCtx* ctx;
ASSIGN_OR_RETURN_UNWRAP(&ctx, args.Holder());
Params(ctx, args[0]->Int32Value(), args[1]->Int32Value());
ctx->Params(args[0]->Int32Value(), args[1]->Int32Value());
}

static void Reset(const FunctionCallbackInfo<Value> &args) {
ZCtx* ctx;
ASSIGN_OR_RETURN_UNWRAP(&ctx, args.Holder());
ctx->Reset();
SetDictionary(ctx);
ctx->SetDictionary();
}

static bool Init(ZCtx* ctx, int level, int windowBits, int memLevel,
Expand Down Expand Up @@ -577,51 +577,47 @@ class ZCtx : public AsyncWrap, public ThreadPoolWork {
return true;
}

static void SetDictionary(ZCtx* ctx) {
if (ctx->dictionary_ == nullptr)
void SetDictionary() {
if (dictionary_ == nullptr)
return;

ctx->err_ = Z_OK;
err_ = Z_OK;

switch (ctx->mode_) {
switch (mode_) {
case DEFLATE:
case DEFLATERAW:
ctx->err_ = deflateSetDictionary(&ctx->strm_,
ctx->dictionary_,
ctx->dictionary_len_);
err_ = deflateSetDictionary(&strm_, dictionary_, dictionary_len_);
break;
case INFLATERAW:
// The other inflate cases will have the dictionary set when inflate()
// returns Z_NEED_DICT in Process()
ctx->err_ = inflateSetDictionary(&ctx->strm_,
ctx->dictionary_,
ctx->dictionary_len_);
err_ = inflateSetDictionary(&strm_, dictionary_, dictionary_len_);
break;
default:
break;
}

if (ctx->err_ != Z_OK) {
ctx->Error("Failed to set dictionary");
if (err_ != Z_OK) {
Error("Failed to set dictionary");
}
}

static void Params(ZCtx* ctx, int level, int strategy) {
AllocScope alloc_scope(ctx);
void Params(int level, int strategy) {
AllocScope alloc_scope(this);

ctx->err_ = Z_OK;
err_ = Z_OK;

switch (ctx->mode_) {
switch (mode_) {
case DEFLATE:
case DEFLATERAW:
ctx->err_ = deflateParams(&ctx->strm_, level, strategy);
err_ = deflateParams(&strm_, level, strategy);
break;
default:
break;
}

if (ctx->err_ != Z_OK && ctx->err_ != Z_BUF_ERROR) {
ctx->Error("Failed to set parameters");
if (err_ != Z_OK && err_ != Z_BUF_ERROR) {
Error("Failed to set parameters");
}
}

Expand Down