As long as there are less than 20 open directories, it's perfectly fine
to use a doubly-linked list for name lookup. A singly linked list or
even an array list would have been better, but anyway.
When the number of directories rises above 1000, which happens with
dirdeps.mk, linear list lookup becomes too expensive, especially since
each list entry is compared using a strcmp call, in a callback function
that is not inlined.
Using a hash table is much more efficient than linear lookup. While
here, abstract all operations regarding the openDirectories list into a
new data type that provides a simple and straight-forward API. This
strongly typed API is especially important since the current
implementation of the list and hash table is weakly typed, using void *
for the actual data, and StringList and CachedDirList refer to the
exactly same type, they just have different names to help the human
readers but don't provide any type safety.
Before, the parsing position was updated once at the beginning, which
didn't make sense. Updating it in each branch allows to decide for its
appropriate value in each branch individually.
Cherry-pick and adapt:
From 2a9ce60de98e53198047daaeeec3cf09ece4e693 Mon Sep 17 00:00:00 2001
From: Kamil Rytarowski <n54@gmx.com>
Date: Fri, 2 Oct 2020 16:13:09 +0200
Subject: [PATCH] [compiler-rt] [netbsd] Improve the portability of
ThreadSelfTlsTcb
Use __lwp_gettcb_fast() and __lwp_getprivate_fast(), as _lwp_getprivate()
can be a biased pointer and invalid for use in this function on all CPUs.
That part of the code is long enough and independent enough to get its
own function. Having a struct stat in MainParseArgs just didn't feel
like a correct abstraction level.
The LLVM work is merged mostly to GCC.
The remaining work is not worth tracking here and is restricted mostly to
fixing bugs from various 'make check-*' targets in LLVM.
idea stolen from various other operating systems.
this configurable with a sysctl in case somebody wants to hold the middle
button, e.g. with old window managers that close menus when a button is
released.