[PATCH] cat: increase perf when catting without patterns

Martin Geisler martin at geisler.net
Sat Jan 11 15:10:54 CST 2014


Durham Goode <durham at fb.com> writes:

> # HG changeset patch
> # User Durham Goode <durham at fb.com>
> # Date 1389405865 28800
> #      Fri Jan 10 18:04:25 2014 -0800
> # Node ID c4d55205c7d81950d631debed3c044c82e87cbd9
> # Parent  d2704c48f4176d8cd6f21d33500820d44763585c
> cat: increase perf when catting without patterns
>
> +    files = set(m.files())
> +    files.discard('.')
> +    if files and not m.anypats():
> +        for file in sorted(list(files)):

The sorted builtin works on sets too, so I don't think you need to turn
the set into a list first.

> +            try:
> +                write(file)
> +                err = 0
> +            except error.ManifestLookupError:
> +                # It's significantly cheaper to catch the exception than it
> +                # is to do a 'file in ctx' check, due to makefileobj using
> +                # manifest.find instead of manifest.read
> +                m.bad(file, _('no such file in rev %s') % ctx)
> +    else:
> +        for abs in ctx.walk(m):
> +            write(abs)
> +            err = 0

Would ctx.walk be able to have this "if files and no m.anypats()" logic
built-in? That is, could you push the if-statement into that method and
let more callers benefit?

-- 
Martin Geisler


More information about the Mercurial-devel mailing list