Commits

funkybob  committed 172b798

Encoder performance improvements

  • Participants
  • Parent commits 3e49ef9

Comments (0)

Files changed (1)

File gnocchi/ajax/serialiser.py

             FIRST_SEP = ['']
             NEXT_SEP = ','
             if isinstance(obj, basestring):
-                yield '"' + ''.join([ESCAPE_DCT.get(x,x) for x in obj]) + '"'
+                yield '"' + ESCAPE.sub(lambda x: ESCAPE_DCT[x.group(0)], obj) + '"'
             elif obj is None:
                 yield 'null'
             elif obj is True:
                 yield '{'
                 sep = chain(FIRST_SEP, repeat(NEXT_SEP))
                 for key, val in obj.iteritems():
-                    for chunk in chain(sep.next(), _encode(key), [': '], _encode(val)):
+                    yield sep.next()
+                    for chunk in chain( _encode(key), [': '], _encode(val)):
                         yield chunk
                 yield '}'
             elif isinstance(obj, (list, tuple)) or hasattr(obj, '__iter__'):
                 yield '['
                 sep = chain(FIRST_SEP, repeat(NEXT_SEP))
                 for item in obj:
-                    for chunk in chain(sep.next(), _encode(item)):
+                    yield sep.next()
+                    for chunk in _encode(item):
                         yield chunk
                 yield ']'
             else: