From: Amos Jeffries Date: Wed, 23 Mar 2011 08:55:43 +0000 (+1200) Subject: ICC: useless code removals X-Git-Tag: take06~27^2~73 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=58c0b17def00feae8c1c74f631f05b375efaef88;p=thirdparty%2Fsquid.git ICC: useless code removals size_t is guaranteed to be >=0 so these checks are useless. Also some optimization of the tunnel and whois comm result handling after the size_t test changes. --- diff --git a/src/tunnel.cc b/src/tunnel.cc index bc27dadf9f..6e1945de0c 100644 --- a/src/tunnel.cc +++ b/src/tunnel.cc @@ -313,7 +313,7 @@ TunnelStateData::copy (size_t len, comm_err_t errcode, int xerrno, Connection &f if (!fd_closed(server.fd())) commSetTimeout(server.fd(), Config.Timeout.read, tunnelTimeout, this); - if (len < 0 || errcode) + if (errcode) from.error (xerrno); else if (len == 0 || fd_closed(to.fd())) { comm_close(from.fd()); @@ -347,12 +347,10 @@ TunnelStateData::writeServerDone(char *buf, size_t len, comm_err_t flag, int xer { debugs(26, 3, "tunnelWriteServer: FD " << server.fd() << ", " << len << " bytes written"); - if (flag == COMM_ERR_CLOSING) - return; - /* Error? */ - if (len < 0 || flag != COMM_OK) { - server.error(xerrno); // may call comm_close + if (flag != COMM_OK) { + if (flag != COMM_ERR_CLOSING) + server.error(xerrno); // may call comm_close return; } @@ -408,12 +406,10 @@ TunnelStateData::writeClientDone(char *buf, size_t len, comm_err_t flag, int xer { debugs(26, 3, "tunnelWriteClient: FD " << client.fd() << ", " << len << " bytes written"); - if (flag == COMM_ERR_CLOSING) - return; - /* Error? */ - if (len < 0 || flag != COMM_OK) { - client.error(xerrno); // may call comm_close + if (flag != COMM_OK) { + if (flag != COMM_ERR_CLOSING) + client.error(xerrno); // may call comm_close return; } diff --git a/src/urn.cc b/src/urn.cc index 8e1c4ad714..c3b95528d5 100644 --- a/src/urn.cc +++ b/src/urn.cc @@ -327,9 +327,9 @@ urnHandleReply(void *data, StoreIOBuffer result) char *buf = urnState->reqbuf; StoreIOBuffer tempBuffer; - debugs(52, 3, "urnHandleReply: Called with size=" << (unsigned int)result.length << "."); + debugs(52, 3, "urnHandleReply: Called with size=" << result.length << "."); - if (EBIT_TEST(urlres_e->flags, ENTRY_ABORTED) || result.length == 0 || result.flags.error < 0) { + if (EBIT_TEST(urlres_e->flags, ENTRY_ABORTED) || result.length == 0 || result.flags.error) { urnHandleReplyError(urnState, urlres_e); return; } diff --git a/src/whois.cc b/src/whois.cc index fc300d3191..f7ef8227c5 100644 --- a/src/whois.cc +++ b/src/whois.cc @@ -139,65 +139,55 @@ WhoisState::setReplyToOK(StoreEntry *sentry) void WhoisState::readReply (int fd, char *aBuffer, size_t aBufferLength, comm_err_t flag, int xerrno) { - int do_next_read = 0; - /* Bail out early on COMM_ERR_CLOSING - close handlers will tidy up for us */ - - if (flag == COMM_ERR_CLOSING) { + if (flag == COMM_ERR_CLOSING) return; - } aBuffer[aBufferLength] = '\0'; debugs(75, 3, "whoisReadReply: FD " << fd << " read " << aBufferLength << " bytes"); debugs(75, 5, "{" << aBuffer << "}"); - if (flag == COMM_OK && aBufferLength > 0) { - if (!dataWritten) - setReplyToOK(entry); - - kb_incr(&statCounter.server.all.kbytes_in, aBufferLength); - - kb_incr(&statCounter.server.http.kbytes_in, aBufferLength); - - /* No range support, we always grab it all */ - dataWritten = true; - - entry->append(aBuffer, aBufferLength); - - entry->flush(); - - do_next_read = 1; - } else if (flag != COMM_OK || aBufferLength < 0) { + if (flag != COMM_OK) { debugs(50, 2, "whoisReadReply: FD " << fd << ": read failure: " << xstrerror() << "."); if (ignoreErrno(errno)) { - do_next_read = 1; + comm_read(fd, aBuffer, BUFSIZ, whoisReadReply, this); } else { ErrorState *err; err = errorCon(ERR_READ_ERROR, HTTP_INTERNAL_SERVER_ERROR, fwd->request); err->xerrno = errno; fwd->fail(err); comm_close(fd); - do_next_read = 0; } - } else { - entry->timestampsSet(); - entry->flush(); - - if (!EBIT_TEST(entry->flags, RELEASE_REQUEST)) - entry->setPublicKey(); + return; + } - fwd->complete(); + if (aBufferLength > 0) { + if (!dataWritten) + setReplyToOK(entry); - debugs(75, 3, "whoisReadReply: Done: " << entry->url() ); + kb_incr(&statCounter.server.all.kbytes_in, aBufferLength); + kb_incr(&statCounter.server.http.kbytes_in, aBufferLength); - comm_close(fd); + /* No range support, we always grab it all */ + dataWritten = true; + entry->append(aBuffer, aBufferLength); + entry->flush(); - do_next_read = 0; + comm_read(fd, aBuffer, BUFSIZ, whoisReadReply, this); + return; } - if (do_next_read) - comm_read(fd, aBuffer, BUFSIZ, whoisReadReply, this); + /* no bytes read. stop reading */ + entry->timestampsSet(); + entry->flush(); + + if (!EBIT_TEST(entry->flags, RELEASE_REQUEST)) + entry->setPublicKey(); + + fwd->complete(); + debugs(75, 3, "whoisReadReply: Done: " << entry->url()); + comm_close(fd); } static void diff --git a/test-suite/debug.cc b/test-suite/debug.cc index 02f5b08a6b..19c7011d02 100644 --- a/test-suite/debug.cc +++ b/test-suite/debug.cc @@ -42,7 +42,7 @@ class StreamTest { public: std::ostream &serialise(std::ostream &); - int const getAnInt() const; + int getAnInt() const; char const *getACString() const; }; @@ -58,7 +58,7 @@ StreamTest::serialise(std::ostream &aStream) return aStream; } -int const +int StreamTest::getAnInt() const { return 5;