mirror of
https://github.com/Sarjuuk/aowow.git
synced 2025-11-29 15:58:16 +08:00
Core/Optimization
* avoid using expensive numeric cast for anything but user inputs especially within nested loops * CharStats aggregation should be about x5 faster
This commit is contained in:
@@ -444,10 +444,10 @@ class StatsContainer implements \Countable
|
||||
{
|
||||
if (isset($json[$key])) // 0 is a valid amount!
|
||||
{
|
||||
$float = Stat::getFlags($idx) & Stat::FLAG_FLOAT_VALUE;
|
||||
|
||||
if (Util::checkNumeric($json[$key], $float ? NUM_CAST_FLOAT : NUM_CAST_INT))
|
||||
Util::arraySumByKey($this->store, [$idx => $json[$key]]);
|
||||
if (Stat::getFlags($idx) & Stat::FLAG_FLOAT_VALUE)
|
||||
Util::arraySumByKey($this->store, [$idx => (float)$json[$key]]);
|
||||
else
|
||||
Util::arraySumByKey($this->store, [$idx => (int)$json[$key]]);
|
||||
}
|
||||
|
||||
if ($pruneFromSrc)
|
||||
|
||||
@@ -1696,7 +1696,6 @@ class ItemList extends BaseType
|
||||
|
||||
$json = array(
|
||||
'id' => $this->id,
|
||||
'name' => $this->getField('name', true),
|
||||
'quality' => ITEM_QUALITY_HEIRLOOM - $this->curTpl['quality'],
|
||||
'icon' => $this->curTpl['iconString'],
|
||||
'classs' => $class,
|
||||
@@ -1709,7 +1708,7 @@ class ItemList extends BaseType
|
||||
'level' => $this->curTpl['itemLevel'],
|
||||
'reqlevel' => $this->curTpl['requiredLevel'],
|
||||
'displayid' => $this->curTpl['displayId'],
|
||||
// 'commondrop' => 'true' / null // set if the item is a loot-filler-item .. check common ref-templates..?
|
||||
// 'commondrop' => 'true' / null // set if the item is a loot-filler-item .. check common ref-templates..?
|
||||
'holres' => $this->curTpl['resHoly'],
|
||||
'firres' => $this->curTpl['resFire'],
|
||||
'natres' => $this->curTpl['resNature'],
|
||||
@@ -1729,15 +1728,19 @@ class ItemList extends BaseType
|
||||
'scaflags' => $this->curTpl['scalingStatValue']
|
||||
);
|
||||
|
||||
$json = array_map('intval', $json);
|
||||
|
||||
$json['name'] = $this->getField('name', true);
|
||||
|
||||
if ($class == ITEM_CLASS_AMMUNITION)
|
||||
$json['dps'] = round(($this->curTpl['tplDmgMin1'] + $this->curTpl['dmgMin2'] + $this->curTpl['tplDmgMax1'] + $this->curTpl['dmgMax2']) / 2, 2);
|
||||
else if ($class == ITEM_CLASS_WEAPON)
|
||||
{
|
||||
$json['dmgtype1'] = $this->curTpl['dmgType1'];
|
||||
$json['dmgmin1'] = $this->curTpl['tplDmgMin1'] + $this->curTpl['dmgMin2'];
|
||||
$json['dmgmax1'] = $this->curTpl['tplDmgMax1'] + $this->curTpl['dmgMax2'];
|
||||
$json['dmgtype1'] = (int)$this->curTpl['dmgType1'];
|
||||
$json['dmgmin1'] = (int)($this->curTpl['tplDmgMin1'] + $this->curTpl['dmgMin2']);
|
||||
$json['dmgmax1'] = (int)($this->curTpl['tplDmgMax1'] + $this->curTpl['dmgMax2']);
|
||||
$json['speed'] = round($this->curTpl['delay'] / 1000, 2);
|
||||
$json['dps'] = $json['speed'] ? round(($json['dmgmin1'] + $json['dmgmax1']) / (2 * $json['speed']), 1) : 0;
|
||||
$json['dps'] = $json['speed'] ? round(($json['dmgmin1'] + $json['dmgmax1']) / (2 * $json['speed']), 1) : 0.0;
|
||||
|
||||
if ($this->isRangedWeapon())
|
||||
{
|
||||
@@ -1768,8 +1771,6 @@ class ItemList extends BaseType
|
||||
if (!$v && !in_array($k, ['classs', 'subclass', 'quality', 'side', 'gearscore']))
|
||||
unset($json[$k]);
|
||||
|
||||
Util::checkNumeric($json);
|
||||
|
||||
$this->json[$json['id']] = $json;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -639,7 +639,7 @@ abstract class Util
|
||||
{
|
||||
if (is_array($v))
|
||||
$ref[$k] = [];
|
||||
else if (Util::checkNumeric($v))
|
||||
else if (is_numeric($v))
|
||||
$ref[$k] = 0;
|
||||
else
|
||||
continue;
|
||||
@@ -647,7 +647,7 @@ abstract class Util
|
||||
|
||||
if (is_array($ref[$k]) && is_array($v))
|
||||
Util::arraySumByKey($ref[$k], $v);
|
||||
else if (Util::checkNumeric($ref[$k]) && Util::checkNumeric($v))
|
||||
else if (is_numeric($ref[$k]) && is_numeric($v))
|
||||
$ref[$k] += $v;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user