Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!news.musoftware.de!wum.musoftware.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Ian Collins Newsgroups: comp.lang.c++ Subject: Re: Thoughts on function Date: Mon, 19 Sep 2011 09:34:12 +1200 Lines: 58 Message-ID: <9dn6ekFr5dU8@mid.individual.net> References: <19d88541-0f1e-4fa5-90dd-9ff8c23046f3@19g2000vbx.googlegroups.com> <9ddfi0F784U12@mid.individual.net> <85a545df-d6b9-4e67-9570-4d2aab13b8c3@f41g2000yqh.googlegroups.com> <9df2i4F2gmU11@mid.individual.net> <0d205a4f-b6d5-494e-baf1-b5add2798806@o9g2000vbo.googlegroups.com> <880af656-7aaf-4e4c-baa8-91ae77d541e4@f41g2000yqh.googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net eHC/NPXb8ds4PwJhOEkSqQciSau0MrbreveG4NJkjxtkRDBu2Z Cancel-Lock: sha1:BQZteBpaTf/bu3KtFuEUkD1UhpM= User-Agent: Mozilla/5.0 (X11; U; SunOS i86pc; en-US; rv:1.9.2.9) Gecko/20101021 Lightning/1.0b2 Thunderbird/3.1.4 In-Reply-To: <880af656-7aaf-4e4c-baa8-91ae77d541e4@f41g2000yqh.googlegroups.com> Xref: x330-a1.tempe.blueboxinc.net comp.lang.c++:10258 On 09/19/11 08:30 AM, Ebenezer wrote: > On Sep 15, 7:23 pm, Ebenezer wrote: >> >> I started by asking for ideas on how to improve it. >> Perhaps someone would show what they believe to be >> an improvement. I realized after thinking about >> your earlier comments that the member variable >> partialFlush could be a static local variable. >> >> bool >> SendBuffer::Flush () >> { >> uint32_t const all = buf_.size(); >> uint32_t numWritten = 0; >> static bool partialFlush = false; >> if (partialFlush) { >> ::neolib::segmented_array::segment& >> segment = >> segmented_iterator> chunk_size>(buf_.begin()).segment(); >> >> numWritten = Write(sock_,&buf_[0], segment.size()); >> if (numWritten< segment.size()) goto ending; >> partialFlush = false; >> } >> >> { >> int32_t const chunks = (all - numWritten) / chunk_size; >> for (int32_t ii = 0; ii< chunks; ++ii) { >> uint32_t bytes = Write(sock_,&buf_[numWritten], chunk_size); >> numWritten += bytes; >> if (bytes< chunk_size) goto ending; >> } >> } >> >> if (numWritten< all) { >> numWritten += Write(sock_,&buf_[numWritten], all - numWritten); >> } >> >> ending: >> buf_.erase(buf_.begin(), buf_.begin() + numWritten); >> if (numWritten == all) return true; >> >> partialFlush = true; >> return false; >> } > > > How would you rate this function -- with a 1 being terrible > and a 10 being excellent? You don't appear to have headed any of the suggestions. At review, I'd still give it a 1 because it isn't clear what it does, why it uses fixed width types and it still contains gratuitous gotos. -- Ian Collins