php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #25855 move stuff out of the loop as much as possible
Submitted: 2003-10-13 15:28 UTC Modified: 2015-02-18 07:32 UTC
From: katsura at apple dot com Assigned: krakjoe (profile)
Status: Closed Package: *General Issues
PHP Version: 4.3.3 OS: Mac OS X 10.3
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: katsura at apple dot com
New email:
PHP Version: OS:

 

 [2003-10-13 15:28 UTC] 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.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-02-18 07:30 UTC] krakjoe@php.net
-Package: Feature/Change Request +Package: *General Issues
 [2015-02-18 07:32 UTC] krakjoe@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: krakjoe
 [2015-02-18 07:32 UTC] krakjoe@php.net
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 ;)
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 16 09:01:33 2025 UTC