One could do something ugly and special case this in the environment lookup on Windows to prevent allocation for this specific case with the argument that the overhead of the string compare is negligible to the allocation from cwstring
. But I am not sure that is acceptable.
diff --git a/base/env.jl b/base/env.jl
index 077b3a4ed2..c3c60da9c0 100644
--- a/base/env.jl
+++ b/base/env.jl
@@ -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")
+
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
return Libc.GetLastError() != ERROR_ENVVAR_NOT_FOUND ? "" : onError(str)