From 1fb29c20400a99844306a35414dc24a8fb287ec9 Mon Sep 17 00:00:00 2001 From: Jeff Hill Date: Fri, 21 Feb 2003 00:29:04 +0000 Subject: [PATCH] optimizations suggested by quantify --- src/ca/comQueRecv.h | 54 ++++++++++++++++++-------------------- src/ca/oldSubscription.cpp | 6 ++--- 2 files changed, 29 insertions(+), 31 deletions(-) diff --git a/src/ca/comQueRecv.h b/src/ca/comQueRecv.h index b63c98efc..c2f0ebf59 100644 --- a/src/ca/comQueRecv.h +++ b/src/ca/comQueRecv.h @@ -126,26 +126,25 @@ inline epicsUInt8 comQueRecv::popUInt8 () // optimization here complicates this function somewhat inline epicsUInt16 comQueRecv::popUInt16 () { - comBuf *pComBuf = this->bufs.first (); - if ( ! pComBuf ) { - comBuf::throwInsufficentBytesException (); - } - // try first for all in one buffer efficent version - // (double check here avoids slow C++ exception) - // (hopefully optimizer removes inside check) - epicsUInt16 tmp; - unsigned bytesAvailable = pComBuf->occupiedBytes(); - if ( bytesAvailable >= sizeof (tmp) ) { - tmp = pComBuf->popUInt16 (); - if ( bytesAvailable == sizeof (tmp) ) { - this->removeAndDestroyBuf ( *pComBuf ); + comBuf * pComBuf = this->bufs.first (); + if ( pComBuf ) { + // try first for all in one buffer efficent version + // (double check here avoids slow C++ exception) + // (hopefully optimizer removes inside check) + unsigned bytesAvailable = pComBuf->occupiedBytes(); + if ( bytesAvailable > sizeof ( epicsUInt16 ) ) { + this->nBytesPending -= sizeof ( epicsUInt16 ); + return pComBuf->popUInt16 (); } - this->nBytesPending -= sizeof( tmp ); + else if ( bytesAvailable == sizeof ( epicsUInt16 ) ) { + this->nBytesPending -= sizeof ( epicsUInt16 ); + epicsUInt16 tmp = pComBuf->popUInt16 (); + this->removeAndDestroyBuf ( *pComBuf ); + return tmp; + } + return this->multiBufferPopUInt16 (); } - else { - tmp = this->multiBufferPopUInt16 (); - } - return tmp; + comBuf::throwInsufficentBytesException (); } // optimization here complicates this function somewhat @@ -155,22 +154,21 @@ inline epicsUInt32 comQueRecv::popUInt32 () if ( ! pComBuf ) { comBuf::throwInsufficentBytesException (); } - epicsUInt32 tmp; // try first for all in one buffer efficent version // (double check here avoids slow C++ exception) // (hopefully optimizer removes inside check) unsigned bytesAvailable = pComBuf->occupiedBytes(); - if ( pComBuf->occupiedBytes() >= sizeof (tmp) ) { - tmp = pComBuf->popUInt32 (); - if ( bytesAvailable == sizeof (tmp) ) { - this->removeAndDestroyBuf ( *pComBuf ); - } - this->nBytesPending -= sizeof ( tmp ); + if ( bytesAvailable > sizeof ( epicsUInt32 ) ) { + this->nBytesPending -= sizeof ( epicsUInt32 ); + return pComBuf->popUInt32 (); } - else { - tmp = this->multiBufferPopUInt32 (); + else if ( bytesAvailable == sizeof ( epicsUInt32 ) ) { + this->nBytesPending -= sizeof ( epicsUInt32 ); + epicsUInt32 tmp = pComBuf->popUInt32 (); + this->removeAndDestroyBuf ( *pComBuf ); + return tmp; } - return tmp; + return this->multiBufferPopUInt32 (); } #endif // ifndef comQueRecvh diff --git a/src/ca/oldSubscription.cpp b/src/ca/oldSubscription.cpp index e5de6fa0f..50697872a 100644 --- a/src/ca/oldSubscription.cpp +++ b/src/ca/oldSubscription.cpp @@ -42,9 +42,9 @@ void oldSubscription::current ( struct event_handler_args args; args.usr = this->pPrivate; - args.chid = &this->chan; - args.type = type; - args.count = count; + args.chid = & this->chan; + args.type = static_cast < long > ( type ); + args.count = static_cast < long > ( count ); args.status = ECA_NORMAL; args.dbr = pData; ( *this->pFunc ) ( args );