feature: improve dict merging speed

This commit is contained in:
UpstreamData
2023-12-12 09:25:43 -07:00
parent dc22df0280
commit 02234f3d1e

View File

@@ -13,8 +13,11 @@
# See the License for the specific language governing permissions and - # See the License for the specific language governing permissions and -
# limitations under the License. - # limitations under the License. -
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
from copy import deepcopy
from dataclasses import asdict, dataclass from dataclasses import asdict, dataclass
import toml
from pyasic.config.fans import FanModeConfig from pyasic.config.fans import FanModeConfig
from pyasic.config.mining import MiningModeConfig from pyasic.config.mining import MiningModeConfig
from pyasic.config.pools import PoolConfig from pyasic.config.pools import PoolConfig
@@ -151,20 +154,11 @@ class MinerConfig:
def merge(a: dict, b: dict) -> dict: def merge(a: dict, b: dict) -> dict:
ret = {} result = deepcopy(a)
for k in a: for b_key, b_val in b.items():
v = a[k] a_val = result.get(b_key)
if k in b.keys(): if isinstance(a_val, dict) and isinstance(b_val, dict):
if isinstance(v, dict): result[b_key] = merge(a_val, b_val)
ret[k] = merge(a[k], b[k])
elif isinstance(v, list):
ret[k] = [*v, *b[k]]
else: else:
ret[k] = v result[b_key] = deepcopy(b_val)
else: return result
ret[k] = v
for k in b:
v = b[k]
if k not in ret.keys():
ret[k] = v
return ret