Mercurial > hg
view contrib/casesmash.py @ 31020:2d1bf84046f6
smartset: use native set operations as fast paths
For set operations like "&" and "-", where we know both basesets have their
sets ready, and the first set is sorted, use the native Python set
operations as a fast path.
Note: "+" is not optimized as that will break the ordering.
This leads to noticeable improvements on performance:
revset | before | after | delta
----------------------------------------------------------------
draft() & draft() & draft() & draft() | 776 | 477 | -39%
draft() + draft() + draft() + draft() | 2849 | 2864 |
draft() - draft() + draft() - draft() | 943 | 240 | -75%
draft() - draft() - draft() - draft() | 557 | 197 | -64%
(time measured in microseconds)
author | Jun Wu <quark@fb.com> |
---|---|
date | Sat, 18 Feb 2017 17:23:43 -0800 |
parents | 42a7301fb4d5 |
children | 2372284d9457 |
line wrap: on
line source
from __future__ import absolute_import import __builtin__ import os from mercurial import ( util, ) def lowerwrap(scope, funcname): f = getattr(scope, funcname) def wrap(fname, *args, **kwargs): d, base = os.path.split(fname) try: files = os.listdir(d or '.') except OSError: files = [] if base in files: return f(fname, *args, **kwargs) for fn in files: if fn.lower() == base.lower(): return f(os.path.join(d, fn), *args, **kwargs) return f(fname, *args, **kwargs) scope.__dict__[funcname] = wrap def normcase(path): return path.lower() os.path.normcase = normcase for f in 'file open'.split(): lowerwrap(__builtin__, f) for f in "chmod chown open lstat stat remove unlink".split(): lowerwrap(os, f) for f in "exists lexists".split(): lowerwrap(os.path, f) lowerwrap(util, 'posixfile')