replace create_function with performanter, because opcachable closure

This commit is contained in:
Ralf Becker 2016-03-20 14:01:29 +00:00
parent 4da844a70f
commit 485416d5f1
6 changed files with 36 additions and 9 deletions

View File

@ -811,7 +811,10 @@ class Categories
($cat['appname'] != self::GLOBAL_APPNAME); ($cat['appname'] != self::GLOBAL_APPNAME);
} }
// sort heighest weight to the top // sort heighest weight to the top
usort($cats,create_function('$a,$b',"return \$b['weight'] - \$a['weight'];")); usort($cats, function($a, $b)
{
return $b['weight'] - $a['weight'];
});
} }
return $cache[$cat['cat_name']] = (int) $cats[0]['id']; return $cache[$cat['cat_name']] = (int) $cats[0]['id'];
} }

View File

@ -2057,7 +2057,11 @@ class Db
{ {
$keys = array_keys($arr); $keys = array_keys($arr);
return array_walk($keys,create_function('&$v,$k,$strip','$v = str_replace($strip,\'\',$v);'),$strip) ? return array_walk($keys, function(&$v, $k, $strip)
{
unset($k); // not used, but required by function signature
$v = str_replace($strip, '', $v);
}, $strip) ?
array_combine($keys,$arr) : $arr; array_combine($keys,$arr) : $arr;
} }
} }

View File

@ -1369,7 +1369,10 @@ class Schema
{ {
if($this->capabilities['name_case'] == 'upper') if($this->capabilities['name_case'] == 'upper')
{ {
array_walk($primary,create_function('&$s','$s = strtolower($s);')); array_walk($primary, function(&$s)
{
$s = strtolower($s);
});
} }
$definition['pk'] = $primary; $definition['pk'] = $primary;
} }
@ -1402,7 +1405,10 @@ class Schema
} }
if($this->capabilities['name_case'] == 'upper') if($this->capabilities['name_case'] == 'upper')
{ {
array_walk($index['columns'],create_function('&$s','$s = strtolower($s);')); array_walk($index['columns'], function(&$s)
{
$s = strtolower($s);
});
} }
if (count($definition['pk']) && (implode(':',$definition['pk']) == implode(':',$index['columns']) || if (count($definition['pk']) && (implode(':',$definition['pk']) == implode(':',$index['columns']) ||
$index['unique'] && count(array_intersect($definition['pk'],$index['columns'])) == count($definition['pk']))) $index['unique'] && count(array_intersect($definition['pk'],$index['columns'])) == count($definition['pk'])))

View File

@ -90,7 +90,8 @@ class Link extends Etemplate\Widget
// ToDo: implement on client-side // ToDo: implement on client-side
if (!$attrs['help']) self::setElementAttribute($form_name, 'help', 'view this linked entry in its application'); if (!$attrs['help']) self::setElementAttribute($form_name, 'help', 'view this linked entry in its application');
if($attrs['type'] == 'link-list') { if($attrs['type'] == 'link-list')
{
$app = $value['to_app']; $app = $value['to_app'];
$id = $value['to_id']; $id = $value['to_id'];
$links = Api\Link::get_links($app,$id,'','link_lastmod DESC',true, $value['show_deleted']); $links = Api\Link::get_links($app,$id,'','link_lastmod DESC',true, $value['show_deleted']);
@ -103,11 +104,18 @@ class Link extends Etemplate\Widget
/** /**
* Find links that match the given parameters * Find links that match the given parameters
*/ */
public static function ajax_link_search($app, $type, $pattern, $options=array()) { public static function ajax_link_search($app, $type, $pattern, $options=array())
{
$options['type'] = $type ? $type : $options['type']; $options['type'] = $type ? $type : $options['type'];
if(!$options['num_rows']) $options['num_rows'] = 1000; if(!$options['num_rows']) $options['num_rows'] = 1000;
$links = Api\Link::query($app, $pattern, $options); $links = Api\Link::query($app, $pattern, $options);
$linksc = array_combine(array_map(create_function('$k', 'return (string)" ".$k;'), array_keys($links)), $links);
$linksc = array_combine(array_map(function($k)
{
return (string)$k;
}, array_keys($links)), $links);
$response = Api\Json\Response::get(); $response = Api\Json\Response::get();
$response->data($linksc); $response->data($linksc);
} }

View File

@ -360,7 +360,10 @@ class Vfs extends Vfs\StreamWrapper
} }
self::$fstab[$path] = $url; self::$fstab[$path] = $url;
uksort(self::$fstab,create_function('$a,$b','return strlen($a)-strlen($b);')); uksort(self::$fstab, function($a, $b)
{
return strlen($a) - strlen($b);
});
if ($persitent_mount) if ($persitent_mount)
{ {

View File

@ -1103,7 +1103,10 @@ class StreamWrapper implements StreamWrapperIface
self::$symlink_cache[$path] = $target; self::$symlink_cache[$path] = $target;
// sort longest path first // sort longest path first
uksort(self::$symlink_cache,create_function('$b,$a','return strlen($a)-strlen($b);')); uksort(self::$symlink_cache, function($b, $a)
{
return strlen($a) - strlen($b);
});
if (self::LOG_LEVEL > 1) error_log(__METHOD__."($path,$target) cache now ".array2string(self::$symlink_cache)); if (self::LOG_LEVEL > 1) error_log(__METHOD__."($path,$target) cache now ".array2string(self::$symlink_cache));
} }