zlib: instance-ify two methods
Both `Params` and `SetDictionary` take `ZCtx` as an arg, so just make them both instance methods on `ZCtx`. PR-URL: https://github.com/nodejs/node/pull/21702 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
acf0606f72
commit
144c1b7e98
@ -486,7 +486,7 @@ class ZCtx : public AsyncWrap, public ThreadPoolWork {
|
|||||||
write_js_callback, dictionary, dictionary_len);
|
write_js_callback, dictionary, dictionary_len);
|
||||||
if (!ret) goto end;
|
if (!ret) goto end;
|
||||||
|
|
||||||
SetDictionary(ctx);
|
ctx->SetDictionary();
|
||||||
|
|
||||||
end:
|
end:
|
||||||
return args.GetReturnValue().Set(ret);
|
return args.GetReturnValue().Set(ret);
|
||||||
@ -496,14 +496,14 @@ class ZCtx : public AsyncWrap, public ThreadPoolWork {
|
|||||||
CHECK(args.Length() == 2 && "params(level, strategy)");
|
CHECK(args.Length() == 2 && "params(level, strategy)");
|
||||||
ZCtx* ctx;
|
ZCtx* ctx;
|
||||||
ASSIGN_OR_RETURN_UNWRAP(&ctx, args.Holder());
|
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) {
|
static void Reset(const FunctionCallbackInfo<Value> &args) {
|
||||||
ZCtx* ctx;
|
ZCtx* ctx;
|
||||||
ASSIGN_OR_RETURN_UNWRAP(&ctx, args.Holder());
|
ASSIGN_OR_RETURN_UNWRAP(&ctx, args.Holder());
|
||||||
ctx->Reset();
|
ctx->Reset();
|
||||||
SetDictionary(ctx);
|
ctx->SetDictionary();
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool Init(ZCtx* ctx, int level, int windowBits, int memLevel,
|
static bool Init(ZCtx* ctx, int level, int windowBits, int memLevel,
|
||||||
@ -577,51 +577,47 @@ class ZCtx : public AsyncWrap, public ThreadPoolWork {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void SetDictionary(ZCtx* ctx) {
|
void SetDictionary() {
|
||||||
if (ctx->dictionary_ == nullptr)
|
if (dictionary_ == nullptr)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ctx->err_ = Z_OK;
|
err_ = Z_OK;
|
||||||
|
|
||||||
switch (ctx->mode_) {
|
switch (mode_) {
|
||||||
case DEFLATE:
|
case DEFLATE:
|
||||||
case DEFLATERAW:
|
case DEFLATERAW:
|
||||||
ctx->err_ = deflateSetDictionary(&ctx->strm_,
|
err_ = deflateSetDictionary(&strm_, dictionary_, dictionary_len_);
|
||||||
ctx->dictionary_,
|
|
||||||
ctx->dictionary_len_);
|
|
||||||
break;
|
break;
|
||||||
case INFLATERAW:
|
case INFLATERAW:
|
||||||
// The other inflate cases will have the dictionary set when inflate()
|
// The other inflate cases will have the dictionary set when inflate()
|
||||||
// returns Z_NEED_DICT in Process()
|
// returns Z_NEED_DICT in Process()
|
||||||
ctx->err_ = inflateSetDictionary(&ctx->strm_,
|
err_ = inflateSetDictionary(&strm_, dictionary_, dictionary_len_);
|
||||||
ctx->dictionary_,
|
|
||||||
ctx->dictionary_len_);
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ctx->err_ != Z_OK) {
|
if (err_ != Z_OK) {
|
||||||
ctx->Error("Failed to set dictionary");
|
Error("Failed to set dictionary");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void Params(ZCtx* ctx, int level, int strategy) {
|
void Params(int level, int strategy) {
|
||||||
AllocScope alloc_scope(ctx);
|
AllocScope alloc_scope(this);
|
||||||
|
|
||||||
ctx->err_ = Z_OK;
|
err_ = Z_OK;
|
||||||
|
|
||||||
switch (ctx->mode_) {
|
switch (mode_) {
|
||||||
case DEFLATE:
|
case DEFLATE:
|
||||||
case DEFLATERAW:
|
case DEFLATERAW:
|
||||||
ctx->err_ = deflateParams(&ctx->strm_, level, strategy);
|
err_ = deflateParams(&strm_, level, strategy);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ctx->err_ != Z_OK && ctx->err_ != Z_BUF_ERROR) {
|
if (err_ != Z_OK && err_ != Z_BUF_ERROR) {
|
||||||
ctx->Error("Failed to set parameters");
|
Error("Failed to set parameters");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user