Daniel Silverstone pushed to branch danielsilverstone-ct/further-optimisations at BuildStream / buildstream
Commits:
-
23a4e53b
by Daniel Silverstone at 2018-11-06T11:05:34Z
1 changed file:
Changes:
... | ... | @@ -914,9 +914,14 @@ RoundTripRepresenter.add_representer(SanitizedDict, |
914 | 914 |
# Only dicts are ordered, list elements are left in order.
|
915 | 915 |
#
|
916 | 916 |
def node_sanitize(node):
|
917 |
- |
|
918 |
- if isinstance(node, collections.Mapping):
|
|
919 |
- |
|
917 |
+ # Short-circuit None which occurs ca. twice per element
|
|
918 |
+ if node is None:
|
|
919 |
+ return node
|
|
920 |
+ |
|
921 |
+ node_type = type(node)
|
|
922 |
+ if node_type in (str, bool, tuple):
|
|
923 |
+ return node
|
|
924 |
+ if node_type in (dict, ChainMap):
|
|
920 | 925 |
result = SanitizedDict()
|
921 | 926 |
|
922 | 927 |
key_list = [key for key, _ in node_items(node)]
|
... | ... | @@ -925,7 +930,7 @@ def node_sanitize(node): |
925 | 930 |
|
926 | 931 |
return result
|
927 | 932 |
|
928 |
- elif isinstance(node, list):
|
|
933 |
+ elif node_type is list:
|
|
929 | 934 |
return [node_sanitize(elt) for elt in node]
|
930 | 935 |
|
931 | 936 |
return node
|