diff options
author | David Lamparter <equinox@opensourcerouting.org> | 2022-10-04 18:01:08 +0200 |
---|---|---|
committer | David Lamparter <equinox@opensourcerouting.org> | 2022-10-06 15:40:06 +0200 |
commit | d40aee771f40b72356eb57d4c9d7bfc2622d9577 (patch) | |
tree | 0a175e23246f89a078d00a3427d0ec7ac47c8ba1 /python | |
parent | build: don't include vtysh.xref in frr.xref (diff) | |
download | frr-d40aee771f40b72356eb57d4c9d7bfc2622d9577.tar.xz frr-d40aee771f40b72356eb57d4c9d7bfc2622d9577.zip |
python: use ujson if available
It's noticeably faster.
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
Diffstat (limited to 'python')
-rw-r--r-- | python/xrelfo.py | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/python/xrelfo.py b/python/xrelfo.py index 3bfe9950d..09455ea9b 100644 --- a/python/xrelfo.py +++ b/python/xrelfo.py @@ -21,7 +21,16 @@ import os import struct import re import traceback -import json + +json_dump_args = {} + +try: + import ujson as json + + json_dump_args["escape_forward_slashes"] = False +except ImportError: + import json + import argparse from clippy.uidhash import uidhash @@ -418,12 +427,12 @@ def _main(args): if args.output: with open(args.output + '.tmp', 'w') as fd: - json.dump(out, fd, indent=2, sort_keys=True) + json.dump(out, fd, indent=2, sort_keys=True, **json_dump_args) os.rename(args.output + '.tmp', args.output) if args.out_by_file: with open(args.out_by_file + '.tmp', 'w') as fd: - json.dump(outbyfile, fd, indent=2, sort_keys=True) + json.dump(outbyfile, fd, indent=2, sort_keys=True, **json_dump_args) os.rename(args.out_by_file + '.tmp', args.out_by_file) if __name__ == '__main__': |