This is an archive of the discontinued Mercurial Phabricator instance.

util: use set for reserved Windows filenames
ClosedPublic

Authored by indygreg on Aug 31 2017, 10:42 PM.

Details

Summary

Previously, we were performing membership testing against a
list. Change it to a set for a minor perf win. While we're at it,
explode the assignment in place so less work is needed at module
import time.

Diff Detail

Repository
rHG Mercurial
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

indygreg created this revision.Aug 31 2017, 10:42 PM
quark accepted this revision.Sep 1 2017, 1:37 PM
quark added a subscriber: quark.

LGTM. Maybe include some timing data in commit message:

In [3]: _winreservednames = b'''con prn aux nul
   ...:     com1 com2 com3 com4 com5 com6 com7 com8 com9
   ...:     lpt1 lpt2 lpt3 lpt4 lpt5 lpt6 lpt7 lpt8 lpt9'''.split()
   ...: 

In [4]: %timeit 'lpt9' in _winreservednames
The slowest run took 6.61 times longer than the fastest. This could mean that an intermediate result is being cached.
1000000 loops, best of 3: 288 ns per loop

In [5]: %timeit 'con' in _winreservednames
The slowest run took 42.41 times longer than the fastest. This could mean that an intermediate result is being cached.
10000000 loops, best of 3: 45 ns per loop

In [6]: _winreservednames=set(_winreservednames)

In [7]: %timeit 'con' in _winreservednames
The slowest run took 28.03 times longer than the fastest. This could mean that an intermediate result is being cached.
10000000 loops, best of 3: 42.5 ns per loop

In [8]: %timeit 'lpt9' in _winreservednames
10000000 loops, best of 3: 39.3 ns per loop
In D600#9766, @quark wrote:

LGTM. Maybe include some timing data in commit message:

In [3]: _winreservednames = b'''con prn aux nul
   ...:     com1 com2 com3 com4 com5 com6 com7 com8 com9
   ...:     lpt1 lpt2 lpt3 lpt4 lpt5 lpt6 lpt7 lpt8 lpt9'''.split()
   ...: 
In [4]: %timeit 'lpt9' in _winreservednames
The slowest run took 6.61 times longer than the fastest. This could mean that an intermediate result is being cached.
1000000 loops, best of 3: 288 ns per loop
In [5]: %timeit 'con' in _winreservednames
The slowest run took 42.41 times longer than the fastest. This could mean that an intermediate result is being cached.
10000000 loops, best of 3: 45 ns per loop
In [6]: _winreservednames=set(_winreservednames)
In [7]: %timeit 'con' in _winreservednames
The slowest run took 28.03 times longer than the fastest. This could mean that an intermediate result is being cached.
10000000 loops, best of 3: 42.5 ns per loop
In [8]: %timeit 'lpt9' in _winreservednames
10000000 loops, best of 3: 39.3 ns per loop

The most relevant test is probably "'not-reserved' in _winreservednames" (which is probably close to the 'lpt9' test).

This revision was automatically updated to reflect the committed changes.