Skip to content

Conversation

squeek502
Copy link
Member

Something of a follow-up to #23657, and in particular #23657 (comment) which outlines pretty much exactly the changes made here. Contributes to #23643


  • Deprecates the following with a 2 suffixed replacement (in the future, the 2 suffixed functions will be renamed over top of the deprecated functions):
    • std.fs.Dir.readLinkW -> readLinkW2
    • std.os.windows.ReadLink -> ReadLink2
    • std.os.windows.ntToWin32Namespace -> ntToWin32Namespace2
    • std.posix.readlinkW -> readlinkW2
    • std.posix.readlinkatW -> readlinkatW2

Each of the deprecated functions (except ntToWin32Namespace) took WTF-16 as input and would output WTF-8, which makes optimal buffer re-use difficult at callsites and could force unnecessary WTF-16 <-> WTF-8 conversion during an intermediate step.

The new functions output WTF-16, and also allow for the path and the output to re-use the same buffer (i.e. in-place modification), which can reduce the stack usage at callsites. For example, all of std.fs.Dir.readLink/readLinkZ/std.posix.readlink/readlinkZ/readlinkat/readlinkatZ have had their stack usage reduced by one PathSpace struct (64 KiB) when targeting Windows.

The new ntToWin32Namespace2 takes an output buffer and returns a slice from that instead of returning a PathSpace, which is necessary to make the above possible.

The reasoning in the comment deleted by this commit no longer applies, since that same benefit can be obtained by using OpenFile with `.filter = .any`.

Also removes a stray debug.print
…lers

- Deprecates the following with a `2` suffixed replacement (in the future, the `2` suffixed functions will be renamed over top of the deprecated functions):
  + `std.fs.Dir.readLinkW` -> `readLinkW2`
  + `std.os.windows.ReadLink` -> `ReadLink2`
  + `std.os.windows.ntToWin32Namespace` -> `ntToWin32Namespace2`
  + `std.posix.readlinkW` -> `readlinkW2`
  + `std.posix.readlinkatW` -> `readlinkatW2`

Each of the deprecated functions (except `ntToWin32Namespace`) took WTF-16 as input and would output WTF-8, which makes optimal buffer re-use difficult at callsites and could force unnecessary WTF-16 <-> WTF-8 conversion during an intermediate step.

The new functions output WTF-16, and also allow for the path and the output to re-use the same buffer (i.e. in-place modification), which can reduce the stack usage at callsites. For example, all of `std.fs.Dir.readLink`/`readLinkZ`/`std.posix.readlink`/`readlinkZ`/`readlinkat`/`readlinkatZ` have had their stack usage reduced by one PathSpace struct (64 KiB) when targeting Windows.

The new `ntToWin32Namespace2` takes an output buffer and returns a slice from that instead of returning a PathSpace, which is necessary to make the above possible.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant