From 485416d5f121f498c652090a739e4867f16781a0 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Sun, 20 Mar 2016 14:01:29 +0000 Subject: [PATCH] replace create_function with performanter, because opcachable closure --- api/src/Categories.php | 5 ++++- api/src/Db.php | 6 +++++- api/src/Db/Schema.php | 10 ++++++++-- api/src/Etemplate/Widget/Link.php | 14 +++++++++++--- api/src/Vfs.php | 5 ++++- api/src/Vfs/StreamWrapper.php | 5 ++++- 6 files changed, 36 insertions(+), 9 deletions(-) diff --git a/api/src/Categories.php b/api/src/Categories.php index 6dd7e90322..f164c1822a 100644 --- a/api/src/Categories.php +++ b/api/src/Categories.php @@ -811,7 +811,10 @@ class Categories ($cat['appname'] != self::GLOBAL_APPNAME); } // 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']; } diff --git a/api/src/Db.php b/api/src/Db.php index 05ebfac77a..9a3a804f9d 100644 --- a/api/src/Db.php +++ b/api/src/Db.php @@ -2057,7 +2057,11 @@ class Db { $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; } } diff --git a/api/src/Db/Schema.php b/api/src/Db/Schema.php index c98ff92a6e..a528a42883 100644 --- a/api/src/Db/Schema.php +++ b/api/src/Db/Schema.php @@ -1369,7 +1369,10 @@ class Schema { 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; } @@ -1402,7 +1405,10 @@ class Schema } 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']) || $index['unique'] && count(array_intersect($definition['pk'],$index['columns'])) == count($definition['pk']))) diff --git a/api/src/Etemplate/Widget/Link.php b/api/src/Etemplate/Widget/Link.php index 86bf50cac7..ff1599a777 100644 --- a/api/src/Etemplate/Widget/Link.php +++ b/api/src/Etemplate/Widget/Link.php @@ -90,7 +90,8 @@ class Link extends Etemplate\Widget // ToDo: implement on client-side 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']; $id = $value['to_id']; $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 */ - 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']; if(!$options['num_rows']) $options['num_rows'] = 1000; + $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->data($linksc); } diff --git a/api/src/Vfs.php b/api/src/Vfs.php index 9b812ce5e4..f4b1092b4b 100644 --- a/api/src/Vfs.php +++ b/api/src/Vfs.php @@ -360,7 +360,10 @@ class Vfs extends Vfs\StreamWrapper } 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) { diff --git a/api/src/Vfs/StreamWrapper.php b/api/src/Vfs/StreamWrapper.php index 780d824996..cdbe67847e 100644 --- a/api/src/Vfs/StreamWrapper.php +++ b/api/src/Vfs/StreamWrapper.php @@ -1103,7 +1103,10 @@ class StreamWrapper implements StreamWrapperIface self::$symlink_cache[$path] = $target; // 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)); }