On Nov 11, 9:22*am, "Tree*Rat" <tree....@googlemail.comwrote:
Quote:
Trying to reduce alot of my codes size and am having no joy with this
code. How can I get this smaller?
>
// Block
$prefix_length = strlen( PREFIX_BLOCKS );
>
$block_dir = @opendir($root_path . 'modules/modules_blocks');
while( false !== ($dir_name = readdir($block_dir)) )
{
* * * * if( $dir_name != "." && $dir_name != ".." )
* * * * {
* * * * * * * * if ( substr( $dir_name, 0, $prefix_length) == PREFIX_BLOCKS
)
* * * * * * * * {
* * * * * * * * * * * * if( is_dir( $root_path . 'modules/modules_blocks/' .
$dir_name))
* * * * * * * * * * * * {
* * * * * * * * * * * * * * * * $mod_list_blocks[] = $dir_name;
* * * * * * * * * * * * }
* * * * * * * * }
* * * * }}
>
@closedir( $block_dir );
>
// Page
$prefix_length = strlen( PREFIX_PAGES );
>
$page_dir = @opendir($root_path . 'modules/modules_page');
while( false !== ($dir_name = readdir($page_dir)) )
{
* * * * if( $dir_name != "." && $dir_name != ".." )
* * * * {
* * * * * * * * if ( substr( $dir_name, 0, $prefix_length) == PREFIX_PAGES
)
* * * * * * * * {
* * * * * * * * * * * * if( is_dir( $root_path . 'modules/modules_page/' .
$dir_name))
* * * * * * * * * * * * {
* * * * * * * * * * * * * * * * $mod_list_page[] = $dir_name;
* * * * * * * * * * * * }
* * * * * * * * }
* * * * }}
>
@closedir( $page_dir );
>
// Admin
$prefix_length = strlen( PREFIX_ADMIN );
>
$admin_dir = @opendir($root_path . 'modules/modules_admin');
while( false !== ($dir_name = readdir($page_dir)) )
{
* * * * if( $dir_name != "." && $dir_name != ".." )
* * * * {
* * * * * * * * if ( substr( $dir_name, 0, $prefix_length) == PREFIX_ADMIN
)
* * * * * * * * {
* * * * * * * * * * * * if( is_dir( $root_path . 'modules/modules_admin/' .
$dir_name))
* * * * * * * * * * * * {
* * * * * * * * * * * * * * * * $mod_list_admin[] = $dir_name;
* * * * * * * * * * * * }
* * * * * * * * }
* * * * }}
>
@closedir( $admin_dir );
>
big thanks
The size of a piece of PHP code has no bearing on its performance.
Keeping code readable is far more important. If you hare having
performance issues that would suggest you have picked an incorrect
algorithm or have implemented it in a suboptimal way. If this is the
case then there is far more to be gained by looking into what your
code is doing and how it works rather than how it is written.