Req #25855 [Opn->Csd]: move stuff out of the loop as much as possible

From: Date: Wed, 18 Feb 2015 07:32:42 +0000
Subject: Req #25855 [Opn->Csd]: move stuff out of the loop as much as possible
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-190766@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=25855&edit=1 ID: 25855 Updated by: krakjoe@php.net Reported by: katsura at apple dot com Summary: move stuff out of the loop as much as possible -Status: Open +Status: Closed Type: Feature/Change Request Package: *General Issues Operating System: Mac OS X 10.3 PHP Version: 4.3.3 -Assigned To: +Assigned To: krakjoe Block user comment: N Private report: N New Comment: This is no longer applicable, we no longer have a frontbase driver in core, and the apache stuff I cannot find. Even if I could have found it, it really would be a micro-optimization that I would not expect to see a real world gain from. Regardless, I'm closing the issue, as 12 years is long enough to wait for nothing to be done ;) Previous Comments: ------------------------------------------------------------------------ [2003-10-13 15:28:17] katsura at apple dot com Description: ------------ 10/13/03 12:14 PM Hidetomo Katsura: apache_mod_php: move stuff out of the loop as much as possible in this example, CFArrayGetCount() gets executed every time it loops: for ( index = 0; index < CFArrayGetCount( array ); ++index ) { value = CFArrayGetValueAtIndex( array, index ); // do something with value } _if_ the count of array does not change in the loop, CFArrayGetCount() only needs to be called once outside of the loop: count = CFArrayGetCount( array ); for ( index = 0; index < count; ++index ) { value = CFArrayGetValueAtIndex( array, index ); // do something with value } % cd ~rc/Updates/Panther/Panther7B85/Projects/ apache_mod_php % grep -rns "for.*;.*Count(.*;" . ------------ apache_mod_php -------------- ./php/ext/fbsql/php_fbsql.c:3512: for (i=0; i<fbaCount(asInfo->infoLines); i++) { NOTE: this bug is not about major performance improvement, and this bug should be the lowest priority. we all know this is a micro optimization and not going to make Mac OS X 100x faster if you just move the "count" function out of the loop. but the point is that you should never write a loop with unnecessary code in it in the first place. this is just a reminder based on something "srcsgrep" found. please fix whenever you have a chance to modify the listed files. thanks. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=25855&edit=1

« previous php.bugs (#190766) next »