]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
ICC: useless code removals
authorAmos Jeffries <squid3@treenet.co.nz>
Wed, 23 Mar 2011 08:55:43 +0000 (20:55 +1200)
committerAmos Jeffries <squid3@treenet.co.nz>
Wed, 23 Mar 2011 08:55:43 +0000 (20:55 +1200)
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.

src/tunnel.cc
src/urn.cc
src/whois.cc
test-suite/debug.cc

index bc27dadf9f9f0ed1b6401de12a8e0d57854165a5..6e1945de0c30d92709b26b88b3fb37422633f11d 100644 (file)
@@ -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;
     }
 
index 8e1c4ad7145bf5009ec876ca79c37e6228a2feac..c3b95528d5257421fc95f997eaf3bd8a2453f4b0 100644 (file)
@@ -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;
     }
index fc300d3191d28bddf62ccdea10434d372eaa2e5c..f7ef8227c51cb75976077918ac99ed2f836034cb 100644 (file)
@@ -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
index 02f5b08a6b1f68c9fab94c8c018cca5048472d0a..19c7011d02c7e704c9393f3da2938ea826cb93e9 100644 (file)
@@ -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;