Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
zlib: C++ style fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
indutny committed Jan 11, 2012
1 parent b073989 commit 07701e7
Showing 1 changed file with 15 additions and 23 deletions.
38 changes: 15 additions & 23 deletions src/node_zlib.cc
Expand Up @@ -71,8 +71,7 @@ template <node_zlib_mode mode> class ZCtx : public ObjectWrap {
}

// write(flush, in, in_off, in_len, out, out_off, out_len)
static Handle<Value>
Write(const Arguments& args) {
static Handle<Value> Write(const Arguments& args) {
HandleScope scope;
assert(args.Length() == 7);

Expand All @@ -97,25 +96,25 @@ template <node_zlib_mode mode> class ZCtx : public ObjectWrap {
assert(Buffer::HasInstance(args[1]));
Local<Object> in_buf;
in_buf = args[1]->ToObject();
in_off = (size_t)args[2]->Uint32Value();
in_len = (size_t)args[3]->Uint32Value();
in_off = args[2]->Uint32Value();
in_len = args[3]->Uint32Value();

assert(in_off + in_len <= Buffer::Length(in_buf));
in = reinterpret_cast<Bytef *>(Buffer::Data(in_buf) + in_off);
}

assert(Buffer::HasInstance(args[4]));
Local<Object> out_buf = args[4]->ToObject();
out_off = (size_t)args[5]->Uint32Value();
out_len = (size_t)args[6]->Uint32Value();
out_off = args[5]->Uint32Value();
out_len = args[6]->Uint32Value();
assert(out_off + out_len <= Buffer::Length(out_buf));
out = reinterpret_cast<Bytef *>(Buffer::Data(out_buf) + out_off);

// build up the work request
uv_work_t* work_req = &(ctx->work_req_);

ctx->strm_.avail_in = in_len;
ctx->strm_.next_in = &(*in);
ctx->strm_.next_in = in;
ctx->strm_.avail_out = out_len;
ctx->strm_.next_out = out;
ctx->flush_ = flush;
Expand All @@ -138,8 +137,7 @@ template <node_zlib_mode mode> class ZCtx : public ObjectWrap {
// This function may be called multiple times on the uv_work pool
// for a single write() call, until all of the input bytes have
// been consumed.
static void
Process(uv_work_t* work_req) {
static void Process(uv_work_t* work_req) {
ZCtx<mode> *ctx = container_of(work_req, ZCtx<mode>, work_req_);

// If the avail_out is left at 0, then it means that it ran out
Expand All @@ -150,13 +148,13 @@ template <node_zlib_mode mode> class ZCtx : public ObjectWrap {
case DEFLATE:
case GZIP:
case DEFLATERAW:
err = deflate(&(ctx->strm_), ctx->flush_);
err = deflate(&ctx->strm_, ctx->flush_);
break;
case UNZIP:
case INFLATE:
case GUNZIP:
case INFLATERAW:
err = inflate(&(ctx->strm_), ctx->flush_);
err = inflate(&ctx->strm_, ctx->flush_);
break;
default:
assert(0 && "wtf?");
Expand All @@ -169,10 +167,10 @@ template <node_zlib_mode mode> class ZCtx : public ObjectWrap {
}

// v8 land!
static void
After(uv_work_t* work_req) {
static void After(uv_work_t* work_req) {
HandleScope scope;
ZCtx<mode> *ctx = container_of(work_req, ZCtx<mode>, work_req_);

Local<Integer> avail_out = Integer::New(ctx->strm_.avail_out);
Local<Integer> avail_in = Integer::New(ctx->strm_.avail_in);

Expand All @@ -187,17 +185,15 @@ template <node_zlib_mode mode> class ZCtx : public ObjectWrap {
ctx->Unref();
}

static Handle<Value>
New(const Arguments& args) {
static Handle<Value> New(const Arguments& args) {
HandleScope scope;
ZCtx<mode> *ctx = new ZCtx<mode>();
ctx->Wrap(args.This());
return args.This();
}

// just pull the ints out of the args and call the other Init
static Handle<Value>
Init(const Arguments& args) {
static Handle<Value> Init(const Arguments& args) {
HandleScope scope;

assert(args.Length() == 4 &&
Expand Down Expand Up @@ -225,12 +221,8 @@ template <node_zlib_mode mode> class ZCtx : public ObjectWrap {
return Undefined();
}

static void
Init(ZCtx *ctx,
int level,
int windowBits,
int memLevel,
int strategy) {
static void Init(ZCtx *ctx, int level, int windowBits, int memLevel,
int strategy) {
ctx->level_ = level;
ctx->windowBits_ = windowBits;
ctx->memLevel_ = memLevel;
Expand Down

0 comments on commit 07701e7

Please sign in to comment.