From 183cce17071a9b40f6aecdca14c9bd0696e7b68d Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Fri, 8 Jun 2012 22:52:08 +0900 Subject: [PATCH] Use bitmask instead of std::vector --- examples/shrpx_io_control.cc | 10 +++++----- examples/shrpx_io_control.h | 7 +++---- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/examples/shrpx_io_control.cc b/examples/shrpx_io_control.cc index 007c39d..3113958 100644 --- a/examples/shrpx_io_control.cc +++ b/examples/shrpx_io_control.cc @@ -30,7 +30,7 @@ namespace shrpx { IOControl::IOControl(bufferevent *bev) : bev_(bev), - ctrlv_(SHRPX_REASON_MAX) + rdbits_(0) {} IOControl::~IOControl() @@ -43,14 +43,14 @@ void IOControl::set_bev(bufferevent *bev) void IOControl::pause_read(IOCtrlReason reason) { - ctrlv_[reason] = 1; + rdbits_ |= reason; bufferevent_disable(bev_, EV_READ); } bool IOControl::resume_read(IOCtrlReason reason) { - ctrlv_[reason] = 0; - if(std::find(ctrlv_.begin(), ctrlv_.end(), 1) == ctrlv_.end()) { + rdbits_ &= ~reason; + if(rdbits_ == 0) { bufferevent_enable(bev_, EV_READ); return true; } else { @@ -60,7 +60,7 @@ bool IOControl::resume_read(IOCtrlReason reason) void IOControl::force_resume_read() { - std::fill(ctrlv_.begin(), ctrlv_.end(), 0); + rdbits_ = 0; bufferevent_enable(bev_, EV_READ); } diff --git a/examples/shrpx_io_control.h b/examples/shrpx_io_control.h index 800c4e7..7395d7c 100644 --- a/examples/shrpx_io_control.h +++ b/examples/shrpx_io_control.h @@ -35,9 +35,8 @@ namespace shrpx { enum IOCtrlReason { - SHRPX_NO_BUFFER = 0, - SHRPX_MSG_BLOCK, - SHRPX_REASON_MAX + SHRPX_NO_BUFFER = 1 << 0, + SHRPX_MSG_BLOCK = 1 << 1 }; class IOControl { @@ -52,7 +51,7 @@ public: void force_resume_read(); private: bufferevent *bev_; - std::vector ctrlv_; + uint32_t rdbits_; }; } // namespace shrpx