[perf]for 루프 조건의 count() 호출을 루프 밖으로 추출 (핵심 파일)
for ($i=0; $i<count(\$arr); $i++) 패턴은 매 반복마다 count()를 호출하여 불필요한 CPU 오버헤드를 발생시킴. 루프 전에 한 번만 count()를 계산하여 변수에 저장하는 고전적인 최적화. 적용 파일 (19개, 41곳): - lib/common.lib.php (8) - common.php (2) - lib/shop.lib.php (5) - lib/naverpay.lib.php (1) - lib/thumbnail.lib.php (2) - bbs/list.php (1), bbs/search.php (4), bbs/qalist.php (1), bbs/qawrite.php (1) - bbs/ajax.filter.php (1), bbs/write_update.php (4) - bbs/write_comment_update.php (1), bbs/memo_form_update.php (2) - bbs/new_delete.php (1), bbs/move_update.php (4) - shop/search.php (1), shop/orderform.sub.php (1) - mobile/shop/search.php (1), mobile/shop/orderform.sub.php (1) 부수 효과: - lib/shop.lib.php line 2115: 동일 루프 내 strstr($dlcomp, $company)를 strpos($dlcomp, $company) !== false 로 변경 (strstr 최적화의 일부) 제외: - theme/, skin/, plugin/ (사용자 커스터마이징/서드파티) - lib/PHPExcel/ (서드파티 라이브러리) - adm/ 및 shop/mail/ (관리자/드문 경로, 별도 후속 작업 여지) - 주석 처리된 코드 (bbs/delete.php:127, bbs/delete_all.php:143)
This commit is contained in:
1 parent
29e55de1fa
commit
a612e69d3e
19 files changed
+85
-43
No files matched your search
+11
-6
@@ -1819,7 +1819,8 @@ function get_sendcost($cart_id, $selected=1)
|
||||
$send_cost_limit = explode(";", $default['de_send_cost_limit']);
|
||||
$send_cost_list = explode(";", $default['de_send_cost_list']);
|
||||
$send_cost = 0;
|
||||
for ($k=0; $k<count($send_cost_limit); $k++) {
|
||||
$send_cost_limit_cnt = count($send_cost_limit);
|
||||
for ($k=0; $k<$send_cost_limit_cnt; $k++) {
|
||||
// 총판매금액이 배송비 상한가 보다 작다면
|
||||
if ($total_price < preg_replace('/[^0-9]/', '', $send_cost_limit[$k])) {
|
||||
$send_cost = preg_replace('/[^0-9]/', '', $send_cost_list[$k]);
|
||||
@@ -1894,7 +1895,8 @@ function get_item_sendcost2($it_id, $price, $qty)
|
||||
$send_cost_limit = explode(";", $default['de_send_cost_limit']);
|
||||
$send_cost_list = explode(";", $default['de_send_cost_list']);
|
||||
|
||||
for ($k=0; $k<count($send_cost_limit); $k++) {
|
||||
$send_cost_limit_cnt = count($send_cost_limit);
|
||||
for ($k=0; $k<$send_cost_limit_cnt; $k++) {
|
||||
// 총판매금액이 배송비 상한가 보다 작다면
|
||||
if ($price < preg_replace('/[^0-9]/', '', $send_cost_limit[$k])) {
|
||||
$sendcost = preg_replace('/[^0-9]/', '', $send_cost_list[$k]);
|
||||
@@ -2134,8 +2136,9 @@ function get_delivery_inquiry($company, $invoice, $class='')
|
||||
|
||||
$dlcomp = explode(")", str_replace("(", "", G5_DELIVERY_COMPANY));
|
||||
|
||||
for($i=0; $i<count($dlcomp); $i++) {
|
||||
if(strstr($dlcomp[$i], $company)) {
|
||||
$dlcomp_cnt = count($dlcomp);
|
||||
for($i=0; $i<$dlcomp_cnt; $i++) {
|
||||
if(strpos($dlcomp[$i], $company) !== false) {
|
||||
list($com, $url, $tel) = explode("^", $dlcomp[$i]);
|
||||
break;
|
||||
}
|
||||
@@ -2411,7 +2414,8 @@ function get_delivery_company($company)
|
||||
$option .= '<option value="자체배송" '.get_selected($company, '자체배송').'>자체배송</option>'.PHP_EOL;
|
||||
|
||||
$dlcomp = explode(")", str_replace("(", "", G5_DELIVERY_COMPANY));
|
||||
for ($i=0; $i<count($dlcomp); $i++) {
|
||||
$dlcomp_cnt = count($dlcomp);
|
||||
for ($i=0; $i<$dlcomp_cnt; $i++) {
|
||||
if (trim($dlcomp[$i])=="") continue;
|
||||
list($value, $url, $tel) = explode("^", $dlcomp[$i]);
|
||||
$option .= '<option value="'.$value.'" '.get_selected($company, $value).'>'.$value.'</option>'.PHP_EOL;
|
||||
@@ -2429,7 +2433,8 @@ function get_itemuse_thumb($contents, $thumb_width, $thumb_height, $is_create=fa
|
||||
|
||||
$matches = get_editor_image($contents, false);
|
||||
|
||||
for($i=0; $i<count($matches[1]); $i++)
|
||||
$matches_cnt = count($matches[1]);
|
||||
for($i=0; $i<$matches_cnt; $i++)
|
||||
{
|
||||
// 이미지 path 구함
|
||||
$p = parse_url($matches[1][$i]);
|
||||
|
||||
Reference in new issue
Block a user