From: Ben Pfaff Date: Wed, 24 Aug 2011 19:05:13 +0000 (-0700) Subject: ovs.json: Optimize __dump_string(). X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e0b2332760c97b8dbe6fdd89e18634a7e8f8050e;p=openvswitch ovs.json: Optimize __dump_string(). Suggested-by: Reid Price --- diff --git a/python/ovs/json.py b/python/ovs/json.py index 67470fcb..97ff1bbd 100644 --- a/python/ovs/json.py +++ b/python/ovs/json.py @@ -28,15 +28,7 @@ for i in range(32): escapes[i] = u"\\u%04x" % i def __dump_string(stream, s): - stream.write(u"\"") - for c in s: - x = ord(c) - escape = escapes.get(x) - if escape: - stream.write(escape) - else: - stream.write(c) - stream.write(u"\"") + stream.write(u'"%s"' % ''.join(escapes.get(ord(c), c) for c in s)) def to_stream(obj, stream, pretty=False, sort_keys=True): if obj is None: