-
-
Notifications
You must be signed in to change notification settings - Fork 723
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add new path API for os2
#4954
Add new path API for os2
#4954
Conversation
There are several places where this is assumed to be true, most visibly in `is_path_separator`, as it takes a `byte` argument. Note that the data type of `_Path_Separator` is a rune, which allows any Unicode value.
} | ||
case: | ||
// Copy the path element verbatim and add a separator. | ||
intrinsics.mem_copy_non_overlapping(raw_data(buffer[buffer_i:]), raw_data(elem), len(elem)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason this style isn't used? I know mem_copy_non_overlapping
is going to be faster in this case, but it is a little more noiser.
copy(buffer[buffer_i:], elem)
See all other cases of this too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure about the benefit of intrinsics.mem_copy_non_overlapping
vs copy
. However, everything else looks really really good!
Initially I did this for speed, because I was under the assumption that
|
In order for
os2
to replaceos
,filepath
has to be decoupled from the package. This PR takes care of that by re-writing most of the main part of thecore:path/filepath
API directly intoos2
. (Theglob
-related API will come in a future PR that I want to spend more time testing.)clean
works to not depend on the oldLazy_Buffer
structure and procs.when
statements to keep things cleaner/more modular.split
,base
,short_stem
,ext
,long_ext
, anddir
, we now havesplit_path -> (dir, filename)
andsplit_filename -> (base, ext)
. There is alsosplit_filename_all
to treat the first.
extension separator as the splitting point./usr/share
will split into/usr
andshare
, instead of/usr/
andshare
as was done with thefilepath
API.rel
has also been rewritten. Currently, it is invalid on case-sensitive filesystems (POSIX, for example), as it usesstrings.equal_fold
. The rewritten version no longer automatically runsclean
on the arguments for the sake of performance, and this is documented as an argument requirement.Here is the new API summary. Given that it lives directly inside
os2
, the procedure names have been made verbose enough to outline their path-specific functionality, following in line with the rest ofos2
's procedures being fluently readable.are_paths_identical
compares two paths for exactness (but not equivalency). This is to handle case sensitivity on different platforms.clean_path
replacesfilepath.clean
.is_absolute_path
replacesfilepath.is_abs
.get_absolute_path
replacesfilepath.abs
.get_relative_path
replacesfilepath.rel
.split_path
replacesfilepath.split
,filepath.dir
, andfilepath.base
.join_path
replacesfilepath.join
.split_filename
, when used with the filename result ofsplit_path
, replacesstem
andext
.split_filename_all
, when used with the filename result ofsplit_path
, replacesshort_stem
andlong_ext
.join_filename
complementssplit_filename_*
, as it made sense to me to have a join if we have split.split_path_list
replacesfilepath.split_list
.Note:
split_filename_*
, when given".foo"
will return".foo", ""
instead of"", "foo"
.I reduced the various splitting mechanisms down to just a couple for the sake of clarity and performance, because if someone needs both the name and the extension split, it's easier to just index the separator once and return both sides of the split. You can discard the other if you don't need it.
I'm interested in hearing feedback about this API: if it's sensible and matches expectations, particularly with regard to trimming final separators on split directories and treating dot-prefixed filenames as entire names. It's a convention in the POSIX world that dot-prefixed files are treated as hidden (so it feels more natural to me that it is part of the filename), but I'm not sure how Windows users feel about this particular handling.