From 8168d435535bde5548f4d6027fad50f1fb558005 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Sat, 30 Apr 2022 19:44:50 +0200 Subject: [PATCH] use libyaml-based loader factor 10 faster on my laptop --- python/damask/_config.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/python/damask/_config.py b/python/damask/_config.py index 6dd6a8328..79fa228cc 100644 --- a/python/damask/_config.py +++ b/python/damask/_config.py @@ -6,6 +6,10 @@ from typing import Union, Dict, Any, Type, TypeVar import numpy as np import yaml +try: + from yaml import CSafeLoader as SafeLoader +except ImportError: + from yaml import SafeLoader from ._typehints import FileHandle from . import Rotation @@ -53,7 +57,7 @@ class Config(dict): **kwargs): """Initialize from YAML, dict, or key=value pairs.""" if isinstance(yml,str): - kwargs.update(yaml.safe_load(yml)) + kwargs.update(yaml.load(yml, Loader=SafeLoader)) elif isinstance(yml,dict): kwargs.update(yml) @@ -144,7 +148,7 @@ class Config(dict): Configuration from file. """ - return cls(yaml.safe_load(util.open_text(fname))) + return cls(yaml.load(util.open_text(fname), Loader=SafeLoader)) def save(self, fname: FileHandle,