Archive - Aug 1, 2007 - Blog entry

Date
  • All
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31

More on Loops--Fusion and Unwinding

I wonder why it's not fusion and defusion...
Loop fusion should be a very common thing in PHP programming.
For example, 2 arrays;

for($i= 0;$i<30;++$i){
	$a[$i]++;
}
for($i = 0;$i<30;++$i){
	$b[$i]++;
}

FUSION!!!
for($i = 0l $i<30; ++$i){
	$a[$i]++;
	$b[$i]++;
}

On the other hand, loop unwinding is rarely seen in PHP.
Unwinding is to reduce the loop overhead by hand code the next few loop into the system.
For example
for($i=0;$i<101;++$i){
echo $i;
}

unwind
for($i=0;$i<101;$i+=4){
echo $i;
echo $i+1;
echo $i+2;
echo $i+3;
}

This technique is proven to have some speed gain, but, unwind is not all powerful, it comes with a cost.
For example, your code will be longer, and harder to read.
and, the unwinding require to have some previous knowledge about the loop. If the loop above is for 100 times instead of 101 times, the 2nd one will output 4 less items.
Even though it is possible to treat this by find the remain ones and use another loop to loop it though, but this make the code more complex than it should.

Site Upgrade to Drupal 5.2

Today I have successfully updated my site to Drupal 5.2. It's recommend everyone with Drupal 5.1 do the same thing. Multiple XSS possibilities are erased. The entire upgrade took me one hour. include downloading everything I need like Filezilla.(i'm using someone else's computer). Everything was fine, until I found my sessions got destroyed. Because I locked my site, so no one other than the admin can access, so I was blocked out. The smart Drupal allow me to login though the account page. Try go to http://yourdomain.com/user if you stuck in the same situation.

Honey Pot that kill bots