Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2026-03-31
05:28 • Closed ticket [a382a311e0]: glob on case insentitive sytems not respecting chara... artifact: 7e24f155bc user: apnadkarni
2026-03-30
14:58 • Ticket [a382a311e0]: 3 changes artifact: 59216cd1f8 user: juliannoble2
11:50 • Ticket [a382a311e0]: 3 changes artifact: e5687cbbfe user: apnadkarni
2026-03-28
05:25 • Ticket [a382a311e0]: 3 changes artifact: 633cb4c972 user: juliannoble2
05:02 • Ticket [a382a311e0]: 3 changes artifact: dd5ea83704 user: juliannoble2
04:55 • New ticket [a382a311e0]. artifact: a93954d90a user: juliannoble2

glob on case insentitive sytems not respecting character class case

Closed / Rejecteda382a311e098c19ae3abe371602eb84d7a1e00e6Created 250 days agoUpdated 247 days ago
Descriptionplain2026-03-28 04:55:08
elated but I suspect different to https://core.tcl-lang.org/tcl/tktview/108904173c

An example on windows c:/windows/system32 folder (which is one of the largest default directories on a windows system)

  %llength [glob {[a]*}]
  246
  %llength [glob {[A]*}]
  246
  %llength [glob {[aA]*}]
  246

I have an alternative command fglob that I implemented using twapi that can produce correct results.

  %llength [fglob {[a]*}]
  118
  %llength [fglob {[A]*}]
  128
  %llength [fglob {[aA]*}]
  246

I expect on a case-insensitve system that characters outside either character classes or braced-alternative globs should be case-insensitive, but character classes such as [a-z] [A-Z] should be respect the case of the file as stored on the system - which is clearly possible to do, and at least in the cases I tested - pretty performantly.

As a side note - my wrapper is using tcl script and twapi but no other c code - and is understandably slower on many simple queries such as *, it can outperform the builtin glob on some of the more complex glob queries.
  
  %time {glob {[a]*}}
  9444 microseconds per iteration

  %time {fglob {[aA]*}}
  3164 microseconds per iteration
  %time {fglob {[a]*}}
  1820 microseconds per iteration

This suggests that there may be justification for re-examining the mechanisms being used here - although I don't claim to know all the tradeoffs that could be required to preferably optimise for simple cases.

I would expect my tcl/twapi alternative to be slower in all cases.

The difference is large enough that I don't think it's related to any side issues such as option parsing or checking for vfs etc (which I also do anyway)
My fglob also handles braced expressions (even nested) and generates fairly complex regexps to post-process the result from necessarily broader queries that the underlying windows system accepts (only * and ? globs).

Whilst I haven't set up tests to verify my fglob supports all possible valid globs (e.g processing escaped glob characters in all levels of nesting) the time difference is still a bit suspicious to me, and the simple cases above should be faster regardless of glob expression processing or post-retrieval filtering which I wouldn't expect to dominate.

My time tests are on a modern fast nvme ssd - so I can't suggest that my glob vs fglob timings above are indicative for spinning rust systems, although testing on a mapped network drive from a share on a remote system the fglob version was still significantly faster than glob for those basic character-class queries.
juliannoble2 Ticket [a382a311e0]: 3 changes [History diff]2026-03-28 05:02:28
juliannoble2plain2026-03-28 05:25:55
Just to clarify - the performance thing is really not the point of this.

I believe that once there are more than a handful of character class entries e.g [a-d] my system performs more hits to the the filesystem and use of {choice1,choice2,...} can result in a combinatoric explosion of underlying queries which is slower than just retrieving all and doing only post-filtering.
An optimised system might count the number of queries generated and switch strategies.

It may not be worth further complicating the core glob code just because some intermediate style queries aren't optimal.
apnadkarnimarkdown2026-03-30 11:50:41

I am not sure I agree that glob [a-z] should not match a file called A on case-insensitive systems. As I see it, the glob pattern represents a (potentially infinite) set of strings. The command then should return any file name that matches any of those strings using the case-sensitivity behaviour of the file system.

Regarding performance, while debugging the related bugs, it appeared that traversal to build the internal representation is unnecessarily duplicated at times. I've still not fully grok'ed maintenance of the representation. The other possiblity is that Tcl builds up the internal representation of the file path which twapi does not do. While this is an additional cost in globbing (possibly wasted), it may speed up later operations such as normalization. I wonder how relative performance would look if you normalized the returned paths in both cases.

juliannoble2plain2026-03-30 14:58:09
While I like, and find it occasionally useful that in my system I can differentiate [A-Z] [a-z] etc and was surprised it didn't by default, I can see this isn't necessarily a common expectation.

I had an expectation of what a character in square brackets would match on case-preserving systems where there are sometimes conventions about capitalization of tags in filenames.
The Globbing Patterns section of the docs didn't clarify - but if it's never been raised before I guess it's a minor concern and I'm fine with this being closed. I have my workaround.


You're right, the performance gain is illusory if you have to normalize.
(for all but small result sets)
In my case I'm using it mainly as part of a system for interactive viewing, so am often not normalizing - but then the speed difference is not so important for that sort of application.

I wonder if not normalizing makes a memory difference in a long running session doing lots of listings? Probably not a big concern either unless AI keeps eating all our ram forever.
apnadkarni Closed ticket [a382a311e0]. [History diff]2026-03-31 05:28:29
Log in (anonymous is fine) to add a comment.