Closed (works as designed)
Project:
Ubercart Restrict Qty
Version:
6.x-1.1
Component:
Code
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
28 Dec 2009 at 02:32 UTC
Updated:
20 Jan 2010 at 05:15 UTC
Hey, in uc_restrict_qty.module, there is one major inefficient loop. Looking at the uc_restrict_qty_form_alter() function, the following exists:
...
for ($i = 0, $j = count(uc_cart_get_contents()); $i < $j; $i++) {
...
}
The uc_cart_get_contents() function will be executed every time that loop occurs, and is very inefficient. It should probably be changed to:
...
$total = count(uc_cart_get_contents());
for ($i = 0, $j = $total; $i < $j; $i++) {
...
}
A patch is attached to make it a little easier :)
| Comment | File | Size | Author |
|---|---|---|---|
| uc_restrict_qty.patch | 673 bytes | mbelos |
Comments
Comment #1
rszrama commentedActually, notice that I'm instantiating $j in the first parameter of that for loop. Those instructions are only executed once, meaning that at the start of the loop $i will be set to 0 and $j to the number of items in the cart. After that, the second parameter will perform the evaluation of $i < $j. The code is optimal as is. : )
Comment #2
mbelos commentedAh I see now, was a bit too quick on the trigger there! My apologies :)