Micro optimalizations
Saved 0.015s on various things, mostly thanks to new chibi-core caching
This commit is contained in:
parent
8cfc2aeb2a
commit
306c6478b4
5 changed files with 21 additions and 5 deletions
|
@ -1 +1 @@
|
||||||
Subproject commit 971fba5cb9398f7521c2d8ae33e6bc6a1dbf3400
|
Subproject commit 9653960e235c2c932bce404d3fe8ff4ea3990e08
|
|
@ -20,7 +20,7 @@ class TextHelper
|
||||||
//todo: convert to enum and make one method
|
//todo: convert to enum and make one method
|
||||||
public static function snakeCaseToCamelCase($string, $lower = false)
|
public static function snakeCaseToCamelCase($string, $lower = false)
|
||||||
{
|
{
|
||||||
$string = preg_split('/_/', $string);
|
$string = explode('_', $string);
|
||||||
$string = array_map('trim', $string);
|
$string = array_map('trim', $string);
|
||||||
$string = array_map('ucfirst', $string);
|
$string = array_map('ucfirst', $string);
|
||||||
$string = join('', $string);
|
$string = join('', $string);
|
||||||
|
@ -31,7 +31,7 @@ class TextHelper
|
||||||
|
|
||||||
public static function kebabCaseToCamelCase($string)
|
public static function kebabCaseToCamelCase($string)
|
||||||
{
|
{
|
||||||
$string = preg_split('/-/', $string);
|
$string = explode('-', $string);
|
||||||
$string = array_map('trim', $string);
|
$string = array_map('trim', $string);
|
||||||
$string = array_map('ucfirst', $string);
|
$string = array_map('ucfirst', $string);
|
||||||
$string = join('', $string);
|
$string = join('', $string);
|
||||||
|
|
|
@ -79,9 +79,22 @@ abstract class AbstractCrudModel implements IModel
|
||||||
|
|
||||||
public static function convertRows(array $rows)
|
public static function convertRows(array $rows)
|
||||||
{
|
{
|
||||||
|
$keyCache = [];
|
||||||
|
$entities = [];
|
||||||
foreach ($rows as $i => $row)
|
foreach ($rows as $i => $row)
|
||||||
$rows[$i] = self::convertRow($row);
|
{
|
||||||
return $rows;
|
$entity = self::spawn();
|
||||||
|
foreach ($row as $key => $val)
|
||||||
|
{
|
||||||
|
if (isset($keyCache[$key]))
|
||||||
|
$key = $keyCache[$key];
|
||||||
|
else
|
||||||
|
$key = $keyCache[$key] = TextHelper::snakeCaseToCamelCase($key, true);
|
||||||
|
$entity->$key = $val;
|
||||||
|
}
|
||||||
|
$entities[$i] = $entity;
|
||||||
|
}
|
||||||
|
return $entities;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,9 @@ class PostEntity extends AbstractEntity
|
||||||
public $imageHeight;
|
public $imageHeight;
|
||||||
public $uploaderId;
|
public $uploaderId;
|
||||||
public $source;
|
public $source;
|
||||||
|
public $commentCount;
|
||||||
|
public $favCount;
|
||||||
|
public $score;
|
||||||
|
|
||||||
public function getUploader()
|
public function getUploader()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue