Commit Graph

26 Commits

Author SHA1 Message Date
Fabian Homborg
6af3896217 wcsfilecmp: Stop actually computing the numbers
This just compares two longs as strings on the go.

We can simply

1. ignore leading zeroes - they have no influence on the value
2. compare the digits char-by-char
3. keep the comparison for the first differing digit
4. if one number is longer than the other, that is larger
5. if the numbers have the same length, the one larger in the first
differing digit is larger

This makes this comparison quite a bit faster, which makes globs in
directories with numbered files up to 20% faster.

Note that, for historical reasons, this still ignores whitespace right
after the numbers!
2021-10-07 17:57:52 +02:00
Mahmoud Al-Qudsi
72e50d1ab2 Revert "wcsfilecmp: Don't use iswdigit"
This reverts commit 1ab81ab90d.
2021-10-04 18:08:18 -05:00
Fabian Homborg
1ab81ab90d wcsfilecmp: Don't use iswdigit
For some godforsaken reason it's slow on glibc

Like, actually, this manages to somehow make "echo **" 10% faster now?

The spec says this matches 0 through 9 always, so this is safe. We
also use this logic in a variety of other places already.
2021-10-01 19:14:27 +02:00
Fabian Homborg
78fcbed6f2 wcsfilecmp: Skip towlower/upper if unnecessary
Also for the glob version, because this is just a performance thing.

Makes `echo **` 20% faster - 100ms to 80ms for the fish repo.

This also applies to the future `path` builtin.

Still not a speed demon, but this is a very very easy win.

Now we probably gotta do globbing all in string instead of wcs2stringing ourselves to death.
2021-09-30 18:09:58 +02:00
Rosen Penev
312b575424 [clang-tidy] numeric literals to uppercase
Found with hicpp-uppercase-literal-suffix

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-04-05 10:13:13 +02:00
Fabian Homborg
f053cd27c6 Return glob ordering to pre-3.1 state
Glob ordering is used in a variety of places, including figuring out
conf.d and really needs to be stable.

Other ordering, like completions, is really just cosmetic and can
change if it makes for a nicer experience.

So we uncouple it by copying the wcsfilecmp from 3.0.2, which will
return the ordering to what it was in that release.

Fixes #6593
2020-02-14 19:06:19 +01:00
Rosen Penev
1055ff321c [clang-tidy] Replace NULL with nullptr
Found with modernize-use-nullptr

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2019-11-25 14:23:03 -08:00
ridiculousfish
82eca4bc86 Run clang-format on all files
The main change here is to reorder headers.
2019-10-13 15:50:48 -07:00
David Adam
b5cf9e52ca wcsfilecmp: be clearer about sorting "-" after letters 2019-05-28 22:05:23 +08:00
ridiculousfish
b405b979ec Eliminate the CHECK() macro
This thing was pretty useless.
2019-05-27 17:24:19 -07:00
Fabian Homborg
c2970f9618 Reformat all files
This runs build_tools/style.fish, which runs clang-format on C++, fish_indent on fish and (new) black on python.

If anything is wrong with the formatting, we should fix the tools, but automated formatting is worth it.
2019-05-05 12:09:25 +02:00
Aaron Gyes
6e525cc5d9 wcsfilecmp: sort - after everything else
Before this change, - was sorted with other punctuation before
A-Z. Now, it sorts above the rest of the characters.

This has a practical effect on completions, where when there are
both -s and --long with the same description, the short option
is now before the long option in the pager, which is what is now
selected when navigating `foo -<TAB>`. The long options can be
picked out with `foo --<TAB>`. Before, short options which
duplicated a long option literally could not be selected by
any means from the pager.

Fixes #5634
2019-03-16 01:31:56 -07:00
Aaron Gyes
74a22ff426 wcsfilecmp: punctuation [\]^_` after A-Z.
This tweaks wcsfilecmp such that certain punctuation characters will
come after A-Z.

A big win with `set <TAB>` - the __prefixed fish junk now comes
after the stuff users should care about.
2019-03-16 01:18:16 -07:00
Aaron Gyes
d5ac239f68 This commit changes wchar.h includes to cwchar, and uses std::
for everything it provides.
2019-03-12 15:09:36 -07:00
Alan Somers
0e954e4764 Fix the build on FreeBSD with Clang
NULL expands to nullptr which cannot be cast to an int.  Replace it with
0 in wcsfilecmp.

Fixes issue #4136
2017-06-17 22:51:25 -07:00
Kurtis Rader
0b976a1843 fix wcsfilecmp()
This started out as a refactoring to eliminate the lint warnings. Adding
unit tests revealed the current implementation does not behave as
implied. So this is a complete rewrite of the implementation. With the
addition of unit tests so that it doesn't break in the future and anyone
who thinks this new version behaves wrong can update the unit tests to
help ensure we're testing for the correct behavior.

Fixes #4027
2017-05-19 21:09:07 -07:00
Kurtis Rader
a928517e95 improve converting strings to ints/longs
The existing code is inconsistent, and in a couple of cases wrong, about
dealing with strings that are not valid ints. For example, there are
locations that call wcstol() and check errno without first setting errno
to zero. Normalize the code to a consistent pattern.  This is mostly to
deal with inconsistencies between BSD, GNU, and other UNIXes.

This does make some syntax more liberal. For example `echo $PATH[1 .. 3]`
is now valid due to uniformly allowing leading and trailing whitespace
around numbers. Whereas prior to this change you would get a "Invalid
index value" error. Contrast this with `echo $PATH[ 1.. 3 ]` which was
valid and still is.
2016-11-25 18:52:15 -08:00
Kurtis Rader
42458ff7ab lint: "collapsible if statements" warnings 2016-10-22 19:09:40 -07:00
Kurtis Rader
00303ed07f lint cleanup: parameter reassignment 2016-10-20 18:53:31 -07:00
Kurtis Rader
5bf1b0e5f5 fix random lint issues
This only eliminates errors reported by `make lint`. It shouldn't cause any
functional changes.

This change does remove several functions that are unused. It also removes the
`desc_arr` variable which is both unused and out of date with reality.
2016-05-29 22:24:29 -07:00
David Adam
9225b16d12 add (or restore) config.h to all files
The autoconf-generated config.h contains a number of directives which
may alter the behaviour of system headers on certain platforms. Always
include it in every C++ file as the first include.

Closes #2993.
2016-05-18 22:30:21 +00:00
Kurtis Rader
79f342b954 lint cleanup: eliminate "redundant" errors
This removes some pointless parentheses but the primary focus is removing
redundancies like unnecessary "else" clauses.
2016-05-04 15:32:04 -07:00
Kurtis Rader
5c8763be0e restyle remaining modules to match project style
For this change I decided to bundle the remaining modules that need to be
resytyled because only two were large enough to warrant doing on their own.

Reduces lint errors from 225 to 162 (-28%). Line count from 3073 to 2465 (-20%).

Another step in resolving issue #2902.
2016-05-03 16:09:45 -07:00
Kurtis Rader
1f06e5f0b9 add better support for IWYU and fix things
Remove the "make iwyu" build target. Move the functionality into the
recently introduced lint.fish script. Fix a lot, but not all, of the
include-what-you-use errors. Specifically, it fixes all of the IWYU errors
on my OS X server but only removes some of them on my Ubuntu 14.04 server.

Fixes #2957
2016-04-26 15:02:22 -07:00
ridiculousfish
871a822379 Remove some dead #defines 2015-08-11 01:00:05 -07:00
ridiculousfish
b4f53143b0 Migrate source files into src/ directory
This change moves source files into a src/ directory,
and puts object files into an obj/ directory. The Makefile
and xcode project are updated accordingly.

Fixes #1866
2015-07-24 00:59:27 -07:00