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