Forums / Cotonti / Development / idea: Optimize plugin hook includes

code optimization idea

ez
#1 2011-12-05 12:56

To activate the code from a hook, we always do something like this:

/* === Hook === */
$extp = sed_getextplugins('input');
if (is_array($extp))
{
	foreach($extp as $k => $pl)
	{
		include_once($cfg['plugins_dir'].'/'.$pl['pl_code'].'/'.$pl['pl_file'].'.php');
	}
}
/* ======================== */

 

The function sed_getextplugins itself gets off course the hooks

function sed_getextplugins($hook, $cond='R')
{
	global $sed_plugins, $usr;

	if (is_array($sed_plugins))
	{
		foreach($sed_plugins as $i => $k)
		{
			if($k['pl_hook']==$hook && sed_auth('plug', $k['pl_code'], $cond))
			{
				$extplugins[$i] = $k;
			}
		}
	}
	return $extplugins;
}

 

THE IDEA to speed things up (and this is a just a quick idea i got) to integrate these two parts together in a
new function in functions.php.

function sed_getextplugins_hook_includecode($hook, $cond='R')
{
	global $sed_plugins, $usr, $cfg;

	if (is_array($sed_plugins))
	{
		foreach($sed_plugins as $i => $k)
		{
			if($k['pl_hook']==$hook && sed_auth('plug', $k['pl_code'], $cond))
			{
				$extplugins[$i] = $k;
				// the above line CAN be optional if the return data is needed ????
				include_once($cfg['plugins_dir'].'/'.$k['pl_code'].'/'.$k['pl_file'].'.php');
			}
		}
	}
	return $extplugins;
}

 

Result:

And the call to activate hook includes is just:

/* === Hook === */
$extp = sed_getextplugins_hook_includecode('input');
/* ======================== */

This could save a couple off calls and possible foreach loops. Also the new code looks better :)
I am an optimizing freak... so i always look different @ the code

greetings,
EZ

==- I say: Keep it EZ -==
esclkm
#2 2011-12-05 13:00

include in funtion is very bad Idea - We try in in cotonti 0.7 - but it need to use $_GLOBAL for using variables

So in siena this code optimized

littledev.ru - мой маленький зарождающийся блог о котонти.
снижение стоимости программирования и снижение стоимости производства разные вещи. Первое можно скорее сравнить с раздачей работникам дешевых инструментов, чем со снижением зарплаты
ez
#3 2011-12-05 13:07

@esclkm:
Could you explain more about why this is a bad idea.... ???
 

==- I say: Keep it EZ -==
esclkm
#4 2011-12-05 13:44

try to use vaiables in your code))) no way?

littledev.ru - мой маленький зарождающийся блог о котонти.
снижение стоимости программирования и снижение стоимости производства разные вещи. Первое можно скорее сравнить с раздачей работникам дешевых инструментов, чем со снижением зарплаты
ez
#5 2011-12-05 16:13

Ow.. ok i get it.... forget this post.. it does not work due to wrong variable scope

==- I say: Keep it EZ -==
esclkm
#6 2011-12-05 16:18

you want to rewrite all genoa pluugs?

littledev.ru - мой маленький зарождающийся блог о котонти.
снижение стоимости программирования и снижение стоимости производства разные вещи. Первое можно скорее сравнить с раздачей работникам дешевых инструментов, чем со снижением зарплаты
Twiebie
#7 2011-12-05 18:04
#31905 esclkm:

you want to rewrite all genoa pluugs?

I wouldn't mind it if you did :)

ez
#8 2011-12-05 18:15

I still work a lot in Genoa.... so I am always looking for improvements there....

Sienna ( I am not sure about that yet )... I see a lot off good things, but i doubt some off them... (Not all changes... I think are real improvements)
So I am really wondering where Sienna is going.

What I really would have liked is more good plugins rather then a core rewrite... I would have loved a more gradual core change.

But hey.... its just my thoughts..
 


 

==- I say: Keep it EZ -==