From 5c3fc4840c6c5729b7144b8f268990684f151b12 Mon Sep 17 00:00:00 2001 From: Cesar G Date: Thu, 27 Feb 2014 19:29:02 -0800 Subject: [ticket/12232] Remove excessive calls to sizeof() in assign_block_vars() method The size of the template block array is calculated within a foreach loop iterating through the array, which is unnecessary. It only needs to be done once. In a block of 1000 rows, this results in 500,500 calls to sizeof() in this location. With this change, that's reduced to 1000. PHPBB3-12232 --- phpBB/phpbb/template/context.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'phpBB/phpbb') diff --git a/phpBB/phpbb/template/context.php b/phpBB/phpbb/template/context.php index 65c7d094a0..ef01034c52 100644 --- a/phpBB/phpbb/template/context.php +++ b/phpBB/phpbb/template/context.php @@ -186,11 +186,12 @@ class context // Add a new iteration to this block with the variable assignments we were given. $this->tpldata[$blockname][] = $vararray; + $s_num_rows = sizeof($this->tpldata[$blockname]); // Set S_NUM_ROWS foreach ($this->tpldata[$blockname] as &$mod_block) { - $mod_block['S_NUM_ROWS'] = sizeof($this->tpldata[$blockname]); + $mod_block['S_NUM_ROWS'] = $s_num_rows; } } -- cgit v1.2.1 From 99db2d91996c9beb40ff9b635c69497941a69ffb Mon Sep 17 00:00:00 2001 From: Cesar G Date: Thu, 27 Feb 2014 22:27:09 -0800 Subject: [ticket/12232] Fix a similar excessive pattern in the method. PHPBB3-12232 --- phpBB/phpbb/template/context.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'phpBB/phpbb') diff --git a/phpBB/phpbb/template/context.php b/phpBB/phpbb/template/context.php index ef01034c52..0b929f4934 100644 --- a/phpBB/phpbb/template/context.php +++ b/phpBB/phpbb/template/context.php @@ -155,11 +155,12 @@ class context // We're adding a new iteration to this block with the given // variable assignments. $str[$blocks[$blockcount]][] = $vararray; + $s_num_rows = sizeof($str[$blocks[$blockcount]]); // Set S_NUM_ROWS foreach ($str[$blocks[$blockcount]] as &$mod_block) { - $mod_block['S_NUM_ROWS'] = sizeof($str[$blocks[$blockcount]]); + $mod_block['S_NUM_ROWS'] = $s_num_rows; } } else -- cgit v1.2.1