tests/heredoctest.py
author Pierre-Yves David <pierre-yves.david@fb.com>
Thu, 18 Sep 2014 15:52:45 -0700
changeset 22669 00c8abe64cf3
parent 22565 8d45a42b0c0f
child 25032 1db2127d2373
permissions -rw-r--r--
revset: prefetch an attribute in _generatorset.__iter__ Python's attribute lookup are expensible, lets do less of them. This gives us a 7% speedup on this revset iteration (from 0.063403 to 0.059032)

import sys

globalvars = {}
lines = sys.stdin.readlines()
while lines:
    l = lines.pop(0)
    if l.startswith('SALT'):
        print l[:-1]
    elif l.startswith('>>> '):
        snippet = l[4:]
        while lines and lines[0].startswith('... '):
            l = lines.pop(0)
            snippet += l[4:]
        c = compile(snippet, '<heredoc>', 'single')
        try:
            exec c in globalvars
        except Exception, inst:
            print repr(inst)