Skip to content
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

Memoize cwstring when used for env lookup / modification on Windows #51371

Merged
merged 9 commits into from
Nov 27, 2023
4 changes: 3 additions & 1 deletion base/env.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ if Sys.iswindows()
_hasenv(s::Vector{UInt16}) = _getenvlen(s) != 0 || Libc.GetLastError() != ERROR_ENVVAR_NOT_FOUND
_hasenv(s::AbstractString) = _hasenv(cwstring(s))

const JULIA_DEBUG_CWSTRING = cwstring("JULIA_DEBUG")
vtjnash marked this conversation as resolved.
Show resolved Hide resolved

function access_env(onError::Function, str::AbstractString)
var = cwstring(str)
var = str == "JULIA_DEBUG" ? JULIA_DEBUG_CWSTRING : cwstring(str)
len = _getenvlen(var)
if len == 0
vtjnash marked this conversation as resolved.
Show resolved Hide resolved
return Libc.GetLastError() != ERROR_ENVVAR_NOT_FOUND ? "" : onError(str)
Expand Down